From: jfa Date: Fri, 7 Mar 2008 07:44:38 +0000 (+0000) Subject: Join modifications from BR_Dev_For_4_0 tag V4_1_1. X-Git-Tag: TG_start_ELNO_visualization~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6e139186337f4e0d9e48d954bb0f23a9c92ac26a;p=modules%2Fmed.git Join modifications from BR_Dev_For_4_0 tag V4_1_1. --- diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ + diff --git a/COPYING b/COPYING new file mode 100644 index 000000000..b1e3f5a26 --- /dev/null +++ b/COPYING @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 000000000..f964a3459 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,63 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# -* Makefile *- +# +# Author : Patrick GOLDBRONN (CEA) +# Date : 28/06/2001 +# $Header$ +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = adm_local + +if MED_ENABLE_KERNEL + SUBDIRS+= idl +endif + +SUBDIRS+= src + +if MED_ENABLE_GUI + SUBDIRS+= doc +endif + +SUBDIRS+= resources bin +DIST_SUBDIRS= adm_local adm_local_without_kernel idl src doc resources bin + +DISTCLEANFILES= a.out aclocal.m4 configure + +EXTRA_DIST+= build_configure clean_configure LICENCE INSTALL README + +dist-hook: + rm -rf `find . -name CVS` + +if MED_ENABLE_SSTREAM + install-data-local: $(pkgincludedir)/SALOMEconfig.h +else !MED_ENABLE_SSTREAM + install-data-local: $(pkgincludedir)/SALOMEconfig.h $(pkgincludedir)/sstream $(pkgincludedir)/MED_version.h +endif + +$(pkgincludedir)/SALOMEconfig.h: ./salome_adm/unix/SALOMEconfig.h + cp -f $^ $(pkgincludedir) + +$(pkgincludedir)/sstream: ./include/salome/sstream + cp -f $^ $(pkgincludedir) + +$(pkgincludedir)/MED_version.h: MED_version.h + cp -f $^ $(pkgincludedir) diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 0666443ca..000000000 --- a/Makefile.in +++ /dev/null @@ -1,272 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -* Makefile *- -# -# Author : Patrick GOLDBRONN (CEA) -# Date : 28/06/2001 -# $Header$ -# - -# source path -top_srcdir=@top_srcdir@ -top_builddir=. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/bin:./bin/salome:./resources:@top_srcdir@/resources:./bin:@top_srcdir@/idl:${KERNEL_ROOT_DIR}/idl/salome - - -@COMMENCE@ - -SUBDIRS = src - -ifeq ($(MED_WITH_KERNEL),yes) - SUBDIRS+= idl -endif - -ifeq (@WITHIHM@,yes) - SUBDIRS+= doc -endif - -SUBDIRS+= adm_local - -RESOURCES_FILES = \ -MEDCatalog.xml \ -MED_en.xml \ -MED.config \ -SalomeApp.xml \ -Data.png \ -Infos.png \ -Structure.png \ -ModuleMed.png \ -carre_en_quad4.med \ -carre_en_quad4_seg2.med \ -cube_hexa8.med \ -cube_hexa8_quad4.med \ -maill.0.med \ -maillage_UniSegFam.med \ -mesh.med \ -pointe.med \ -test19.med \ -zzzz121b.med \ -Mistrat.med \ -TimeStamps.med \ -cas_defaut_domaine_fluide.med \ -polyedres.med \ -polygones.med \ -recoll_bord.med \ -carre_en_quad4_import22.med \ -carre_en_quad4_seg2_import22.med \ -cube_hexa8_import22.med \ -cube_hexa8_quad4_import22.med \ -maillage_UniSegFam_import22.med \ -mesh_import22.med \ -Mistrat_import22.med \ -pointe_import22.med \ -TimeStamps_import22.med \ -poly3D.med \ -Darcy3_3D_H_10x10x10_2.med \ -elle_3D_HPr_10x10x10_2.med \ -elle_3D_HPr_2x2x2_2.med \ -elle_3D_HPr_4x4x4_2.med \ -test_2D.med \ -maill.00.med \ -maill.00_nofield.med \ -maill.00_nomesh.med \ -maill.00_without_seg2.med \ -zzzz121b_without_tr6.med \ -geomMesh21.med \ -geomMesh22.med \ -ChampsDarcy.med \ -darcy_1.1_res.med \ -darcy_1.3_resCASTEM.med \ -darcy_1.3_resPORFLOW.med \ -darcy_1.3_resTRACES.med \ -darcy2_Castem_EFMH.med \ -darcy2_Castem_qua_EFMH.med \ -darcy2_Castem_qua_VF.med \ -Deff_fdt_5.8_castem_efmh_diff_conc_dom.med \ -Deff_fdt_5.8_castem_vf_diff_conc_dom.med \ -extendedtransport53_triangles.med \ -H_CastCast_EFMH_I129_COUPLEX1.med \ -H_CastCast_VF_I129_COUPLEX1.med \ -H_CastCast_VF_Se79_COUPLEX1.med \ -H_CastPorf_I129_COUPLEX1.med \ -H_CastPorf_Se79_COUPLEX1.med \ -H_PorfCast_EFMH_I129_COUPLEX1.med \ -H_PorfCast_EFMH_Se79_COUPLEX1.med \ -H_PorfPorf_I129_COUPLEX1.med \ -H_Traces_I129_COUPLEX1.med \ -H_Traces_Se79_COUPLEX1.med \ -maillage_5_5_5.med \ -maillage_chemvalIV_cas1_40elts.med \ -Old_ChampsDarcy.med \ -Old_darcy_1.1_res.med \ -Old_darcy_1.3_resCASTEM.med \ -Old_darcy_1.3_resPORFLOW.med \ -Old_darcy_1.3_resTRACES.med \ -Old_darcy2_Castem_EFMH.med \ -Old_darcy2_Castem_qua_EFMH.med \ -Old_darcy2_Castem_qua_VF.med \ -Old_Deff_fdt_5.8_castem_efmh_diff_conc_dom.med \ -Old_Deff_fdt_5.8_castem_vf_diff_conc_dom.med \ -Old_H_CastCast_EFMH_I129_COUPLEX1.med \ -Old_H_CastCast_VF_I129_COUPLEX1.med \ -Old_H_CastCast_VF_Se79_COUPLEX1.med \ -Old_H_CastPorf_I129_COUPLEX1.med \ -Old_H_CastPorf_Se79_COUPLEX1.med \ -Old_H_PorfCast_EFMH_I129_COUPLEX1.med \ -Old_H_PorfCast_EFMH_Se79_COUPLEX1.med \ -Old_H_PorfPorf_I129_COUPLEX1.med \ -Old_H_PorfPorf_Se79_COUPLEX1.med \ -Old_H_Traces_I129_COUPLEX1.med \ -Old_H_Traces_Se79_COUPLEX1.med \ -Old_maillage_chemvalIV_cas1_40elts.med \ -Darcy3_3D_H_10x10x10.sauve \ -dx200_dy1_avec_2couches.sauve \ -elle_2D_QT_10x10.sauve \ -elle_2D_QT_2x2.sauve \ -elle_2D_QT_40x40.sauve \ -elle_2D_QT_4x4.sauve \ -elle_3D_HPr_10x10x10.sauve \ -elle_3D_HPr_2x2x2.sauve \ -elle_3D_HPr_4x4x4.sauve \ -inclusion_2d_raf.sauve \ -inclusion_2d.sauve \ -mail_ktest1-3-hexa.sauve \ -mail_ktest1-3-tetra.sauve \ -mail_ktest3-1.sauve \ -mail_ktest3-2.sauve \ -maillage_andra2_100elts.sauve \ -maillage_cas2_2d.sauve \ -maillage_cas4_234elts.sauve \ -maillage_CHEMVAL_100elts.sauve \ -maillage_CHEMVAL_40elts.sauve \ -maillage_chemvalIV_cas1_100elts.sauve \ -maillage_chemvalIV_cas1_40elts.sauve \ -mail_test1-1-qua.sauve \ -mail_test1-1-tri.sauve \ -mail_test1-2-qua.sauve \ -mail_test1-2-tri.sauve \ -mail-test1-4-1.sauve \ -mail-test1-4-2.sauve \ -boitenew.inp \ -Case1.inp \ -cube.inp \ -test3.inp \ -titi.inp \ -boitenew.cnc \ -Case1.cnc \ -cube.cnc \ -test3.cnc \ -titi.cnc \ -boitenew.xyz \ -Case1.xyz \ -cube.xyz \ -test3.xyz \ -titi.xyz - -BIN_SCRIPT= \ -VERSION - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -# copy header files in common directory -include_list = include/salome/SALOMEconfig.h \ - include/salome/MED_version.h - -ifeq ($(HAVE_SSTREAM),no) - include_list+=include/salome/sstream -endif - -inc: idl $(include_list) - -bin: bin/salome/VERSION - -bin/salome/VERSION : bin/VERSION - -$(RM) $@ - $(LN_S) ../../$< $@ - -include/salome/SALOMEconfig.h: salome_adm/unix/SALOMEconfig.ref - -$(RM) $@ - $(LN_S) ../../$< $@ - -# test if SALOMEconfig.h has changed (contents) -salome_adm/unix/SALOMEconfig.ref: salome_adm/unix/SALOMEconfig.h - @if ! [ -a $@ ]; then \ - cp -p -f $< $@; \ - fi; \ - if ! cmp $< $@; then \ - cp -p -f $< $@; \ - fi; \ - -include/salome/sstream: salome_adm/unix/sstream - -$(RM) $@ - $(LN_S) ../../$< $@ - -include/salome/MED_version.h: MED_version.h - -$(RM) $@ - $(LN_S) ../../$< $@ - -depend: depend_idl - -depend_idl: - (cd idl ; $(MAKE) $@) || exit 1 - -# doc is already build : if you want to had documents, go manually to doc and run 'make doc' -#doc: -# (cd doc && $(MAKE) $@) || exit 1 - -install-end: -# finish libtool install -# @$(LT) --mode=finish $(libdir) - -install-include: $(include_list) - $(INSTALL) -d $(includedir) - @for f in X $(include_list); do \ - if test $$f != X; then \ - (cp -p $$f $(includedir) || exit 1); \ - fi; \ - done - -# install script in $(bindir) : -install-bin: $(BIN_SCRIPT) - $(INSTALL) -d $(bindir) - for f in X $(BIN_SCRIPT); do \ - if test $$f != X; then \ - (cp -p -f ./bin/salome/$$f $(bindir) || exit 1); \ - fi; \ - done - -uninstall: uninstall-idl - -uninstall-idl: - $(RM) $(idldir)/*.idl - -distclean: distclean-other - -distclean-other: - -$(RM) salome_adm/unix/*~ salome_adm/unix/*% salome_adm/unix/*.bak salome_adm/unix/*.new salome_adm/unix/*.old - -$(RM) salome_adm/unix/make_* - -$(RM) salome_adm/unix/depend salome_adm/unix/SALOMEconfig.h - -$(RM) config.cache config.log config.status - -@MODULE@ - -install: install-bin install-include install-end - diff --git a/NEWS b/NEWS new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/NEWS @@ -0,0 +1 @@ + diff --git a/README b/README index 1e366e41b..975c66396 100644 --- a/README +++ b/README @@ -50,110 +50,42 @@ Server/Client configuration. II : MedMemory building and installation : ========================================= -Assuming that the rather straightforward - -path_to_your_MedMemory_installation_directory, - -path_to_your_MedMemory_building_directory, - -path_to_your_MedMemory_sources_directory, - -path_to_your_MedFile_installation_directory, - -path_to_your_HDF5_installation_directory, - -directories are setted; the user/installer may use the following commands to -build the Med Memory installation as a Salome component : - -In the directory path_to_your_MedMemory_building_directory; - -path_to_your_MedMemory_sources_directory/build_configure - -path_to_your_MedMemory_sources_directory/configure --prefix=path_to_your_MedMemory_installation_directory +It's very simple : +./configure --prefix=path_to_your_installation_directory make - make install -Eventually if the user/installer needs to build an installation of Med -Memory as a stand alone package, he/she may use always in the -path_to_your_MedMemory_building_directory, the following commands : - -path_to_your_MedMemory_sources_directory/build_configure --without-kernel - -path_to_your_MedMemory_sources_directory/configure --prefix=path_to_your_MedMemory_installation_directory - -make - -make install - -Remark : If the installer gets the sources archives from the NEPAL web site --------- (CEA, EDF, OCC, ie hammi web site) the user may only use the - following commands : - - path_to_your_MedMemory_sources_directory/configure --prefix=path_to_your_MedMemory_installation_directory - - make - - make install - - -By default the full debug options are set: +eventually if the user or the installer needs to build an installation of Med +Memory as a stand alone package, he may use the configure option +--without-kernel. By default the full debug options are set: - compilation using -g option - Med Memory debugging information history using -D_DEBUG_ option. -The user/installer may - -get all configure option with : - -path_to_your_MedMemory_sources_directory/configure --help - -set optimization option : - -path_to_your_MedMemory_sources_directory/configure --enable-production --disable-debug (use compiler flags -O) - -In order to avoid most of the problem the user/installer should first -check the $HDF5HOME and the $MED2HOME environment variables. In csh: +The user may get all configure option with : + ./configure --help -setenv HDF5HOME path_to_your_HDF5_installation_directory +The user may set optimization option : + ./configure --enable-production --disable-debug (use compiler flags -O) -setenv MED2HOME path_to_your_MedFile_installation_directory - -This version of Med Memory has been tested with Med File V2.2.2, V2.2.3, as -well as V2.3.0 but with the version of HDF5 V1.6.3. Thus, in the installation -process of Med File the user/installer should take care of the $HDF5HOME -environement variable. This warning is especially intended to the user of the -Med Memory in its stand alone vesion (ie without the SALOME KERNEL component). +In order to avoid most of the problem the user or the installer should first +check the HDF5HOME and the MED2HOME environment variables. This version of +Med Memory with Med File V2.2.2, V2.2.3, as well as V2.3.0 but with the +version of HDF5 V1.6.3. In the installation of Med File you should take care +of the $HDF5HOME environement variable. This warning is especially intended +to the user of The Med Memory in stand alone (without the SALOME KERNEL +component). III : MedMemory testing : ========================= -After installation of the Med Memory; the user/installer may find a large set -of Med File V2.1, V2.2, GIBI test files in the directory : - -path_to_your_MedMemory_installation_directory/share/salome/resources/ - -For user/installer of the Med Meory as a Salome component, sourcing the usual -Salome environement and using the usual runSalome command, all needed -environement variables (such as $MED_ROOT_DIR, $LD_LIBRARY_PATH and -$PYTHONPATH) are well setted. - -But for the user/installer of the Med Memory as a stand alone version should -set his/her environement. Assuming that $HDF5HOME $MED2HOME are setted -properly, in csh : - -setenv MED_ROOT_DIR path_to_your_MedMemory_installation_directory - -setenv PATH ${MED2HOME}/bin:${HDF5HOME}/bin:$PATH - -setenv LD_LIBRARY_PATH ${MED_ROOT_DIR}/lib/salome:${MED2HOME}/lib:${HDF5HOME}/lib:$LD_LIBRARY_PATH - -setenv PYTHONPATH ${MED_ROOT_DIR}/bin/salome:${MED_ROOT_DIR}/lib/salome:${MED_ROOT_DIR}/lib/python${PYTHON_VERSION}/site-packages/salome: +After installation of the Med Memory; the user may find a large set of test +files in Med File V2.1, V2.2, GIBI format. To check the Med Memory installation, in the directory -path_to_your_MedMemory_installation_directory/bin/salome you may find a set of -python scripts and test executable. To ckeck the deep layers (C++, Python) of -the Med Memory, the installer may run: +path_to_your_installation_directory/bin/salome you may find a set of python +scripts and test executable. To ckeck the deep layers (C++, Python) of the Med +Memory, the installer may run: - testMedMemGeneral.py, - medMeshing_test.py diff --git a/adm_local/Makefile.am b/adm_local/Makefile.am new file mode 100644 index 000000000..76fe0fa5f --- /dev/null +++ b/adm_local/Makefile.am @@ -0,0 +1,22 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS= unix \ No newline at end of file diff --git a/adm_local/Makefile.in b/adm_local/Makefile.in deleted file mode 100644 index 6c0326fad..000000000 --- a/adm_local/Makefile.in +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# source path -top_srcdir=@top_srcdir@ -top_builddir=.. -srcdir=@srcdir@ -VPATH=.:$(srcdir)/adm_local - - -all: resources - -install: - cp -rf @top_srcdir@/adm_local @prefix@ - -bin: - -resources : - cp -rf @top_srcdir@/adm_local $(top_builddir) - -inc: - -lib: - -depend: - -depend_idl: - -install-end: - -install-include: - -install-bin: - -uninstall: - -uninstall-idl: - -distclean: - -clean: - -distclean-other: - diff --git a/adm_local/unix/Makefile.am b/adm_local/unix/Makefile.am new file mode 100644 index 000000000..facd4e6f4 --- /dev/null +++ b/adm_local/unix/Makefile.am @@ -0,0 +1,22 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = config_files diff --git a/adm_local/unix/config_files/Makefile.am b/adm_local/unix/config_files/Makefile.am new file mode 100644 index 000000000..d46d738d0 --- /dev/null +++ b/adm_local/unix/config_files/Makefile.am @@ -0,0 +1,30 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +dist_admlocalm4_DATA=\ + check_Med2.m4 \ + check_Med.m4 \ + check_metis.m4 \ + check_scotch.m4 \ + splitter.m4 \ + with_Kernel.m4 \ + ac_check_sizeof_fortran.m4 \ + med_check_sizeof_medint.m4 \ + README diff --git a/adm_local/unix/config_files/ac_check_sizeof_fortran.m4 b/adm_local/unix/config_files/ac_check_sizeof_fortran.m4 new file mode 100644 index 000000000..57346a614 --- /dev/null +++ b/adm_local/unix/config_files/ac_check_sizeof_fortran.m4 @@ -0,0 +1,48 @@ +AC_DEFUN([AC_CHECK_SIZEOF_FORTRAN], [ + AC_REQUIRE([AC_F77_WRAPPERS]) + AC_CACHE_CHECK([size of Fortran [$1]], [ac_cv_sizeof_fortran_[]translit($1, [A-Z *], [a-z_p])],[ + AC_LANG_SAVE() + AC_LANG([Fortran 77]) + AC_COMPILE_IFELSE([ + AC_LANG_SOURCE([ + subroutine fsize() + $1 i(2) + call csize(i(1), i(2)) + end + ]) + ],[ + AC_LANG([C]) + cp conftest.$ac_objext conftestf.$ac_objext + old_LDFLAGS="$LDFLAGS" + LDFLAGS="conftestf.$ac_objext $LDFLAGS" + AC_TRY_RUN([ +# include +# define CSIZE F77_FUNC(csize,CSIZE) +# define FSIZE F77_FUNC(fsize,FSIZE) + static long size_val; + /* Called by Fortran */ + void CSIZE (i1p, i2p) + char *i1p, *i2p; + { + size_val = (i2p - i1p); + } + main() { + FILE *f=fopen ("conftestval","w"); + if (!f) return 1; + /* Call the Fortran function */ + FSIZE (); + fprintf (f, "%d\n", size_val); + return 0; + } + ]) + LDFLAGS="$old_LDFLAGS" + ac_cv_sizeof_fortran_[]translit($1, [A-Z *], [a-z_p])=`cat conftestval` + rm -f conftestval conftestf.$ac_objext + ]) + AC_LANG_RESTORE() + ]) + AC_DEFINE_UNQUOTED(SIZEOF_FORTRAN_[]translit($1, [a-z *], [A-Z_p]), + [$ac_cv_sizeof_fortran_[]translit($1, [A-Z *], [a-z_p])], + [The size of a Fortran `$1', as computed by sizeof.]) + +]) diff --git a/adm_local/unix/config_files/check_Med.m4 b/adm_local/unix/config_files/check_Med.m4 index b741c5b9f..803d1fca6 100644 --- a/adm_local/unix/config_files/check_Med.m4 +++ b/adm_local/unix/config_files/check_Med.m4 @@ -5,6 +5,7 @@ AC_DEFUN([CHECK_MED],[ AC_REQUIRE([AC_LINKER_OPTIONS])dnl +AC_REQUIRE([CHECK_MED2]) AC_CHECKING(for Med) @@ -29,6 +30,8 @@ if test "x${MED_DIR}" == "x" ; then fi +MED_ENABLE_MULTIPR=no + if test -f ${MED_DIR}/idl/salome/MED.idl ; then AC_MSG_RESULT(Using Med module distribution in ${MED_DIR}) Med_ok=yes @@ -44,11 +47,25 @@ if test -f ${MED_DIR}/idl/salome/MED.idl ; then AC_SUBST(MED_LDFLAGS) AC_SUBST(MED_CXXFLAGS) + + # MULTIPR + AC_CHECK_FILE(${MED_DIR}/include/salome/MULTIPR_Obj.hxx, + ENABLE_MULTIPR=yes, + ENABLE_MULTIPR=no) + AC_SUBST(ENABLE_MULTIPR) + MULTIPR_CPPFLAGS="" + MULTIPR_LIBS="" + if test "x${ENABLE_MULTIPR}" = "xyes" ; then + MULTIPR_CPPFLAGS="-DENABLE_MULTIPR" + MULTIPR_LIBS="-lMULTIPR_API" + fi + AC_SUBST(MULTIPR_CPPFLAGS) + AC_SUBST(MULTIPR_LIBS) else AC_MSG_WARN("Cannot find Med module sources") fi - + AC_MSG_RESULT(for Med: $Med_ok) - +AC_MSG_RESULT(for MULTIPR Med package: $ENABLE_MULTIPR) + ])dnl - diff --git a/adm_local/unix/config_files/check_Med2.m4 b/adm_local/unix/config_files/check_Med2.m4 index 82b107880..1e58bbd29 100644 --- a/adm_local/unix/config_files/check_Med2.m4 +++ b/adm_local/unix/config_files/check_Med2.m4 @@ -24,6 +24,7 @@ AC_DEFUN([CHECK_MED2],[ AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_PROG_CPP])dnl AC_REQUIRE([CHECK_HDF5])dnl +AC_REQUIRE([MED_CHECK_SIZEOF_MEDINT]) AC_CHECKING(for MED2) @@ -36,15 +37,17 @@ AC_ARG_WITH(med2, AC_SUBST(MED2_INCLUDES) AC_SUBST(MED2_LIBS) AC_SUBST(MED2_MT_LIBS) +AC_SUBST(MED_CPPFLAGS) MED2_INCLUDES="" MED2_LIBS="" MED2_MT_LIBS="" +MED_CPPFLAGS="$DEFINED_F77INT64" med2_ok=no LOCAL_INCLUDES="$HDF5_INCLUDES" -LOCAL_LIBS="-lmed $HDF5_LIBS" +LOCAL_LIBS="-lmed -lmedimportcxx $HDF5_LIBS" if test -z $MED2HOME then @@ -69,12 +72,89 @@ fi dnl check med2 header +f77int="F77INT32" +case $host_os in + irix5.* | irix6.* | osf4.* | osf5.* | linux* ) + + linux64="true" +# porting on intel processor 64 bits + expr "$host_os" : 'linux' >/dev/null && ( test ! x"$host_cpu" = x"x86_64" && test ! x"$host_cpu" = x"ia64" ) && linux64="false" + if test ! x"$linux64" = "xfalse" ; then + echo "$as_me:$LINENO: checking for 64bits integers size in F77/F90" >&5 +echo $ECHO_N "checking for 64bits integers size in F77/F90... $ECHO_C" >&6 + # Check whether --enable-int64 or --disable-int64 was given. +if test "${enable_int64+set}" = set; then + enableval="$enable_int64" + +fi; + case "X-$enable_int64" in + X-no) + echo "$as_me:$LINENO: result: \"disabled\"" >&5 +echo "${ECHO_T}\"disabled\"" >&6 + SUFFIXES="_32" + ;; + *) + echo "$as_me:$LINENO: result: \"enabled\"" >&5 +echo "${ECHO_T}\"enabled\"" >&6 + SUFFIXES="" + f77int="F77INT64" + ;; + esac + fi + ;; + *) + ;; +esac + +case $host_os in + linux*) + test x"$linux64" = x"true" && \ + MACHINE="PCLINUX64${SUFFIXES}" || \ + MACHINE=PCLINUX + ;; + hpux*) + MACHINE=HP9000 + ;; + aix4.*) + MACHINE=RS6000 + host_os_novers=aix4.x + ;; + irix5.*) + MACHINE="IRIX64${SUFFIXES}" + host_os_novers=irix5.x + ;; + irix6.*) + MACHINE="IRIX64${SUFFIXES}" + host_os_novers=irix6.x + ;; + osf4.*) + MACHINE="OSF1${SUFFIXES}" + host_os_novers=osf4.x + ;; + osf5.*) + MACHINE="OSF1${SUFFIXES}" + host_os_novers=osf5.x + ;; + solaris2.*) + MACHINE=SUN4SOL2 + host_os_novers=solaris2.x + ;; + uxpv*) + MACHINE=VPP5000 + ;; + *) + MACHINE= + host_os_novers=$host_os + ;; +esac + CPPFLAGS_old="$CPPFLAGS" dnl we must test system : linux = -DPCLINUX dnl we must test system : Alpha-OSF = -DOSF1 case $host_os in linux*) - CPPFLAGS="$CPPFLAGS -DPCLINUX $LOCAL_INCLUDES" + CPPFLAGS="$CPPFLAGS -D$MACHINE $LOCAL_INCLUDES" +dnl CPPFLAGS="$CPPFLAGS -DPCLINUX $LOCAL_INCLUDES" ;; osf*) CPPFLAGS="$CPPFLAGS -DOSF1 $LOCAL_INCLUDES" @@ -91,15 +171,21 @@ dnl check med2 library LIBS_old="$LIBS" LIBS="$LIBS $LOCAL_LIBS" AC_CHECK_LIB(med,MEDouvrir,med2_ok=yes,med2_ok=no) - LIBS="$LIBS_old" + if test "x$med2_ok" = "xyes" + then + AC_CHECK_LIB(medimportcxx,HAVE_MEDimport,med2_ok=yes,med2_ok=no) + fi + LIBS="$LIBS_old" + fi if test "x$med2_ok" = "xyes" then case $host_os in linux*) - MED2_INCLUDES="-DPCLINUX $LOCAL_INCLUDES" + MED2_INCLUDES="-D$MACHINE $LOCAL_INCLUDES" +dnl MED2_INCLUDES="-DPCLINUX $LOCAL_INCLUDES" ;; osf*) MED2_INCLUDES="-DOSF1 $LOCAL_INCLUDES" @@ -109,6 +195,7 @@ esac MED2_MT_LIBS="$LOCAL_LIBS" fi + AC_MSG_RESULT(for med2: $med2_ok) ])dnl diff --git a/adm_local/unix/config_files/check_libxml.m4 b/adm_local/unix/config_files/check_libxml.m4 new file mode 100644 index 000000000..e7370fb2b --- /dev/null +++ b/adm_local/unix/config_files/check_libxml.m4 @@ -0,0 +1,138 @@ +dnl Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +dnl +dnl +dnl +AC_DEFUN([CHECK_LIBXML],[ + +AC_CHECKING(for libXML Library) + +AC_LANG_SAVE +AC_LANG_C + +LIBXML_CPPFLAGS="" +LIBXML_LIBSUFFIX="" +LIBXML_LIBS="" + +AC_CHECKING(for LIBXML location) +AC_ARG_WITH(libxml, + [ --with-libxml=DIR root directory path to LIBXML library installation ], + [LIBXML_DIR="$withval" + AC_MSG_RESULT("select $withval as path to LIBXML library")]) + +AC_MSG_RESULT(\$LIBXML_DIR = ${LIBXML_DIR}) + +CPPFLAGS_old="${CPPFLAGS}" +LIBS_old=$LIBS + +if test "x${LIBXML_DIR}" != "x" ; then + LIBXML_CPPFLAGS="-I${LIBXML_DIR}/include/libxml2" + LIBXML_LIBS="-L${LIBXML_DIR}/lib -lxml2" +fi + +libxml_ok=no +libxml_headers_ok=no +libxml_binaries_ok=no + +dnl LIBXML headers +AC_CHECKING(for LIBXML headers) +CPPFLAGS="${CPPFLAGS_old} ${LIBXML_CPPFLAGS}" + +libxml_include_dir_ok=yes +if test "x${LIBXML_DIR}" != "x" ; then + AC_CHECK_FILE(${LIBXML_DIR}/include/libxml2/libxml/tree.h, + libxml_include_dir_ok=yes, + libxml_include_dir_ok=no) +fi + +if test "x${libxml_include_dir_ok}" = "xyes" ; then + AC_TRY_COMPILE([#include ], + [xmlNewDoc("1.0")], + libxml_headers_ok=yes, + libxml_headers_ok=no) +fi + +if test "x${libxml_headers_ok}" = "xno" ; then + LIBXML_CPPFLAGS="LIBXML_CPPFLAGS_NOT_DEFINED" +else + AC_MSG_RESULT(\$LIBXML_CPPFLAGS = ${LIBXML_CPPFLAGS}) +fi +AC_MSG_RESULT(for libxml headers: $libxml_headers_ok) + +if test "x${libxml_headers_ok}" = "xyes" ; then +dnl LIBXML binaries + AC_CHECKING(for LIBXML binaries) + libxml_lib_dir_ok=yes + if test "x${LIBXML_DIR}" != "x" ; then + AC_CHECK_FILE(${LIBXML_DIR}/lib/libxml2.a, + libxml_lib_dir_ok=yes, + libxml_lib_dir_ok=no) + if test "x${libxml_lib_dir_ok}" = "xno" ; then + LIBXML_LIBSUFFIX="" + AC_CHECK_FILE(${LIBXML_DIR}/lib/libxml2.a, + libxml_lib_dir_ok=yes, + libxml_lib_dir_ok=no) + fi + fi + if test "x${libxml_lib_dir_ok}" = "xyes" ; then + LIBS="${LIBS_old} ${LIBXML_LIBS}" + AC_TRY_LINK([#include ], + [xmlNewDoc("1.0")], + libxml_binaries_ok=yes, + libxml_binaries_ok=no) + if test "x${libxml_binaries_ok}" = "xno" ; then + LIBXML_LIBSUFFIX="" + LIBS="${LIBS_old} ${LIBXML_LIBS} " + AC_TRY_LINK([#include ], + [xmlNewDoc("1.0")], + libxml_binaries_ok=yes, + libxml_binaries_ok=no) + fi + fi +fi + +if test "x${libxml_binaries_ok}" = "xno" ; then + LIBXML_LIBS="LIBXML_LIBS_NOT_FOUND" + LIBXML_LIBSUFFIX="-not-defined" +else + AC_MSG_RESULT(\$LIBXML_LIBSUFFIX = ${LIBXML_LIBSUFFIX}) + AC_MSG_RESULT(\$LIBXML_LIBS = ${LIBXML_LIBS}) +fi +AC_MSG_RESULT(for libxml binaries: $libxml_binaries_ok) + +CPPFLAGS="${CPPFLAGS_old}" +LIBS="${LIBS_old}" + +if test "x${libxml_headers_ok}" = "xyes" ; then + if test "x${libxml_binaries_ok}" = "xyes" ; then + libxml_ok=yes + fi +fi + +AC_MSG_RESULT(for libxml: $libxml_ok) + +AC_SUBST(LIBXML_CPPFLAGS) +AC_SUBST(LIBXML_LIBSUFFIX) +AC_SUBST(LIBXML_LIBS) + +AC_LANG_RESTORE + +])dnl + + diff --git a/adm_local/unix/config_files/check_metis.m4 b/adm_local/unix/config_files/check_metis.m4 new file mode 100644 index 000000000..0127d0c49 --- /dev/null +++ b/adm_local/unix/config_files/check_metis.m4 @@ -0,0 +1,139 @@ +dnl Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +dnl +dnl +dnl +AC_DEFUN([CHECK_METIS],[ + +AC_CHECKING(for METIS Library) + +AC_LANG_SAVE +AC_LANG_C + +METIS_CPPFLAGS="" +METIS_LIBSUFFIX="" +METIS_LIBS="" +ENABLE_METIS="no" + +AC_CHECKING(for METIS location) +AC_ARG_WITH(metis, + [ --with-metis=DIR root directory path to METIS library installation ], + [METISDIR="$withval" + AC_MSG_RESULT("select $withval as path to METIS library")]) + +AC_MSG_RESULT(\$METISDIR = ${METISDIR}) + +CPPFLAGS_old="${CPPFLAGS}" +LIBS_old=$LIBS + +if test "x${METISDIR}" != "x" ; then + METIS_CPPFLAGS="-DENABLE_METIS -I${METISDIR}/Lib" + METIS_LIBS="-L${METISDIR} -lmetis" +fi + +metis_ok=no +metis_headers_ok=no +metis_binaries_ok=no + +dnl METIS headers +AC_CHECKING(for METIS headers) +CPPFLAGS="${CPPFLAGS_old} ${METIS_CPPFLAGS}" + +metis_include_dir_ok=yes +if test "x${METISDIR}" != "x" ; then + AC_CHECK_FILE(${METISDIR}/Lib/metis.h, + metis_include_dir_ok=yes, + metis_include_dir_ok=no) +fi + +if test "x${metis_include_dir_ok}" = "xyes" ; then + AC_TRY_COMPILE([#include ], + [Change2CNumbering(0,0,0)], + metis_headers_ok=yes, + metis_headers_ok=no) +fi + +if test "x${metis_headers_ok}" = "xno" ; then + METIS_CPPFLAGS="METIS_CPPFLAGS_NOT_DEFINED" +else + AC_MSG_RESULT(\$METIS_CPPFLAGS = ${METIS_CPPFLAGS}) +fi +AC_MSG_RESULT(for metis headers: $metis_headers_ok) + +if test "x${metis_headers_ok}" = "xyes" ; then + dnl METIS binaries + AC_CHECKING(for METIS binaries) + metis_lib_dir_ok=yes + if test "x${METISDIR}" != "x" ; then + AC_CHECK_FILE(${METISDIR}/libmetis.a, + metis_lib_dir_ok=yes, + metis_lib_dir_ok=no) + if test "x${metis_lib_dir_ok}" = "xno" ; then + METIS_LIBSUFFIX="" + AC_CHECK_FILE(${METISDIR}/libmetis.a, + metis_lib_dir_ok=yes, + metis_lib_dir_ok=no) + fi + fi + if test "x${metis_lib_dir_ok}" = "xyes" ; then + LIBS="${LIBS_old} ${METIS_LIBS}" + AC_TRY_LINK([#include ], + [Change2CNumbering(0,0,0)], + metis_binaries_ok=yes, + metis_binaries_ok=no) + if test "x${metis_binaries_ok}" = "xno" ; then + METIS_LIBSUFFIX="" + LIBS="${LIBS_old} ${METIS_LIBS} " + AC_TRY_LINK([#include ], + [Change2CNumbering(0,0,0)], + metis_binaries_ok=yes, + metis_binaries_ok=no) + fi + fi +fi + +if test "x${metis_binaries_ok}" = "xno" ; then + METIS_LIBS="METIS_LIBS_NOT_FOUND" + METIS_LIBSUFFIX="-not-defined" +else + AC_MSG_RESULT(\$METIS_LIBSUFFIX = ${METIS_LIBSUFFIX}) + AC_MSG_RESULT(\$METIS_LIBS = ${METIS_LIBS}) +fi +AC_MSG_RESULT(for metis binaries: $metis_binaries_ok) + +CPPFLAGS="${CPPFLAGS_old}" +LIBS="${LIBS_old}" + +if test "x${metis_headers_ok}" = "xyes" ; then + if test "x${metis_binaries_ok}" = "xyes" ; then + metis_ok=yes + ENABLE_METIS="yes" + fi +fi + +AC_MSG_RESULT(for metis: $metis_ok) + +AC_SUBST(METIS_CPPFLAGS) +AC_SUBST(METIS_LIBSUFFIX) +AC_SUBST(METIS_LIBS) +AC_SUBST(ENABLE_METIS) + +AC_LANG_RESTORE + +])dnl diff --git a/adm_local/unix/config_files/check_scotch.m4 b/adm_local/unix/config_files/check_scotch.m4 new file mode 100644 index 000000000..63c32752f --- /dev/null +++ b/adm_local/unix/config_files/check_scotch.m4 @@ -0,0 +1,147 @@ +dnl Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +dnl +dnl +dnl +AC_DEFUN([CHECK_SCOTCH],[ + +AC_CHECKING(for SCOTCH Library) + +AC_LANG_SAVE +AC_LANG_C + +SCOTCH_CPPFLAGS="" +SCOTCH_LIBSUFFIX="" +SCOTCH_LIBS="" +ENABLE_SCOTCH="no" + +AC_CHECKING(for SCOTCH location) +AC_ARG_WITH(scotch, + [ --with-scotch=DIR root directory path to SCOTCH library installation ], + [SCOTCHDIR="$withval" + AC_MSG_RESULT("select $withval as path to SCOTCH library")]) + +AC_MSG_RESULT(\$SCOTCHDIR = ${SCOTCHDIR}) + +CPPFLAGS_old="${CPPFLAGS}" +LIBS_old=$LIBS + +if test "x${SCOTCHDIR}" != "x" ; then + SCOTCH_CPPFLAGS="-DENABLE_SCOTCH -I${SCOTCHDIR}" + SCOTCH_LIBS="-L${SCOTCHDIR}/bin -lscotch -lscotcherr" +fi + +scotch_ok=no +scotch_headers_ok=no +scotch_binaries_ok=no + +dnl SCOTCH headers +AC_CHECKING(for SCOTCH headers) +CPPFLAGS="${CPPFLAGS_old} ${SCOTCH_CPPFLAGS} -std=c99" + +scotch_include_dir_ok=yes +if test "x${SCOTCHDIR}" != "x" ; then + AC_CHECK_FILE(${SCOTCHDIR}/bin/scotch.h, + scotch_include_dir_ok=yes, + scotch_include_dir_ok=no) +fi + +if test "x${scotch_include_dir_ok}" = "xyes" ; then + AC_TRY_COMPILE([#include + #include ], + [SCOTCH_Graph* graph; + SCOTCH_graphInit(graph)], + scotch_headers_ok=yes, + scotch_headers_ok=no) +fi + +if test "x${scotch_headers_ok}" = "xno" ; then + SCOTCH_CPPFLAGS="SCOTCH_CPPFLAGS_NOT_DEFINED" +else + AC_MSG_RESULT(\$SCOTCH_CPPFLAGS = ${SCOTCH_CPPFLAGS}) +fi +AC_MSG_RESULT(for scotch headers: $scotch_headers_ok) + +if test "x${scotch_headers_ok}" = "xyes" ; then + dnl SCOTCH binaries + AC_CHECKING(for SCOTCH binaries) + scotch_lib_dir_ok=yes + if test "x${SCOTCHDIR}" != "x" ; then + AC_CHECK_FILE(${SCOTCHDIR}/bin/libscotch.a, + scotch_lib_dir_ok=yes, + scotch_lib_dir_ok=no) + if test "x${scotch_lib_dir_ok}" = "xno" ; then + SCOTCH_LIBSUFFIX="" + AC_CHECK_FILE(${SCOTCHDIR}/bin/libscotch.a, + scotch_lib_dir_ok=yes, + scotch_lib_dir_ok=no) + fi + fi + if test "x${scotch_lib_dir_ok}" = "xyes" ; then + LIBS="${LIBS_old} ${SCOTCH_LIBS}" + AC_TRY_LINK([#include + #include ], + [SCOTCH_Graph* graph; + SCOTCH_graphInit(graph)], + scotch_binaries_ok=yes, + scotch_binaries_ok=no) + if test "x${scotch_binaries_ok}" = "xno" ; then + SCOTCH_LIBSUFFIX="" + LIBS="${LIBS_old} ${SCOTCH_LIBS} " + AC_TRY_LINK([#include + #include ], + [SCOTCH_Graph* graph; + SCOTCH_graphInit(graph)], + scotch_binaries_ok=yes, + scotch_binaries_ok=no) + fi + fi +fi + +if test "x${scotch_binaries_ok}" = "xno" ; then + SCOTCH_LIBS="SCOTCH_LIBS_NOT_FOUND" + SCOTCH_LIBSUFFIX="-not-defined" +else + AC_MSG_RESULT(\$SCOTCH_LIBSUFFIX = ${SCOTCH_LIBSUFFIX}) + AC_MSG_RESULT(\$SCOTCH_LIBS = ${SCOTCH_LIBS}) +fi +AC_MSG_RESULT(for scotch binaries: $scotch_binaries_ok) + +CPPFLAGS="${CPPFLAGS_old}" +LIBS="${LIBS_old}" + +if test "x${scotch_headers_ok}" = "xyes" ; then + if test "x${scotch_binaries_ok}" = "xyes" ; then + scotch_ok=yes + ENABLE_SCOTCH="yes" + fi +fi + +AC_MSG_RESULT(for scotch: $scotch_ok) + +AC_SUBST(SCOTCH_CPPFLAGS) +AC_SUBST(SCOTCH_LIBSUFFIX) +AC_SUBST(SCOTCH_LIBS) +AC_SUBST(ENABLE_SCOTCH) + +AC_LANG_RESTORE + +])dnl + + diff --git a/adm_local/unix/config_files/med_check_sizeof_medint.m4 b/adm_local/unix/config_files/med_check_sizeof_medint.m4 new file mode 100644 index 000000000..722479c82 --- /dev/null +++ b/adm_local/unix/config_files/med_check_sizeof_medint.m4 @@ -0,0 +1,17 @@ +AC_DEFUN([MED_CHECK_SIZEOF_MEDINT], [ + + ## Guess the fortran int size + AC_CHECK_SIZEOF_FORTRAN(integer) + if test "x$ac_cv_sizeof_fortran_integer" = "x8" ; then + AC_CHECK_SIZEOF(long) + test "x$ac_cv_sizeof_long" = "x8" || AC_MSG_ERROR([Size of C type long expected to be eight bytes]) + DEFINED_F77INT64="-DHAVE_F77INT64" + elif test "x$ac_cv_sizeof_fortran_integer" = "x4" ; then + AC_CHECK_SIZEOF(int) + test "x$ac_cv_sizeof_int" = "x4" || AC_MSG_ERROR([Size of C type int expected to be four bytes]) + DEFINED_F77INT64="" + else + AC_MSG_ERROR([Size of Fortran type integer is neither four nor eigth bytes]) + fi + AC_SUBST(DEFINED_F77INT64) +]) \ No newline at end of file diff --git a/adm_local/unix/config_files/splitter.m4 b/adm_local/unix/config_files/splitter.m4 new file mode 100644 index 000000000..85f6517bc --- /dev/null +++ b/adm_local/unix/config_files/splitter.m4 @@ -0,0 +1,61 @@ +dnl Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl +dnl See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +dnl +dnl +dnl +dnl define macros : +dnl AC_ENABLE_SPLITTER AC_DISABLE_SPLITTER +dnl +dnl author Vincent BERGEAUD +dnl + +# AC_ENABLE_SPLITTER +AC_DEFUN([AC_ENABLE_SPLITTER], [dnl +define([AC_ENABLE_SPLITTER_DEFAULT], ifelse($1, yes, yes, no))dnl +AC_ARG_ENABLE(splitter, +changequote(<<, >>)dnl +<< --enable-splitter[=PKGS] build with splitter tool [default=>>AC_ENABLE_SPLITTER_DEFAULT], +changequote([, ])dnl +[p=${PACKAGE-default} +case "$enableval" in +yes) enable_splitter=yes ;; +no) enable_splitter=no ;; +*) + enable_splitter=no + # Look at the argument we got. We use all the common list separators. + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," + for pkg in $enableval; do + if test "X$pkg" = "X$p"; then + enable_splitter=yes + fi + done + IFS="$ac_save_ifs" + ;; +esac], +enable_splitter=AC_ENABLE_SPLITTER_DEFAULT)dnl + +if test "X$enable_splitter" = "Xyes"; then + ENABLE_SPLITTER="yes" + AC_SUBST(ENABLE_SPLITTER) +fi +]) + +# AC_DISABLE_SPLITTER - set the default flag to --disable-splitter +AC_DEFUN([AC_DISABLE_SPLITTER], [AC_ENABLE_SPLITTER(no)]) + diff --git a/adm_local/unix/make_commence.in b/adm_local/unix/make_commence.in deleted file mode 100644 index e9997da99..000000000 --- a/adm_local/unix/make_commence.in +++ /dev/null @@ -1,324 +0,0 @@ -# common directories to put headerfiles -inc_builddir=$(top_builddir)/include/salome - -MED_WITH_KERNEL=@MED_WITH_KERNEL@ -@SET_MAKE@ -SHELL=@SHELL@ - -# header missing - -HAVE_SSTREAM=@HAVE_SSTREAM@ - - -LIBS=@LIBS@ -LIBSFORBIN=@LIBS@ -LDFLAGS=@LDFLAGS@ -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN=@LDFLAGS@ -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -# add libstdc++ to link c++ library with libtool ! -LDFLAGS+= @STDLIB@ -LDFLAGSFORBIN+= @STDLIB@ - -CP=@CP@ - -# CPP - -CPP=@CPP@ -CXXCPP=@CXXCPP@ -CPPFLAGS=@CPPFLAGS@ -I$(inc_builddir) -I$(srcdir) -I. - -# C - -CC = @CC@ -CFLAGS = @CFLAGS@ -C_DEPEND_FLAG = @C_DEPEND_FLAG@ - -# C++ - -CXX = @CXX@ -CXXFLAGS = @CXXFLAGS@ -CXX_DEPEND_FLAG = @CXX_DEPEND_FLAG@ - -# BOOST Library - -BOOST_CPPFLAGS = @BOOST_CPPFLAGS@ -BOOST_LIBSUFFIX = @BOOST_LIBSUFFIX@ -BOOST_LIBS = @BOOST_LIBS@ - -# JAVA - -JAVA_INCLUDES = @JAVA_INCLUDES@ -JAVA_LIBS = @JAVA_LIBS@ -JAVA_LDPATH = @JAVA_LDPATH@ - -# PYTHON - -PYTHON = @PYTHON@ -PYTHONHOME = @PYTHONHOME@ -PYTHON_INCLUDES = @PYTHON_INCLUDES@ -PYTHON_LIBS = @PYTHON_LIBS@ -PYTHON_VERSION = @PYTHON_VERSION@ -# Changes from the SalomePro V1.2c -#PYTHON_SITE = @PYTHON_SITE@ -#PYTHON_SITE_INSTALL = @PYTHON_SITE_INSTALL@ -PYTHON_SITE = $(prefix)/lib@LIB_LOCATION_SUFFIX@/python$(PYTHON_VERSION)/site-packages -PYTHON_SITE_INSTALL = $(prefix)/lib@LIB_LOCATION_SUFFIX@/python$(PYTHON_VERSION)/site-packages/salome - -# QT - -QT_ROOT = @QT_ROOT@ -QT_INCLUDES = @QT_INCLUDES@ -QT_MT_INCLUDES = @QT_INCLUDES@ -DQT_THREAD_SUPPORT -QT_LIBS = @QT_LIBS@ -QT_MT_LIBS = @QT_MT_LIBS@ - -MOC = @MOC@ -UIC = @UIC@ -MSG2QM = @MSG2QM@ - -#QWT - -QWT_INCLUDES=@QWT_INCLUDES@ -QWT_LIBS=@QWT_LIBS@ - -# SIP -SIP = @SIP@ -SIP_INCLUDES = @SIP_INCLUDES@ -SIP_LIBS = @SIP_LIBS@ - -# PYQT -PYQT_SIPS = @PYQT_SIPS@ -PYQT_LIBS = @PYQT_LIBS@ - -# openGL -OGL_INCLUDES=@OGL_INCLUDES@ -OGL_LIBS=@OGL_LIBS@ - -# VTK -VTK_INCLUDES=@VTK_INCLUDES@ -VTK_LIBS=@VTK_LIBS@ - -# HDF5 - -HDF5_INCLUDES=@HDF5_INCLUDES@ -HDF5_LIBS=@HDF5_LIBS@ -HDF5_MT_LIBS=@HDF5_MT_LIBS@ - -# MED2 - -MED2_INCLUDES=@MED2_INCLUDES@ -MED2_LIBS=@MED2_LIBS@ -MED2_MT_LIBS=@MED2_MT_LIBS@ - -# OpenCasCade - -OCC_INCLUDES=@CAS_CPPFLAGS@ -OCC_CXXFLAGS=@CAS_CXXFLAGS@ - -#OCC_KERNEL_LIBS=@CAS_KERNEL@ -#OCC_OCAF_LIBS=@CAS_OCAF@ -#OCC_VIEWER_LIBS=@CAS_VIEWER@ -#OCC_MODELER_LIBS=@CAS_MODELER@ -#OCC_DATAEXCHANGE_LIBS=@CAS_DATAEXCHANGE@ -#OCC_LIBS=@CAS_LDFLAGS@ -CAS_KERNEL=@CAS_KERNEL@ -CAS_OCAF=@CAS_OCAF@ -CAS_VIEWER=@CAS_VIEWER@ -CAS_MODELER=@CAS_MODELER@ -CAS_DATAEXCHANGE=@CAS_DATAEXCHANGE@ -CAS_LDPATH=@CAS_LDPATH@ - -# CPPUNIT - -CPPUNIT_INCLUDES = @CPPUNIT_INCLUDES@ -CPPUNIT_LIBS = @CPPUNIT_LIBS@ - -# MPICH - -MPICH_INCLUDES=@MPICH_INCLUDES@ -MPICH_LIBS=@MPICH_LIBS@ - -# Swig C++ Python - -SWIG = @SWIG@ -SWIG_FLAGS = @SWIG_FLAGS@ -I$(inc_builddir) -I$(srcdir) -I. - -# OMNIORB - -OMNIORB_ROOT = @OMNIORB_ROOT@ -OMNIORB_INCLUDES = @OMNIORB_INCLUDES@ -OMNIORB_LIBS = @OMNIORB_LIBS@ -OMNIORB_CXXFLAGS = @OMNIORB_CXXFLAGS@ - -OMNIORB_IDL = @OMNIORB_IDL@ -OMNIORB_IDLCXXFLAGS = @OMNIORB_IDLCXXFLAGS@ -OMNIORB_IDLPYFLAGS = @OMNIORB_IDLPYFLAGS@ -I$(top_srcdir)/idl -I$(top_builddir)/salome/idl -I$(KERNEL_ROOT_DIR)/idl/salome - -OMNIORB_IDL_CLN_H = @OMNIORB_IDL_CLN_H@ -OMNIORB_IDL_CLN_CXX = @OMNIORB_IDL_CLN_CXX@ -OMNIORB_IDL_CLN_OBJ = @OMNIORB_IDL_CLN_OBJ@ - -OMNIORB_IDL_SRV_H = @OMNIORB_IDL_SRV_H@ -OMNIORB_IDL_SRV_CXX = @OMNIORB_IDL_SRV_CXX@ -OMNIORB_IDL_SRV_OBJ = @OMNIORB_IDL_SRV_OBJ@ - -# Default ORB - -CORBA_ROOT = @CORBA_ROOT@ -CORBA_INCLUDES = @CORBA_INCLUDES@ -CORBA_LIBS = @CORBA_LIBS@ -CORBA_CXXFLAGS = @CORBA_CXXFLAGS@ - -IDLCXXFLAGS = -bcxx @IDLCXXFLAGS@ -I$(top_srcdir)/idl -I$(top_builddir)/idl/salome -I$(KERNEL_ROOT_DIR)/idl/salome -IDLPYFLAGS = @IDLPYFLAGS@ - -IDL = @IDL@ - -IDL_CLN_H = @IDL_CLN_H@ -IDL_CLN_CXX = @IDL_CLN_CXX@ -IDL_CLN_OBJ = @IDL_CLN_OBJ@ - -IDL_SRV_H = @IDL_SRV_H@ -IDL_SRV_CXX = @IDL_SRV_CXX@ -IDL_SRV_OBJ = @IDL_SRV_OBJ@ - -ifeq ($(MED_WITH_KERNEL),yes) - CPPFLAGS+= $(CORBA_INCLUDES) - CXXFLAGS+= $(CORBA_CXXFLAGS) - - # add corba libs when link salome application ! - #LDFLAGS+= $(CORBA_LIBS) - LIBS+=$(CORBA_LIBS) -endif - -DOXYGEN = @DOXYGEN@ -DOXYGEN_WITH_PYTHON = @DOXYGEN_WITH_PYTHON@ -DOXYGEN_WITH_STL = @DOXYGEN_WITH_STL@ - -## Shared libraries -LT_STATIC_EXEC=@LT_STATIC_EXEC@ -DYNAMIC_DIRS=@DYNAMIC_DIRS@ -LT_LIB=libtool -LT=$(top_builddir)/libtool -LT_COMPILE=$(LT) --mode=compile $(CC) -LT_LINK_LIB=$(LT_LIB) --mode=link $(CC) -rpath $(libdir) -LT_LINK_EXE=$(LT) --mode=link $(CC) $(LT_STATIC_EXEC) -dlopen self -rpath $(bindir) $(DYNAMIC_DIRS) -LT_RUN=$(LT) --mode=execute -LT_INSTALL_PROG=$(LT) --mode=install $(INSTALL_PROGRAM) -LT_INSTALL_LIB=$(LT) --mode=install $(INSTALL_DATA) -LT_UNINSTALL=$(LT) --mode=uninstall $(RM) - -INSTALL=@INSTALL@ -INSTALL_PROGRAM=@INSTALL_PROGRAM@ -INSTALL_DATA=@INSTALL_DATA@ - -# create a symbolic link (or a copie ?) -LN_S=@LN_S@ - -ifeq ($(MED_WITH_KERNEL),yes) - - KERNEL_ROOT_DIR=@KERNEL_ROOT_DIR@ - KERNEL_SITE_DIR=@KERNEL_SITE_DIR@ - - KERNEL_LDFLAGS=@KERNEL_LDFLAGS@ - KERNEL_CXXFLAGS=@KERNEL_CXXFLAGS@ - - GUI_ROOT_DIR=@GUI_ROOT_DIR@ - GUI_LDFLAGS=@GUI_LDFLAGS@ - GUI_CXXFLAGS=@GUI_CXXFLAGS@ -endif - -## Installation points -prefix=@prefix@ -exec_prefix=@exec_prefix@ -bindir=@exec_prefix@/bin/salome -libdir=@exec_prefix@/lib@LIB_LOCATION_SUFFIX@/salome -# warning : if user give this path in configure we could have salome/salome :-( -includedir=@includedir@/salome -datadir=@datadir@/salome -idldir=${prefix}/idl/salome -sharedpydir=@exec_prefix@/lib@LIB_LOCATION_SUFFIX@/python$(PYTHON_VERSION)/site-packages/salome/shared_modules -incmakedir=${prefix}/salome_adm/unix - -docdir=${prefix}/doc/salome - -# -# begin of package rules -# - -.PHONY: all lib bin inc resources docs tests install uninstall dep depend depend_idl cleandep mostlyclean clean distclean - -.SUFFIXES: .cxx .cc .c .f .o .lo .idl .py .i .ui .po .qm - -all: - $(MAKE) inc - $(MAKE) depend_idl - $(MAKE) depend - $(MAKE) lib - $(MAKE) bin - $(MAKE) resources - -# -# add target to build administrative files -# - -Makefile: $(top_builddir)/config.status $(srcdir)/Makefile.in - cd $(top_builddir) ; ./config.status - -LOCAL_MAKE = make_commence make_conclude - -KERNEL_MAKE = -NOKERNEL_MAKE = - -ifeq ($(MED_WITH_KERNEL),yes) - LOCAL_MAKE += make_omniorb - - KERNEL_MAKE = make_module depend SALOMEconfig.h sstream - KERNEL_MAKE += F77config.h envScript - - NOKERNEL_MAKE = -else - KERNEL_MAKE = - - NOKERNEL_MAKE = make_module depend SALOMEconfig.h sstream - -endif - -$(top_builddir)/config.status: $(top_srcdir)/configure \ - $(LOCAL_MAKE:%=$(top_srcdir)/adm_local/unix/%.in) \ - $(KERNEL_MAKE:%=$(KERNEL_ROOT_DIR)/salome_adm/unix/%.in) \ - $(NOKERNEL_MAKE:%=$(top_srcdir)/adm_local_without_kernel/unix/%.in) - cd $(top_builddir) ; ./config.status --recheck - -# VPATH contain $(srcdir), so make configure is good in top_srcdir and we must add target configure otherwise :-) -ifneq ($(top_srcdir),$(srcdir)) -configure: $(top_srcdir)/configure -endif - -$(top_srcdir)/configure: $(top_srcdir)/configure.in $(top_srcdir)/aclocal.m4 - cd $(top_srcdir) ; autoconf - -$(top_srcdir)/configure.in: $(top_srcdir)/configure.in.base - cd $(top_srcdir) && ./build_configure - - -ifeq ($(MED_WITH_KERNEL),yes) - -ACLOCAL_SRC = \ -ac_cxx_bool.m4 check_corba.m4 \ -ac_cxx_depend_flag.m4 check_hdf5.m4 enable_pthreads.m4 \ -ac_cxx_mutable.m4 check_mico.m4 libtool.m4 \ -ac_cxx_namespaces.m4 check_omniorb.m4 pyembed.m4 \ -ac_cxx_partial_specialization.m4 python.m4 \ -ac_cxx_typename.m4 check_pthreads.m4 check_cas.m4 \ -ac_cc_warnings.m4 check_swig.m4 - -ACLOCAL_GUI = \ -check_vtk.m4 check_opengl.m4 check_qt.m4 \ -check_GUI.m4 check_corba_in_GUI.m4 - -$(top_srcdir)/aclocal.m4: $(ACLOCAL_SRC:%=@KERNEL_ROOT_DIR@/salome_adm/unix/config_files/%) \ - $(ACLOCAL_GUI:%=@GUI_ROOT_DIR@/adm_local/unix/config_files/%) - cd $(top_srcdir) ; aclocal -I adm_local/unix/config_files -I @KERNEL_ROOT_DIR@/salome_adm/unix/config_files \ - -I @GUI_ROOT_DIR@/adm_local/unix/config_files - -endif diff --git a/adm_local/unix/make_common_starter.am b/adm_local/unix/make_common_starter.am new file mode 100644 index 000000000..6a4c36d23 --- /dev/null +++ b/adm_local/unix/make_common_starter.am @@ -0,0 +1,59 @@ +# +# ============================================================ +# This file defines the common definitions used in several +# Makefile. This file must be included, if needed, by the file +# Makefile.am. +# ============================================================ +# + +# Standard directory for installation +salomeincludedir = $(includedir)/@PACKAGE@ +libdir = $(prefix)/lib@LIB_LOCATION_SUFFIX@/@PACKAGE@ +bindir = $(prefix)/bin/@PACKAGE@ +purebindir = $(prefix)/bin +salomescriptdir = $(bindir) + +# Tests environment folders +testsenvirondir = $(prefix)/Tests/environ +testsenvironcshdir = $(prefix)/Tests/environ/csh + +# Directory for installing idl files +salomeidldir = $(prefix)/idl/@PACKAGE@ + +# Directory for installing resource files +salomeresdir = $(prefix)/share/@PACKAGE@/resources/@MODULE_NAME@ + +# Directories for installing admin files +admlocaldir = $(prefix)/adm_local +admlocalunixdir = $(admlocaldir)/unix +admlocalm4dir = $(admlocaldir)/unix/config_files + +# Shared modules installation directory +sharedpkgpythondir =$(pkgpythondir)/shared_modules + +# Documentation directory +docdir = $(datadir)/doc/@PACKAGE@ + +# common rules + +# moc-files generation +%_moc.cxx: %.h + $(MOC) $< -o $@ + +# qm-files generation +%.qm: %.po + $(MSG2QM) $< $@ + +EXTRA_DIST=$(MOC_FILES:%_moc.cxx=%.h) $(nodist_salomeres_DATA:%.qm=%.po) + +mostlyclean-local: + rm -f @builddir@/*_moc.cxx + rm -f @builddir@/*.qm + +# tests +tests: unittest + +unittest: $(UNIT_TEST_PROG) + @if test "x$(UNIT_TEST_PROG)" != "x"; then \ + $(UNIT_TEST_PROG); \ + fi; diff --git a/adm_local/unix/make_conclude.in b/adm_local/unix/make_conclude.in deleted file mode 100644 index e53acdf51..000000000 --- a/adm_local/unix/make_conclude.in +++ /dev/null @@ -1,399 +0,0 @@ -#======================================================================= -# This section of this makefile comes from the file -# 'adm/unix/make_conclude' which was generated with config.status -# from file adm/unix/make_conclude.in -#======================================================================= -# -* Makefile *- -# -# Authors : Patrick GOLDBRONN (CEA) - Marc Tajchman (CEA) -# Date : 6/07/2001 -# $Header$ -# - -# ORB Specifics rules -@CORBA@ - -# transform idl reference in appropriate obj file -LIB_CLIENT_SRC = $(LIB_CLIENT_IDL:%.idl=%$(IDL_CLN_CXX)) -LIB_SERVER_SRC = $(LIB_SERVER_IDL:%.idl=%$(IDL_SRV_CXX)) -LIB_MOC_SRC = $(LIB_MOC:%.h=%_moc.cxx) -LIB_SRC+=$(LIB_MOC_SRC) -LIB_SWIG_SRC = $(SWIG_DEF:%.i=%_wrap.cxx) -LIB_DEP= $(LIB_SRC) $(LIB_CLIENT_SRC) $(LIB_SERVER_SRC) $(LIB_SWIG_SRC) - -LIB_CLIENT_OBJ = $(LIB_CLIENT_IDL:%.idl=%$(IDL_CLN_OBJ)) -LIB_SERVER_OBJ = $(LIB_SERVER_IDL:%.idl=%$(IDL_SRV_OBJ)) - -# declare dependences between SWIG input files -$(LIB_SWIG_SRC): $(SWIG_DEP:%=$(inc_builddir)/%) - -# transform c file in appropriate libtool obj file (.c, .cc and .cxx) -LIB_OBJ_C = $(patsubst %.c, %.lo, $(filter %.c, $(LIB_SRC))) -LIB_OBJ_CC = $(patsubst %.cc, %.lo, $(filter %.cc, $(LIB_SRC))) -LIB_OBJ_CXX = $(patsubst %.cxx, %.lo, $(filter %.cxx, $(LIB_SRC))) -LIB_SWIG_OBJ = $(LIB_SWIG_SRC:%.cxx=%.lo) -LIB_OBJ_F = $(patsubst %.f, %.lo, $(filter %.f, $(LIB_SRC))) - -# all libtool obj file in library -LIB_OBJ = $(LIB_OBJ_CXX) $(LIB_OBJ_CC) $(LIB_OBJ_C) $(LIB_CLIENT_OBJ:%.o=%.lo) $(LIB_SERVER_OBJ:%.o=%.lo) $(LIB_SWIG_OBJ) $(LIB_OBJ_F) - -# LIB_BUILD = $(LIB:%.la=$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/%.la) -LIB_BUILD = $(patsubst %.la, $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/%.la, $(filter %.la, $(LIB))) -LIB_BUILD_A = $(patsubst %.a, $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/%.a, $(filter %.a, $(LIB))) - -ifneq ($(findstring cmodule.la,$(filter %.la, $(LIB))),) -LIB_SWIG = $(patsubst %cmodule.la,%.so, $(filter %.la, $(LIB))) -else -LIB_SWIG = -endif - -lib: $(LIB_BUILD) $(LIB_CLIENT_PY) -# we don't build static library ! - -$(LIB_BUILD): $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/%.la: %.la - -$(RM) $@ - -$(RM) $(patsubst %.la, %.so, $@) - -$(RM) $(patsubst %.la, %.a, $@) - ln -sf $(CURDIR)/$< $@ || true - ln -sf $(patsubst %.la, %.so, $(CURDIR)/.libs/$<) \ - $(patsubst %.la, %.so, $@) || true - ln -sf $(patsubst %.la, %.so, $(CURDIR)/.libs/$<).0 \ - $(patsubst %.la, %.so, $@).0 || true - - if test "X$(LIB_SWIG)" != X; then \ - ln -sf $(patsubst %.la,%.so, $(CURDIR)/.libs/$<) $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/_$(LIB_SWIG) || true;\ - fi; - -$(LIB_BUILD_A): $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/%.a: %.a - -$(RM) $@ - ln -sf $(CURDIR)/$< $@ || true - -$(LIB): $(LIB_OBJ) - @$(LT) --mode=link $(CXX) -rpath $(libdir) -o $@ $(CXXFLAGS) $(LIB_OBJ) $(LDFLAGS) $(LIBS) - -# transform idl reference in appropriate obj file -BIN_CLIENT_SRC = $(BIN_CLIENT_IDL:%.idl=%$(IDL_CLN_CXX)) -BIN_SERVER_SRC = $(BIN_SERVER_IDL:%.idl=%$(IDL_SRV_CXX)) -BIN_MOC_SRC = $(BIN_MOC:%.h=%_moc.cxx) -BIN_SRC+=$(BIN_MOC_SRC) -BIN_DEP=$(BIN:%=%.cxx) $(BIN_SRC) $(BIN_CLIENT_SRC) $(BIN_SERVER_SRC) - -BIN_CLIENT_OBJ = $(BIN_CLIENT_IDL:%.idl=%$(IDL_CLN_OBJ)) -BIN_SERVER_OBJ = $(BIN_SERVER_IDL:%.idl=%$(IDL_SRV_OBJ)) -# transform c file in appropriate libtool obj file (.c) -BIN_OBJ_C = $(patsubst %.c, %.o, $(filter %.c, $(BIN_SRC))) -# transform c++ file in appropriate libtool obj file (.cc and .cxx) -BIN_OBJ_CC = $(patsubst %.cc, %.o, $(filter %.cc, $(BIN_SRC))) -BIN_OBJ_CXX = $(patsubst %.cxx, %.o, $(filter %.cxx, $(BIN_SRC))) -# all obj file in bin target -BIN_OBJ = $(BIN_OBJ_CC) $(BIN_OBJ_CXX) $(BIN_OBJ_C) $(BIN_CLIENT_OBJ) $(BIN_SERVER_OBJ) - -bin: $(BIN:%=$(top_builddir)/bin/salome/%) $(BIN) $(LIB) pyscripts sharedpyscripts - -BIN_LIB=$(LIB:lib%.la=-l%) - -$(BIN:%=$(top_builddir)/bin/salome/%) $(TEST_PROGS:%=$(top_builddir)/bin/salome/%): $(top_builddir)/bin/salome/%: % - -$(RM) $@ - ln -sf $(CURDIR)/$< $@ - -$(BIN) $(TEST_PROGS): %: %.lo $(BIN_OBJ) - $(CXX) $(CXXFLAGS) -o $@ $^ $(BIN_LIB) $(LDFLAGSFORBIN) $(LIBSFORBIN) - -# copy python scripts in $(top_builddir)/bin/salome -# -DEST_PYSCRIPTS = $(EXPORT_PYSCRIPTS:%=$(top_builddir)/bin/salome/%) -pyscripts: $(DEST_PYSCRIPTS) -$(DEST_PYSCRIPTS): $(top_builddir)/bin/salome/%: % - cp -f $< $@ - -# copy pyqt files in $(PYTHON_SHARED_SITE) -# -PYTHON_SHARED_SITE=$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/python$(PYTHON_VERSION)/site-packages/salome/shared_modules - -$(PYTHON_SHARED_SITE): - $(INSTALL) -d $@ - -DEST_SHAREDPYSCRIPTS = $(EXPORT_SHAREDPYSCRIPTS:%=$(PYTHON_SHARED_SITE)/%) -sharedpyscripts: $(PYTHON_SHARED_SITE) $(DEST_SHAREDPYSCRIPTS) -$(DEST_SHAREDPYSCRIPTS): $(PYTHON_SHARED_SITE)/%: % - cp -f $< $@ - -#check: test !!!! version before AG changes - -#tests: test !!!! version before AG changes - -#test: $(LIB) $(TEST_PROGS:%=$(top_builddir)/bin/salome/%) !!!! version before AG changes - -check: tests - - - - - -runtest_%: - @( LD_LIBRARY_PATH=$(top_builddir)/src/MEDMEM/.libs:$(top_builddir)/src/MEDWrapper/V2_1/Core/.libs:$${LD_LIBRARY_PATH} ; \ - SALOME_trace=local ; \ - export SALOME_trace ; \ - x=$@ ; \ - x=$${x#runtest_*} ; \ - echo -n "Passing test : "$$x ; \ - ./$$x > /dev/null ; \ - if test $$? != "0"; then \ - echo $$'\033'[1\;31m [ FAILED ] $$'\033'[0m ; \ - exit 2; \ - else \ - echo $$'\033'[1\;32m [ OK ] $$'\033'[0m \ ; \ - fi; ) - -runpytest_%: - @( LD_LIBRARY_PATH=$(top_builddir)/src/MEDMEM/.libs:$(top_builddir)/src/MEDWrapper/V2_1/Core/.libs:$${LD_LIBRARY_PATH} ; \ - PYTHONPATH=$(top_builddir)/src/MEDMEM_SWIG:$${PYTHONPATH} ; \ - SALOME_trace=local ; \ - export SALOME_trace ; \ - x=$@ ; \ - x=$${x#runpytest_*} ; \ - echo -n "Passing python test : "$$x ; \ - python $(srcdir)/$$x > /dev/null ; \ - if test $$? != "0"; then \ - echo $$'\033'[1\;31m [ FAILED ] $$'\033'[0m ; \ - exit 2; \ - else \ - echo $$'\033'[1\;32m [ OK ] $$'\033'[0m \ ; \ - fi; ) - -ALL_CHECK_TARGETS = $(patsubst %, runtest_%, $(TEST_PROGS)) - -tests: $(LIB) $(TEST_PROGS) $(ALL_CHECK_TARGETS) - @ln -fs $(top_builddir)/src/MEDMEM_SWIG/.libs/libMEDMEM_Swigcmodule.so $(top_builddir)/src/MEDMEM_SWIG/_libMEDMEM_Swig.so ; \ - for f in $(TEST_PYSCRIPTS); do \ - if [ x"$${f#*test}" != x"$${f}" ]; then \ - $(MAKE) runpytest_$$f ; \ - if test $$? != "0"; then \ - rm -f $(top_builddir)/src/MEDMEM_SWIG/_libMEDMEM_Swig.so ; \ - exit 2; \ - fi; \ - fi; \ - done ; \ - rm -f $(top_builddir)/src/MEDMEM_SWIG/_libMEDMEM_Swig.so ; - - - - -# copy header file in $(inc_builddir) -# -DEST_HEADERS = $(EXPORT_HEADERS:%=$(inc_builddir)/%) -inc: $(DEST_HEADERS) -$(DEST_HEADERS): $(inc_builddir)/%: % - cp -f $< $@ - -# build resources file (icons and messages) : .qm file from .po file -resources: $(PO_FILES:%.po=$(top_builddir)/share/salome/resources/%.qm) - -# Make installation directories if they don't exist. -$(libdir) $(includedir) $(bindir) $(datadir) $(idldir) $(sharedpydir): - $(INSTALL) -d $@ && chmod 755 $@ - -# Install the library, the public header files, and programs. -install: $(LIB) $(BIN) $(TEST_PROGS) $(libdir) $(includedir) $(bindir) $(datadir) $(idldir) install-python install-sharedpyqt install-qm -#install: $(LIB) $(BIN) $(libdir) $(includedir) $(bindir) $(datadir) $(idldir) install-python install-sharedpyqt install-qm - @for f in X $(LIB); do \ - if test $$f != X; then \ - ($(LT_INSTALL_LIB) $$f $(libdir)/. || exit 1); \ - fi; \ - done - @if test "X$(LIB_SWIG)" != X ; then \ - (cd $(libdir); ln -sf $(patsubst %.so, %cmodule.so, $(LIB_SWIG)) _$(LIB_SWIG) || true); \ - fi; - @for f in X $(BIN); do \ - if test $$f != X; then \ - ($(LT_INSTALL_PROG) $$f $(bindir)/. || exit 1); \ - fi; \ - done -# Install tests programmes in bindir - @for f in X $(TEST_PROGS); do \ - if test $$f != X; then \ - ($(LT_INSTALL_PROG) $$f $(bindir)/. || exit 1); \ - fi; \ - done -# Install exported includes in includedir - @for f in X $(EXPORT_HEADERS:%=$(srcdir)/%); do \ - if test $$f != X; then \ - (cp -p -f $$f $(includedir) || exit 1); \ - fi; \ - done - -# Install python script in $(bindir) -install-python: $(bindir) $(EXPORT_PYSCRIPTS:%=install-%) - -$(EXPORT_PYSCRIPTS:%=install-%): install-%: % - $(INSTALL_PROGRAM) $< $(bindir)/. - -#install-python: $(bindir) $(EXPORT_PYSCRIPTS) -# @for f in X $(EXPORT_PYSCRIPTS); do \ -# if test $$f != X; then \ -# ($(INSTALL_PROGRAM) $$f $(bindir)/. || exit 1); \ -# fi; \ -# done - -# Install pyqt script in $(install-sharedpyqt) -install-sharedpyqt: $(sharedpydir) $(EXPORT_SHAREDPYSCRIPTS:%=install-%) - -$(EXPORT_SHAREDPYSCRIPTS:%=install-%): install-%: % - $(INSTALL_PROGRAM) $< $(sharedpydir)/. - - -# generic rule to install .qm files : -install-qm: resources - $(INSTALL) -d $(datadir)/resources - @for f in X $(PO_FILES:%.po=$(top_builddir)/share/salome/resources/%.qm); do \ - if test $$f != X; then \ - ($(INSTALL_DATA) $$f $(datadir)/resources/. || exit 1); \ - fi; \ - done - -# Removes those things that `make install' (would have) installed. -uninstall: - @if test "X$(LIB)" != X; then \ - for f in $(LIB); do \ - $(LT_UNINSTALL) $(libdir)/$$f; \ - done; \ - fi - @if test "X$(BIN)" != X; then \ - for f in $(BIN); do \ - $(LT_UNINSTALL) $(bindir)/$$f; \ - done; \ - fi - @for f in X $(TEST_PROGS); do \ - if test $$f != X; then \ - $(LT_UNINSTALL) $(bindir)/$$f; \ - fi; \ - done -# Uninstall exported includes in includedir - @for f in X $(EXPORT_HEADERS); do \ - if test $$f != X; then \ - $(LT_UNINSTALL) $(includedir)/$$f; \ - fi; \ - done -# Uninstall python script in $(bindir) - @for f in X $(EXPORT_PYSCRIPTS); do \ - if test $$f != X; then \ - $(LT_UNINSTALL) $(bindir)/$$f ; \ - fi; \ - done - -# Uninstall pyqt script in $(sharedpydir) - @for f in X $(EXPORT_SHAREDPYSCRIPTS); do \ - if test $$f != X; then \ - $(LT_UNINSTALL) $(sharedpydir)/$$f ; \ - fi; \ - done - -# Uninstall qm files - @for f in X $(PO_FILES:%.po=%.qm); do \ - if test $$f != X; then \ - $(LT_UNINSTALL) $(datadir)/resources/$$f ; \ - fi; \ - done - -# remove all dependencies files -# -cleandep: - -$(RM) .dep* - -# Removes temporary files without removing the final target files. That is, -# remove things like object files but not libraries or executables. -# -mostlyclean: cleandep - -$(RM) $(LIB_OBJ) $(LIB_OBJ:.lo=.o) - -$(RM) $(BIN_OBJ) $(BIN:%=%.o) - -$(RM) $(TEST_OBJ) $(TEST_OBJ:.lo=.o) - -$(RM) $(PROG_OBJ) $(PROG_OBJ:.lo=.o) $(MOSTLYCLEAN) - -# Like `mostlyclean' except it also removes the final targets: things like -# libraries and executables. This target doesn't remove any file that -# is part of the SALOME distribution. -# -clean: mostlyclean - -$(RM) $(LIB) $(TEST_PROGS) $(BIN) $(CLEAN) - -$(RM) TAGS *~ *# core *.core - -$(RM) -r .libs - -$(RM) $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/$(LIB) - -$(RM) $(patsubst %,$(top_builddir)/bin/salome/%, $(BIN)) - -$(RM) $(patsubst %.la, %.so, $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/$(LIB)) - -$(RM) $(patsubst %.la, %.a, $(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome/$(LIB)) -# remove idl generated files (sources) - -$(RM) $(LIB_CLIENT_SRC) $(LIB_SERVER_SRC) $(BIN_CLIENT_SRC) $(BIN_SERVER_SRC) -# remove idl generated files (headers) - -$(RM) $(LIB_CLIENT_IDL:%.idl=%$(IDL_CLN_H)) $(LIB_SERVER_IDL:%.idl=%$(IDL_SRV_H)) - -$(RM) $(BIN_CLIENT_IDL:%.idl=%$(IDL_CLN_H)) $(BIN_SERVER_IDL:%.idl=%$(IDL_SRV_H)) - -$(RM) $(LIB_MOC_SRC) $(BIN_MOC_SRC) - -$(RM) $(LIB_SWIG_SRC) - -# Like `clean' except it also removes files that were created by running -# configure. If you've unpacked the source and built without creating -# any other files, then `make distclean' will leave only the files that were -# in the distribution. -# -distclean: clean - #remove qm file ! - -$(RM) $(PO_FILES:%.po=%.qm) $(PO_FILES:%.po=$(top_builddir)/share/salome/resources/%.qm) - #remove include files - -$(RM) $(DEST_HEADERS) - -$(RM) $(DISTCLEAN) *.bak *.old *.new .dep* - @if test -f $(srcdir)/Makefile.in; then \ - (@SETX@; $(RM) Makefile); \ - fi - - -#implicits rules -.cc.o: - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< - -.cc.lo: - $(LT) --mode=compile $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< - -.cxx.o: - $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< - -.cxx.lo: - $(LT) --mode=compile $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< - -.c.o: - $(CC) $(CFLAGS) $(CPPFLAGS) -c $< - -.c.lo: - $(LT_COMPILE) $(CFLAGS) $(CPPFLAGS) -c $< - -.f.o: - $(FC) $(FFLAGS) -c $< -o $@ - -.f.lo: - $(LT) --mode=compile $(FC) $(FFLAGS) -c $< - -.ui.h: - $(UIC) -o $@ $< - -.ui.cxx: - $(UIC) -o $@ -i $*.h $< - -#pattern rules -%_moc.cxx : %.h - $(MOC) $< -o $@ - -%_wrap.cxx : %.i - $(SWIG) $(SWIG_FLAGS) -o $@ $< - -$(top_builddir)/share/salome/resources/%.qm: %.po - $(MSG2QM) $< $@ ; \ - -#------------------------------------------------------------------------------ -# The following section of this makefile contains dependencies between the -# source files and the header files. If GNU make and GCC are being used then -# the dependencies are in the form of rules that cause the information to -# be kept updated automatically. Otherwise the dependencies are listed -# explicitly and come from the `.distdep' files in the various directories. -# These files are part of the distribution and are generated automatically on -# GNU/GCC systems. -#------------------------------------------------------------------------------ - -@DEPEND@ diff --git a/adm_local/unix/make_omniorb.in b/adm_local/unix/make_omniorb.in deleted file mode 100644 index 84679a9ea..000000000 --- a/adm_local/unix/make_omniorb.in +++ /dev/null @@ -1,53 +0,0 @@ -#======================================================================= -# Begin specific part to omniorb -# (include from file adm/unix/make_omniorb generated by -# adm/unix/make_omniorb.in) -#======================================================================= -# -* Makefile *- -# -# Author : Patrick GOLDBRONN (CEA) -# Date : 29/06/2001 -# $Header$ -# - -# Client and server object are the same with omniorb -# There are one header file and one source file generate - -#IDLOBJ=$(IDLSRC:%.idl=%$(IDL_CLN_OBJ)) - -# dependancies between idl and it's generated files -%$(OMNIORB_IDL_CLN_CXX) %$(OMNIORB_IDL_CLN_H): ${KERNEL_ROOT_DIR}/idl/salome/%.idl - $(OMNIORB_IDL) $(IDLCXXFLAGS) $(OMNIORB_IDLCXXFLAGS) $< - -%$(OMNIORB_IDL_CLN_CXX) %$(OMNIORB_IDL_CLN_H): ${top_srcdir}/idl/%.idl - $(OMNIORB_IDL) $(IDLCXXFLAGS) $(OMNIORB_IDLCXXFLAGS) $< - -# dependncies between idl files -depend_idl: .depidl - -# we use cpp to generate dependencies between idl files. -# we change cpp output to keep only idl file and transform it to get a suitable rule -.depidl: $(IDL_FILES) - @touch $@ - @for dep in $? dummy; do \ - if [ $$dep != "dummy" ]; then \ - echo Building dependencies for $$dep; \ - basedep=`basename $$dep .idl`; \ - header="$$basedep"$(IDL_CLN_H); \ - sed '\%^'"$$header"':%,\%[^\\]$$%d' <$@ >$@- && mv $@- $@; \ - $(CPP) $(C_DEPEND_FLAG) -I$(srcdir) $$dep 2>/dev/null | \ - sed `echo "s%$$basedep\\.idl%$$header:%g"` | \ - sed 's% $(srcdir)/% %g' | \ - sed 's% $(top_srcdir)/% %g' | \ - sed 's% $(top_builddir)/% %g' | \ - sed 's%^.*:\.o: *%%' | sed 's%^ *\\ *%%'| sed 's%^ *\(.*\):%\1:%' | \ - sed 's/\.idl/$(IDL_CLN_H)/' >>$@; \ - echo '' >>$@; \ - fi; \ - done ; - --include .depidl - -#======================================================================= -# End specific part to omniorb -#======================================================================= diff --git a/adm_local_without_kernel/Makefile.am b/adm_local_without_kernel/Makefile.am new file mode 100644 index 000000000..5fc3e2c7a --- /dev/null +++ b/adm_local_without_kernel/Makefile.am @@ -0,0 +1,22 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS= unix diff --git a/adm_local_without_kernel/unix/Makefile.am b/adm_local_without_kernel/unix/Makefile.am new file mode 100644 index 000000000..facd4e6f4 --- /dev/null +++ b/adm_local_without_kernel/unix/Makefile.am @@ -0,0 +1,22 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = config_files diff --git a/adm_local_without_kernel/unix/config_files/Makefile.am b/adm_local_without_kernel/unix/config_files/Makefile.am new file mode 100644 index 000000000..86e4051e0 --- /dev/null +++ b/adm_local_without_kernel/unix/config_files/Makefile.am @@ -0,0 +1,46 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +admlocalwithoutkerneldir = $(prefix)/adm_local_without_kernel +admlocalwithoutkernelm4dir = $(prefix)/adm_local_without_kernel/unix/config_files + +dist_admlocalwithoutkernelm4_DATA=\ + ac_cxx_depend_flag.m4 \ + ac_cxx_have_sstream.m4 \ + ac_cxx_namespaces.m4 \ + ac_cxx_option.m4 \ + ac_cxx_template_options.m4 \ + ac_cxx_use_std_iostream.m4 \ + ac_cxx_warnings.m4 \ + ac_linker_options.m4 \ + check_boost.m4 \ + check_cppunit.m4 \ + check_hdf5.m4 \ + check_pthreads.m4 \ + check_swig.m4 \ + config.guess \ + config.sub \ + enable_pthreads.m4 \ + install-sh \ + libtool.m4 \ + ltconfig \ + ltmain.sh \ + production.m4 \ + python.m4 diff --git a/adm_local_without_kernel/unix/config_files/check_cppunit.m4 b/adm_local_without_kernel/unix/config_files/check_cppunit.m4 new file mode 100644 index 000000000..e78b4fa24 --- /dev/null +++ b/adm_local_without_kernel/unix/config_files/check_cppunit.m4 @@ -0,0 +1,114 @@ + +AC_DEFUN([CHECK_CPPUNIT],[ + +AC_CHECKING(for cppunit) + +cppunit_ok=yes + +dnl were is cppunit ? + +AC_ARG_WITH(cppunit, + [AC_HELP_STRING([--with-cppunit=DIR],[directory path to CPPUNIT installation])], + [CPPUNITHOME="$withval" + AC_MSG_RESULT("select $withval as path to CPPUNIT") + ]) + +AC_ARG_WITH(cppunit_inc, + [AC_HELP_STRING([--with-cppunit_inc=DIR],[directory path to CPPUNIT includes])], + [CPPUNIT_INCLUDES="$withval" + AC_MSG_RESULT("select $withval as path to CPPUNIT includes") + ]) + +if test -z "$CPPUNITHOME"; then + AC_MSG_RESULT(CPPUNITHOME not defined) + exits_ok=no + if test "x$exits_ok" = "xno"; then + for d in /usr/local /usr ; do + AC_CHECK_FILE(${d}/lib64/libcppunit.so,exits_ok=yes,exits_ok=no) + if test "x$exits_ok" = "xyes"; then + CPPUNITHOME=$d + AC_MSG_RESULT(libcppunit.so detected in $d/lib64) + break + fi + AC_CHECK_FILE(${d}/lib/libcppunit.so,exits_ok=yes,exits_ok=no) + if test "x$exits_ok" = "xyes"; then + CPPUNITHOME=$d + AC_MSG_RESULT(libcppunit.so detected in $d/lib) + break + fi + done + fi + if test "x$exits_ok" = "xno"; then + for d in `echo $LD_LIBRARY_PATH | sed -e "s/:/ /g"` ; do + if test -f $d/libcppunit.so ; then + AC_MSG_RESULT(libcppunit.so detected in $d) + CPPUNITHOME=$d + CPPUNITHOME=`echo ${CPPUNITHOME} | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` + exits_ok=yes + break + fi + done + fi + if test "x$exits_ok" = "xyes"; then + if test -z "$CPPUNIT_INCLUDES"; then + CPPUNIT_INCLUDES=$CPPUNITHOME"/include" + fi + fi +else + if test -z "$CPPUNIT_INCLUDES"; then + CPPUNIT_INCLUDES="$CPPUNITHOME/include" + fi +fi + +if test "x$cppunit_ok" = xno -o ! -d "$CPPUNITHOME" ; then + AC_MSG_RESULT(no) + AC_MSG_WARN(cppunit not found) + cppunit_ok=no +else + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + CPPFLAGS_old=$CPPFLAGS + CPPFLAGS="$CPPFLAGS -I$CPPUNIT_INCLUDES" + + AC_CHECK_HEADER(cppunit/extensions/HelperMacros.h,cppunit_ok=yes,cppunit_ok=no) + + CPPFLAGS=$CPPFLAGS_old + + if test "x$cppunit_ok" = xno ; then + AC_MSG_RESULT(no) + AC_MSG_WARN(cppunit not found) + else + cppunit_ok=yes + fi + + if test "x$cppunit_ok" = "xno" + then + AC_MSG_RESULT(unable to found cppunit headers and library) + AC_MSG_RESULT(CPPUNITHOME environment variable may be wrong) + else + if test "x$CPPUNIT_INCLUDES" = "x/usr/include" + then + CPPUNIT_INCLUDES="" + else + CPPUNIT_INCLUDES="-I$CPPUNIT_INCLUDES" + fi + if test "x$CPPUNITHOME" = "x/usr" + then + CPPUNIT_LIBS=" -lcppunit" + else + CPPUNIT_LIBS="-L$CPPUNITHOME/lib -lcppunit" + fi + + AC_SUBST(CPPUNIT_INCLUDES) + AC_SUBST(CPPUNIT_LIBS) + AC_SUBST(cppunit_ok) + AC_MSG_RESULT(yes) + fi +fi + +AM_CONDITIONAL(CPPUNIT_IS_OK, [test x"$cppunit_ok" = xyes]) + +AC_LANG_RESTORE + +])dnl +dnl diff --git a/adm_local_without_kernel/unix/config_files/libtool.m4 b/adm_local_without_kernel/unix/config_files/libtool.m4 index f28545379..2ac1c3967 100644 --- a/adm_local_without_kernel/unix/config_files/libtool.m4 +++ b/adm_local_without_kernel/unix/config_files/libtool.m4 @@ -1,105 +1,509 @@ -## libtool.m4 - Configure libtool for the target system. -*-Shell-script-*- -## Copyright (C) 1996-1999, 2000 Free Software Foundation, Inc. +# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- +## Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 +## Free Software Foundation, Inc. ## Originally by Gordon Matzigkeit , 1996 ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, but -## WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -## -## As a special exception to the GNU General Public License, if you -## distribute this file as part of a program that contains a -## configuration script generated by Autoconf, you may include it under -## the same distribution terms that you use for the rest of that program. +## This file is free software; the Free Software Foundation gives +## unlimited permission to copy and/or distribute it, with or without +## modifications, as long as this notice is preserved. + +# serial 47 AC_PROG_LIBTOOL -# serial 40 AC_PROG_LIBTOOL + +# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED) +# ----------------------------------------------------------- +# If this macro is not defined by Autoconf, define it here. +m4_ifdef([AC_PROVIDE_IFELSE], + [], + [m4_define([AC_PROVIDE_IFELSE], + [m4_ifdef([AC_PROVIDE_$1], + [$2], [$3])])]) + + +# AC_PROG_LIBTOOL +# --------------- AC_DEFUN([AC_PROG_LIBTOOL], -[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl +[AC_REQUIRE([_AC_PROG_LIBTOOL])dnl +dnl If AC_PROG_CXX has already been expanded, run AC_LIBTOOL_CXX +dnl immediately, otherwise, hook it in at the end of AC_PROG_CXX. + AC_PROVIDE_IFELSE([AC_PROG_CXX], + [AC_LIBTOOL_CXX], + [define([AC_PROG_CXX], defn([AC_PROG_CXX])[AC_LIBTOOL_CXX + ])]) +dnl And a similar setup for Fortran 77 support + AC_PROVIDE_IFELSE([AC_PROG_F77], + [AC_LIBTOOL_F77], + [define([AC_PROG_F77], defn([AC_PROG_F77])[AC_LIBTOOL_F77 +])]) -# Save cache, so that ltconfig can load it -AC_CACHE_SAVE +dnl Quote A][M_PROG_GCJ so that aclocal doesn't bring it in needlessly. +dnl If either AC_PROG_GCJ or A][M_PROG_GCJ have already been expanded, run +dnl AC_LIBTOOL_GCJ immediately, otherwise, hook it in at the end of both. + AC_PROVIDE_IFELSE([AC_PROG_GCJ], + [AC_LIBTOOL_GCJ], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], + [AC_LIBTOOL_GCJ], + [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ], + [AC_LIBTOOL_GCJ], + [ifdef([AC_PROG_GCJ], + [define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[AC_LIBTOOL_GCJ])]) + ifdef([A][M_PROG_GCJ], + [define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[AC_LIBTOOL_GCJ])]) + ifdef([LT_AC_PROG_GCJ], + [define([LT_AC_PROG_GCJ], + defn([LT_AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])])]) +])])# AC_PROG_LIBTOOL -# Actually configure libtool. ac_aux_dir is where install-sh is found. -CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" \ -LD="$LD" LDFLAGS="$LDFLAGS" LIBS="$LIBS" \ -LN_S="$LN_S" NM="$NM" RANLIB="$RANLIB" \ -DLLTOOL="$DLLTOOL" AS="$AS" OBJDUMP="$OBJDUMP" \ -${CONFIG_SHELL-/bin/sh} $ac_aux_dir/ltconfig --no-reexec \ -$libtool_flags $ac_aux_dir/ltmain.sh $lt_target \ -|| AC_MSG_ERROR([libtool configure failed]) -# Reload cache, that may have been modified by ltconfig -AC_CACHE_LOAD +# _AC_PROG_LIBTOOL +# ---------------- +AC_DEFUN([_AC_PROG_LIBTOOL], +[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl +AC_BEFORE([$0],[AC_LIBTOOL_CXX])dnl +AC_BEFORE([$0],[AC_LIBTOOL_F77])dnl +AC_BEFORE([$0],[AC_LIBTOOL_GCJ])dnl # This can be used to rebuild libtool when needed -LIBTOOL_DEPS="$ac_aux_dir/ltconfig $ac_aux_dir/ltmain.sh" +LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh" # Always use our own libtool. LIBTOOL='$(SHELL) $(top_builddir)/libtool' AC_SUBST(LIBTOOL)dnl -# Redirect the config.log output again, so that the ltconfig log is not -# clobbered by the next message. -exec 5>>./config.log -]) +# Prevent multiple expansion +define([AC_PROG_LIBTOOL], []) +])# _AC_PROG_LIBTOOL + +# AC_LIBTOOL_SETUP +# ---------------- AC_DEFUN([AC_LIBTOOL_SETUP], -[AC_PREREQ(2.13)dnl +[AC_PREREQ(2.50)dnl AC_REQUIRE([AC_ENABLE_SHARED])dnl AC_REQUIRE([AC_ENABLE_STATIC])dnl AC_REQUIRE([AC_ENABLE_FAST_INSTALL])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl -AC_REQUIRE([AC_PROG_RANLIB])dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_PROG_LD])dnl +AC_REQUIRE([AC_PROG_LD_RELOAD_FLAG])dnl AC_REQUIRE([AC_PROG_NM])dnl + AC_REQUIRE([AC_PROG_LN_S])dnl +AC_REQUIRE([AC_DEPLIBS_CHECK_METHOD])dnl +# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers! +AC_REQUIRE([AC_OBJEXT])dnl +AC_REQUIRE([AC_EXEEXT])dnl dnl -case "$target" in -NONE) lt_target="$host" ;; -*) lt_target="$target" ;; +AC_LIBTOOL_SYS_MAX_CMD_LEN +AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE +AC_LIBTOOL_OBJDIR + +AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl +_LT_AC_PROG_ECHO_BACKSLASH + +case $host_os in +aix3*) + # AIX sometimes has problems with the GCC collect2 program. For some + # reason, if we set the COLLECT_NAMES environment variable, the problems + # vanish in a puff of smoke. + if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES + fi + ;; esac -# Check for any special flags to pass to ltconfig. -# -# the following will cause an existing older ltconfig to fail, so -# we ignore this at the expense of the cache file... Checking this -# will just take longer ... bummer! -#libtool_flags="--cache-file=$cache_file" -# -test "$enable_shared" = no && libtool_flags="$libtool_flags --disable-shared" -test "$enable_static" = no && libtool_flags="$libtool_flags --disable-static" -test "$enable_fast_install" = no && libtool_flags="$libtool_flags --disable-fast-install" -test "$ac_cv_prog_gcc" = yes && libtool_flags="$libtool_flags --with-gcc" -test "$ac_cv_prog_gnu_ld" = yes && libtool_flags="$libtool_flags --with-gnu-ld" -ifdef([AC_PROVIDE_AC_LIBTOOL_DLOPEN], -[libtool_flags="$libtool_flags --enable-dlopen"]) -ifdef([AC_PROVIDE_AC_LIBTOOL_WIN32_DLL], -[libtool_flags="$libtool_flags --enable-win32-dll"]) -AC_ARG_ENABLE(libtool-lock, - [ --disable-libtool-lock avoid locking (might break parallel builds)]) -test "x$enable_libtool_lock" = xno && libtool_flags="$libtool_flags --disable-lock" -test x"$silent" = xyes && libtool_flags="$libtool_flags --silent" +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +Xsed='sed -e 1s/^X//' +[sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g'] + +# Same as above, but do not quote variable references. +[double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g'] + +# Sed substitution to delay expansion of an escaped shell variable in a +# double_quote_subst'ed string. +delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' + +# Sed substitution to avoid accidental globbing in evaled expressions +no_glob_subst='s/\*/\\\*/g' + +# Constants: +rm="rm -f" + +# Global variables: +default_ofile=libtool +can_build_shared=yes + +# All known linkers require a `.a' archive for static linking (except M$VC, +# which needs '.lib'). +libext=a +ltmain="$ac_aux_dir/ltmain.sh" +ofile="$default_ofile" +with_gnu_ld="$lt_cv_prog_gnu_ld" + +AC_CHECK_TOOL(AR, ar, false) +AC_CHECK_TOOL(RANLIB, ranlib, :) +AC_CHECK_TOOL(STRIP, strip, :) + +old_CC="$CC" +old_CFLAGS="$CFLAGS" + +# Set sane defaults for various variables +test -z "$AR" && AR=ar +test -z "$AR_FLAGS" && AR_FLAGS=cru +test -z "$AS" && AS=as +test -z "$CC" && CC=cc +test -z "$LTCC" && LTCC=$CC +test -z "$DLLTOOL" && DLLTOOL=dlltool +test -z "$LD" && LD=ld +test -z "$LN_S" && LN_S="ln -s" +test -z "$MAGIC_CMD" && MAGIC_CMD=file +test -z "$NM" && NM=nm +test -z "$SED" && SED=sed +test -z "$OBJDUMP" && OBJDUMP=objdump +test -z "$RANLIB" && RANLIB=: +test -z "$STRIP" && STRIP=: +test -z "$ac_objext" && ac_objext=o + +# Determine commands to create old-style static archives. +old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs' +old_postinstall_cmds='chmod 644 $oldlib' +old_postuninstall_cmds= + +if test -n "$RANLIB"; then + case $host_os in + openbsd*) + old_postinstall_cmds="\$RANLIB -t \$oldlib~$old_postinstall_cmds" + ;; + *) + old_postinstall_cmds="\$RANLIB \$oldlib~$old_postinstall_cmds" + ;; + esac + old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib" +fi + +_LT_CC_BASENAME([$compiler]) + +# Only perform the check for file, if the check method requires it +case $deplibs_check_method in +file_magic*) + if test "$file_magic_cmd" = '$MAGIC_CMD'; then + AC_PATH_MAGIC + fi + ;; +esac + +AC_PROVIDE_IFELSE([AC_LIBTOOL_DLOPEN], enable_dlopen=yes, enable_dlopen=no) +AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL], +enable_win32_dll=yes, enable_win32_dll=no) + +AC_ARG_ENABLE([libtool-lock], + [AC_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes + +AC_ARG_WITH([pic], + [AC_HELP_STRING([--with-pic], + [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], + [pic_mode="$withval"], + [pic_mode=default]) +test -z "$pic_mode" && pic_mode=default + +# Use C for the default configuration in the libtool script +tagname= +AC_LIBTOOL_LANG_C_CONFIG +_LT_AC_TAGCONFIG +])# AC_LIBTOOL_SETUP + + +# _LT_AC_SYS_COMPILER +# ------------------- +AC_DEFUN([_LT_AC_SYS_COMPILER], +[AC_REQUIRE([AC_PROG_CC])dnl + +# If no C compiler was specified, use CC. +LTCC=${LTCC-"$CC"} + +# Allow CC to be a program name with arguments. +compiler=$CC +])# _LT_AC_SYS_COMPILER + + +# _LT_CC_BASENAME(CC) +# ------------------- +# Calculate cc_basename. Skip known compiler wrappers and cross-prefix. +AC_DEFUN([_LT_CC_BASENAME], +[for cc_temp in $1""; do + case $cc_temp in + compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; + distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; + \-*) ;; + *) break;; + esac +done +cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"` +]) + + +# _LT_COMPILER_BOILERPLATE +# ------------------------ +# Check for compiler boilerplate output or warnings with +# the simple compiler test code. +AC_DEFUN([_LT_COMPILER_BOILERPLATE], +[ac_outfile=conftest.$ac_objext +printf "$lt_simple_compile_test_code" >conftest.$ac_ext +eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d' >conftest.err +_lt_compiler_boilerplate=`cat conftest.err` +$rm conftest* +])# _LT_COMPILER_BOILERPLATE + + +# _LT_LINKER_BOILERPLATE +# ---------------------- +# Check for linker boilerplate output or warnings with +# the simple link test code. +AC_DEFUN([_LT_LINKER_BOILERPLATE], +[ac_outfile=conftest.$ac_objext +printf "$lt_simple_link_test_code" >conftest.$ac_ext +eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d' >conftest.err +_lt_linker_boilerplate=`cat conftest.err` +$rm conftest* +])# _LT_LINKER_BOILERPLATE + + +# _LT_AC_SYS_LIBPATH_AIX +# ---------------------- +# Links a minimal program and checks the executable +# for the system default hardcoded library path. In most cases, +# this is /usr/lib:/lib, but when the MPI compilers are used +# the location of the communication and MPI libs are included too. +# If we don't find anything, use the default library path according +# to the aix ld manual. +AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX], +[AC_LINK_IFELSE(AC_LANG_PROGRAM,[ +aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'` +# Check for a 64-bit object if we didn't find anything. +if test -z "$aix_libpath"; then aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } +}'`; fi],[]) +if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi +])# _LT_AC_SYS_LIBPATH_AIX + + +# _LT_AC_SHELL_INIT(ARG) +# ---------------------- +AC_DEFUN([_LT_AC_SHELL_INIT], +[ifdef([AC_DIVERSION_NOTICE], + [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)], + [AC_DIVERT_PUSH(NOTICE)]) +$1 +AC_DIVERT_POP +])# _LT_AC_SHELL_INIT + + +# _LT_AC_PROG_ECHO_BACKSLASH +# -------------------------- +# Add some code to the start of the generated configure script which +# will find an echo command which doesn't interpret backslashes. +AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH], +[_LT_AC_SHELL_INIT([ +# Check that we are running under the correct shell. +SHELL=${CONFIG_SHELL-/bin/sh} + +case X$ECHO in +X*--fallback-echo) + # Remove one level of quotation (which was required for Make). + ECHO=`echo "$ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','` + ;; +esac + +echo=${ECHO-echo} +if test "X[$]1" = X--no-reexec; then + # Discard the --no-reexec flag, and continue. + shift +elif test "X[$]1" = X--fallback-echo; then + # Avoid inline document here, it may be left over + : +elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then + # Yippee, $echo works! + : +else + # Restart under the correct shell. + exec $SHELL "[$]0" --no-reexec ${1+"[$]@"} +fi + +if test "X[$]1" = X--fallback-echo; then + # used as fallback echo + shift + cat </dev/null 2>&1 && unset CDPATH + +if test -z "$ECHO"; then +if test "X${echo_test_string+set}" != Xset; then +# find a string as large as possible, as long as the shell can cope with it + for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do + # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ... + if (echo_test_string="`eval $cmd`") 2>/dev/null && + echo_test_string="`eval $cmd`" && + (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null + then + break + fi + done +fi + +if test "X`($echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + : +else + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using + # echo "$something" | sed 's/\\/\\\\/g' + # + # So, first we look for a working echo in the user's PATH. + + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for dir in $PATH /usr/ucb; do + IFS="$lt_save_ifs" + if (test -f $dir/echo || test -f $dir/echo$ac_exeext) && + test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + echo="$dir/echo" + break + fi + done + IFS="$lt_save_ifs" + + if test "X$echo" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # This shell has a builtin print -r that does the trick. + echo='print -r' + elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) && + test "X$CONFIG_SHELL" != X/bin/ksh; then + # If we have ksh, try running configure again with it. + ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh} + export ORIGINAL_CONFIG_SHELL + CONFIG_SHELL=/bin/ksh + export CONFIG_SHELL + exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"} + else + # Try using printf. + echo='printf %s\n' + if test "X`($echo '\t') 2>/dev/null`" = 'X\t' && + echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + # Cool, printf works + : + elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL + export CONFIG_SHELL + SHELL="$CONFIG_SHELL" + export SHELL + echo="$CONFIG_SHELL [$]0 --fallback-echo" + elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` && + test "X$echo_testing_string" = 'X\t' && + echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` && + test "X$echo_testing_string" = "X$echo_test_string"; then + echo="$CONFIG_SHELL [$]0 --fallback-echo" + else + # maybe with a smaller string... + prev=: + + for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do + if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null + then + break + fi + prev="$cmd" + done + + if test "$prev" != 'sed 50q "[$]0"'; then + echo_test_string=`eval $prev` + export echo_test_string + exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"} + else + # Oops. We lost completely, so just stick with echo. + echo=echo + fi + fi + fi + fi +fi +fi + +# Copy echo and quote the copy suitably for passing to libtool from +# the Makefile, instead of quoting the original, which is used later. +ECHO=$echo +if test "X$ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then + ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo" +fi + +AC_SUBST(ECHO) +])])# _LT_AC_PROG_ECHO_BACKSLASH + + +# _LT_AC_LOCK +# ----------- +AC_DEFUN([_LT_AC_LOCK], +[AC_ARG_ENABLE([libtool-lock], + [AC_HELP_STRING([--disable-libtool-lock], + [avoid locking (might break parallel builds)])]) +test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes # Some flags need to be propagated to the compiler or linker for good # libtool support. -case "$lt_target" in +case $host in +ia64-*-hpux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *ELF-32*) + HPUX_IA64_MODE="32" + ;; + *ELF-64*) + HPUX_IA64_MODE="64" + ;; + esac + fi + rm -rf conftest* + ;; *-*-irix6*) # Find out which ABI we are using. echo '[#]line __oline__ "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then - case "`/usr/bin/file conftest.o`" in + if test "$lt_cv_prog_gnu_ld" = yes; then + case `/usr/bin/file conftest.$ac_objext` in + *32-bit*) + LD="${LD-ld} -melf32bsmip" + ;; + *N32*) + LD="${LD-ld} -melf32bmipn32" + ;; + *64-bit*) + LD="${LD-ld} -melf64bmip" + ;; + esac + else + case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; @@ -110,6 +514,49 @@ case "$lt_target" in LD="${LD-ld} -64" ;; esac + fi + fi + rm -rf conftest* + ;; + +x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*|s390*-*linux*|sparc*-*linux*) + # Find out which ABI we are using. + echo 'int i;' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case "`/usr/bin/file conftest.o`" in + *32-bit*) + case $host in + x86_64-*linux*) + LD="${LD-ld} -m elf_i386" + ;; + ppc64-*linux*|powerpc64-*linux*) + LD="${LD-ld} -m elf32ppclinux" + ;; + s390x-*linux*) + LD="${LD-ld} -m elf_s390" + ;; + sparc64-*linux*) + LD="${LD-ld} -m elf32_sparc" + ;; + esac + ;; + *64-bit*) + case $host in + x86_64-*linux*) + LD="${LD-ld} -m elf_x86_64" + ;; + ppc*-*linux*|powerpc*-*linux*) + LD="${LD-ld} -m elf64ppc" + ;; + s390*-*linux*) + LD="${LD-ld} -m elf64_s390" + ;; + sparc*-*linux*) + LD="${LD-ld} -m elf64_sparc" + ;; + esac + ;; + esac fi rm -rf conftest* ;; @@ -119,321 +566,5620 @@ case "$lt_target" in SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -belf" AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, - [AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])]) + [AC_LANG_PUSH(C) + AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) + AC_LANG_POP]) if test x"$lt_cv_cc_needs_belf" != x"yes"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS="$SAVE_CFLAGS" fi ;; - -ifdef([AC_PROVIDE_AC_LIBTOOL_WIN32_DLL], -[*-*-cygwin* | *-*-mingw*) +AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL], +[*-*-cygwin* | *-*-mingw* | *-*-pw32*) AC_CHECK_TOOL(DLLTOOL, dlltool, false) AC_CHECK_TOOL(AS, as, false) AC_CHECK_TOOL(OBJDUMP, objdump, false) ;; -]) + ]) esac -]) -# AC_LIBTOOL_DLOPEN - enable checks for dlopen support -AC_DEFUN([AC_LIBTOOL_DLOPEN], [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])]) - -# AC_LIBTOOL_WIN32_DLL - declare package support for building win32 dll's -AC_DEFUN([AC_LIBTOOL_WIN32_DLL], [AC_BEFORE([$0], [AC_LIBTOOL_SETUP])]) - -# AC_ENABLE_SHARED - implement the --enable-shared flag -# Usage: AC_ENABLE_SHARED[(DEFAULT)] -# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to -# `yes'. -AC_DEFUN([AC_ENABLE_SHARED], [dnl -define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl -AC_ARG_ENABLE(shared, -changequote(<<, >>)dnl -<< --enable-shared[=PKGS] build shared libraries [default=>>AC_ENABLE_SHARED_DEFAULT], -changequote([, ])dnl -[p=${PACKAGE-default} -case "$enableval" in -yes) enable_shared=yes ;; -no) enable_shared=no ;; -*) - enable_shared=no - # Look at the argument we got. We use all the common list separators. - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," - for pkg in $enableval; do - if test "X$pkg" = "X$p"; then - enable_shared=yes - fi - done - IFS="$ac_save_ifs" - ;; -esac], -enable_shared=AC_ENABLE_SHARED_DEFAULT)dnl -]) +need_locks="$enable_libtool_lock" -# AC_DISABLE_SHARED - set the default shared flag to --disable-shared -AC_DEFUN([AC_DISABLE_SHARED], [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl -AC_ENABLE_SHARED(no)]) - -# AC_ENABLE_STATIC - implement the --enable-static flag -# Usage: AC_ENABLE_STATIC[(DEFAULT)] -# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to -# `yes'. -AC_DEFUN([AC_ENABLE_STATIC], [dnl -define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl -AC_ARG_ENABLE(static, -changequote(<<, >>)dnl -<< --enable-static[=PKGS] build static libraries [default=>>AC_ENABLE_STATIC_DEFAULT], -changequote([, ])dnl -[p=${PACKAGE-default} -case "$enableval" in -yes) enable_static=yes ;; -no) enable_static=no ;; -*) - enable_static=no - # Look at the argument we got. We use all the common list separators. - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," - for pkg in $enableval; do - if test "X$pkg" = "X$p"; then - enable_static=yes - fi - done - IFS="$ac_save_ifs" - ;; -esac], -enable_static=AC_ENABLE_STATIC_DEFAULT)dnl +])# _LT_AC_LOCK + + +# AC_LIBTOOL_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) +# ---------------------------------------------------------------- +# Check whether the given compiler option works +AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], +[AC_REQUIRE([LT_AC_PROG_SED]) +AC_CACHE_CHECK([$1], [$2], + [$2=no + ifelse([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + lt_compiler_flag="$3" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + # The option is referenced via a variable to avoid confusing sed. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>conftest.err) + ac_status=$? + cat conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s "$ac_outfile"; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings other than the usual output. + $echo "X$_lt_compiler_boilerplate" | $Xsed >conftest.exp + $SED '/^$/d' conftest.err >conftest.er2 + if test ! -s conftest.err || diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + fi + $rm conftest* ]) -# AC_DISABLE_STATIC - set the default static flag to --disable-static -AC_DEFUN([AC_DISABLE_STATIC], [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl -AC_ENABLE_STATIC(no)]) - - -# AC_ENABLE_FAST_INSTALL - implement the --enable-fast-install flag -# Usage: AC_ENABLE_FAST_INSTALL[(DEFAULT)] -# Where DEFAULT is either `yes' or `no'. If omitted, it defaults to -# `yes'. -AC_DEFUN([AC_ENABLE_FAST_INSTALL], [dnl -define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl -AC_ARG_ENABLE(fast-install, -changequote(<<, >>)dnl -<< --enable-fast-install[=PKGS] optimize for fast installation [default=>>AC_ENABLE_FAST_INSTALL_DEFAULT], -changequote([, ])dnl -[p=${PACKAGE-default} -case "$enableval" in -yes) enable_fast_install=yes ;; -no) enable_fast_install=no ;; -*) - enable_fast_install=no - # Look at the argument we got. We use all the common list separators. - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," - for pkg in $enableval; do - if test "X$pkg" = "X$p"; then - enable_fast_install=yes - fi - done - IFS="$ac_save_ifs" - ;; -esac], -enable_fast_install=AC_ENABLE_FAST_INSTALL_DEFAULT)dnl +if test x"[$]$2" = xyes; then + ifelse([$5], , :, [$5]) +else + ifelse([$6], , :, [$6]) +fi +])# AC_LIBTOOL_COMPILER_OPTION + + +# AC_LIBTOOL_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, +# [ACTION-SUCCESS], [ACTION-FAILURE]) +# ------------------------------------------------------------ +# Check whether the given compiler option works +AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], +[AC_CACHE_CHECK([$1], [$2], + [$2=no + save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LDFLAGS $3" + printf "$lt_simple_link_test_code" > conftest.$ac_ext + if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + if test -s conftest.err; then + # Append any errors to the config.log. + cat conftest.err 1>&AS_MESSAGE_LOG_FD + $echo "X$_lt_linker_boilerplate" | $Xsed > conftest.exp + $SED '/^$/d' conftest.err >conftest.er2 + if diff conftest.exp conftest.er2 >/dev/null; then + $2=yes + fi + else + $2=yes + fi + fi + $rm conftest* + LDFLAGS="$save_LDFLAGS" ]) -# AC_ENABLE_FAST_INSTALL - set the default to --disable-fast-install -AC_DEFUN([AC_DISABLE_FAST_INSTALL], [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl -AC_ENABLE_FAST_INSTALL(no)]) +if test x"[$]$2" = xyes; then + ifelse([$4], , :, [$4]) +else + ifelse([$5], , :, [$5]) +fi +])# AC_LIBTOOL_LINKER_OPTION -# AC_PROG_LD - find the path to the GNU or non-GNU linker -AC_DEFUN([AC_PROG_LD], -[AC_ARG_WITH(gnu-ld, -[ --with-gnu-ld assume the C compiler uses GNU ld [default=no]], -test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no) -AC_REQUIRE([AC_PROG_CC])dnl -AC_REQUIRE([AC_CANONICAL_HOST])dnl -AC_REQUIRE([AC_CANONICAL_BUILD])dnl -ac_prog=ld -if test "$ac_cv_prog_gcc" = yes; then - # Check if gcc -print-prog-name=ld gives a path. - AC_MSG_CHECKING([for ld used by GCC]) - ac_prog=`($CC -print-prog-name=ld) 2>&5` - case "$ac_prog" in - # Accept absolute paths. -changequote(,)dnl - [\\/]* | [A-Za-z]:[\\/]*) - re_direlt='/[^/][^/]*/\.\./' -changequote([,])dnl - # Canonicalize the path of ld - ac_prog=`echo $ac_prog| sed 's%\\\\%/%g'` - while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do - ac_prog=`echo $ac_prog| sed "s%$re_direlt%/%"` - done - test -z "$LD" && LD="$ac_prog" - ;; - "") - # If it fails, then pretend we aren't using GCC. - ac_prog=ld + +# AC_LIBTOOL_SYS_MAX_CMD_LEN +# -------------------------- +AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], +[# find the maximum length of command line arguments +AC_MSG_CHECKING([the maximum length of command line arguments]) +AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl + i=0 + teststring="ABCD" + + case $build_os in + msdosdjgpp*) + # On DJGPP, this test can blow up pretty badly due to problems in libc + # (any single argument exceeding 2000 bytes causes a buffer overrun + # during glob expansion). Even if it were fixed, the result of this + # check would be larger than it should be. + lt_cv_sys_max_cmd_len=12288; # 12K is about right + ;; + + gnu*) + # Under GNU Hurd, this test is not required because there is + # no limit to the length of command line arguments. + # Libtool will interpret -1 as no limit whatsoever + lt_cv_sys_max_cmd_len=-1; + ;; + + cygwin* | mingw*) + # On Win9x/ME, this test blows up -- it succeeds, but takes + # about 5 minutes as the teststring grows exponentially. + # Worse, since 9x/ME are not pre-emptively multitasking, + # you end up with a "frozen" computer, even though with patience + # the test eventually succeeds (with a max line length of 256k). + # Instead, let's just punt: use the minimum linelength reported by + # all of the supported platforms: 8192 (on NT/2K/XP). + lt_cv_sys_max_cmd_len=8192; + ;; + + amigaos*) + # On AmigaOS with pdksh, this test takes hours, literally. + # So we just punt and use a minimum line length of 8192. + lt_cv_sys_max_cmd_len=8192; + ;; + + netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) + # This has been around since 386BSD, at least. Likely further. + if test -x /sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` + elif test -x /usr/sbin/sysctl; then + lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` + else + lt_cv_sys_max_cmd_len=65536 # usable default for *BSD + fi + # And add a safety zone + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` + ;; + osf*) + # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure + # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not + # nice to cause kernel panics so lets avoid the loop below. + # First set a reasonable default. + lt_cv_sys_max_cmd_len=16384 + # + if test -x /sbin/sysconfig; then + case `/sbin/sysconfig -q proc exec_disable_arg_limit` in + *1*) lt_cv_sys_max_cmd_len=-1 ;; + esac + fi ;; *) - # If it is relative, then search for the first ld in PATH. - with_gnu_ld=unknown + # If test is not a shell built-in, we'll probably end up computing a + # maximum length that is only half of the actual maximum length, but + # we can't tell. + SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} + while (test "X"`$SHELL [$]0 --fallback-echo "X$teststring" 2>/dev/null` \ + = "XX$teststring") >/dev/null 2>&1 && + new_result=`expr "X$teststring" : ".*" 2>&1` && + lt_cv_sys_max_cmd_len=$new_result && + test $i != 17 # 1/2 MB should be enough + do + i=`expr $i + 1` + teststring=$teststring$teststring + done + teststring= + # Add a significant safety factor because C++ compilers can tack on massive + # amounts of additional arguments before passing them to the linker. + # It appears as though 1/2 is a usable value. + lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` ;; esac -elif test "$with_gnu_ld" = yes; then - AC_MSG_CHECKING([for GNU ld]) +]) +if test -n $lt_cv_sys_max_cmd_len ; then + AC_MSG_RESULT($lt_cv_sys_max_cmd_len) else - AC_MSG_CHECKING([for non-GNU ld]) + AC_MSG_RESULT(none) fi -AC_CACHE_VAL(ac_cv_path_LD, -[if test -z "$LD"; then - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" - for ac_dir in $PATH; do - test -z "$ac_dir" && ac_dir=. - if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then - ac_cv_path_LD="$ac_dir/$ac_prog" - # Check to see if the program is GNU ld. I'd rather use --version, - # but apparently some GNU ld's only accept -v. - # Break only if it was the GNU/non-GNU ld that we prefer. - if "$ac_cv_path_LD" -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null; then - test "$with_gnu_ld" != no && break - else - test "$with_gnu_ld" != yes && break - fi - fi - done - IFS="$ac_save_ifs" -else - ac_cv_path_LD="$LD" # Let the user override the test with a path. -fi]) -LD="$ac_cv_path_LD" -if test -n "$LD"; then - AC_MSG_RESULT($LD) +])# AC_LIBTOOL_SYS_MAX_CMD_LEN + + +# _LT_AC_CHECK_DLFCN +# -------------------- +AC_DEFUN([_LT_AC_CHECK_DLFCN], +[AC_CHECK_HEADERS(dlfcn.h)dnl +])# _LT_AC_CHECK_DLFCN + + +# _LT_AC_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, +# ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) +# ------------------------------------------------------------------ +AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF], +[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl +if test "$cross_compiling" = yes; then : + [$4] else - AC_MSG_RESULT(no) + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext < +#endif + +#include + +#ifdef RTLD_GLOBAL +# define LT_DLGLOBAL RTLD_GLOBAL +#else +# ifdef DL_GLOBAL +# define LT_DLGLOBAL DL_GLOBAL +# else +# define LT_DLGLOBAL 0 +# endif +#endif + +/* We may have to define LT_DLLAZY_OR_NOW in the command line if we + find out it does not work in some platform. */ +#ifndef LT_DLLAZY_OR_NOW +# ifdef RTLD_LAZY +# define LT_DLLAZY_OR_NOW RTLD_LAZY +# else +# ifdef DL_LAZY +# define LT_DLLAZY_OR_NOW DL_LAZY +# else +# ifdef RTLD_NOW +# define LT_DLLAZY_OR_NOW RTLD_NOW +# else +# ifdef DL_NOW +# define LT_DLLAZY_OR_NOW DL_NOW +# else +# define LT_DLLAZY_OR_NOW 0 +# endif +# endif +# endif +# endif +#endif + +#ifdef __cplusplus +extern "C" void exit (int); +#endif + +void fnord() { int i=42;} +int main () +{ + void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); + int status = $lt_dlunknown; + + if (self) + { + if (dlsym (self,"fnord")) status = $lt_dlno_uscore; + else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; + /* dlclose (self); */ + } + + exit (status); +}] +EOF + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then + (./conftest; exit; ) 2>/dev/null + lt_status=$? + case x$lt_status in + x$lt_dlno_uscore) $1 ;; + x$lt_dlneed_uscore) $2 ;; + x$lt_unknown|x*) $3 ;; + esac + else : + # compilation failed + $3 + fi fi -test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH]) -AC_PROG_LD_GNU -]) +rm -fr conftest* +])# _LT_AC_TRY_DLOPEN_SELF -AC_DEFUN([AC_PROG_LD_GNU], -[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], ac_cv_prog_gnu_ld, -[# I'd rather use --version here, but apparently some GNU ld's only accept -v. -if $LD -v 2>&1 &5; then - ac_cv_prog_gnu_ld=yes -else - ac_cv_prog_gnu_ld=no -fi]) -]) -# AC_PROG_NM - find the path to a BSD-compatible name lister -AC_DEFUN([AC_PROG_NM], -[AC_MSG_CHECKING([for BSD-compatible nm]) -AC_CACHE_VAL(ac_cv_path_NM, -[if test -n "$NM"; then - # Let the user override the test. - ac_cv_path_NM="$NM" +# AC_LIBTOOL_DLOPEN_SELF +# ------------------- +AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], +[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl +if test "x$enable_dlopen" != xyes; then + enable_dlopen=unknown + enable_dlopen_self=unknown + enable_dlopen_self_static=unknown else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR-:}" - for ac_dir in $PATH /usr/ccs/bin /usr/ucb /bin; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/nm || test -f $ac_dir/nm$ac_exeext ; then - # Check to see if the nm accepts a BSD-compat flag. - # Adding the `sed 1q' prevents false positives on HP-UX, which says: - # nm: unknown option "B" ignored - if ($ac_dir/nm -B /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then - ac_cv_path_NM="$ac_dir/nm -B" - break - elif ($ac_dir/nm -p /dev/null 2>&1 | sed '1q'; exit 0) | egrep /dev/null >/dev/null; then - ac_cv_path_NM="$ac_dir/nm -p" - break - else - ac_cv_path_NM=${ac_cv_path_NM="$ac_dir/nm"} # keep the first match, but - continue # so that we can try to find one that supports BSD flags - fi - fi - done - IFS="$ac_save_ifs" - test -z "$ac_cv_path_NM" && ac_cv_path_NM=nm -fi]) -NM="$ac_cv_path_NM" -AC_MSG_RESULT([$NM]) -]) + lt_cv_dlopen=no + lt_cv_dlopen_libs= -# AC_CHECK_LIBM - check for math library -AC_DEFUN([AC_CHECK_LIBM], -[AC_REQUIRE([AC_CANONICAL_HOST])dnl -LIBM= -case "$lt_target" in -*-*-beos* | *-*-cygwin*) - # These system don't have libm - ;; -*-ncr-sysv4.3*) - AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") - AC_CHECK_LIB(m, main, LIBM="$LIBM -lm") - ;; -*) - AC_CHECK_LIB(m, main, LIBM="-lm") - ;; -esac -]) + case $host_os in + beos*) + lt_cv_dlopen="load_add_on" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ;; -# AC_LIBLTDL_CONVENIENCE[(dir)] - sets LIBLTDL to the link flags for -# the libltdl convenience library and INCLTDL to the include flags for -# the libltdl header and adds --enable-ltdl-convenience to the -# configure arguments. Note that LIBLTDL and INCLTDL are not -# AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If DIR is not -# provided, it is assumed to be `libltdl'. LIBLTDL will be prefixed -# with '${top_builddir}/' and INCLTDL will be prefixed with -# '${top_srcdir}/' (note the single quotes!). If your package is not -# flat and you're not using automake, define top_builddir and -# top_srcdir appropriately in the Makefiles. -AC_DEFUN([AC_LIBLTDL_CONVENIENCE], [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl - case "$enable_ltdl_convenience" in - no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;; + mingw* | pw32*) + lt_cv_dlopen="LoadLibrary" + lt_cv_dlopen_libs= + ;; + + cygwin*) + lt_cv_dlopen="dlopen" + lt_cv_dlopen_libs= + ;; + + darwin*) + # if libdl is installed we need to link against it + AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ + lt_cv_dlopen="dyld" + lt_cv_dlopen_libs= + lt_cv_dlopen_self=yes + ]) + ;; + + *) + AC_CHECK_FUNC([shl_load], + [lt_cv_dlopen="shl_load"], + [AC_CHECK_LIB([dld], [shl_load], + [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-dld"], + [AC_CHECK_FUNC([dlopen], + [lt_cv_dlopen="dlopen"], + [AC_CHECK_LIB([dl], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], + [AC_CHECK_LIB([svld], [dlopen], + [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], + [AC_CHECK_LIB([dld], [dld_link], + [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-dld"]) + ]) + ]) + ]) + ]) + ]) + ;; + esac + + if test "x$lt_cv_dlopen" != xno; then + enable_dlopen=yes + else + enable_dlopen=no + fi + + case $lt_cv_dlopen in + dlopen) + save_CPPFLAGS="$CPPFLAGS" + test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" + + save_LDFLAGS="$LDFLAGS" + eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" + + save_LIBS="$LIBS" + LIBS="$lt_cv_dlopen_libs $LIBS" + + AC_CACHE_CHECK([whether a program can dlopen itself], + lt_cv_dlopen_self, [dnl + _LT_AC_TRY_DLOPEN_SELF( + lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, + lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) + ]) + + if test "x$lt_cv_dlopen_self" = xyes; then + LDFLAGS="$LDFLAGS $link_static_flag" + AC_CACHE_CHECK([whether a statically linked program can dlopen itself], + lt_cv_dlopen_self_static, [dnl + _LT_AC_TRY_DLOPEN_SELF( + lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, + lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) + ]) + fi + + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + ;; + esac + + case $lt_cv_dlopen_self in + yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; + *) enable_dlopen_self=unknown ;; + esac + + case $lt_cv_dlopen_self_static in + yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; + *) enable_dlopen_self_static=unknown ;; + esac +fi +])# AC_LIBTOOL_DLOPEN_SELF + + +# AC_LIBTOOL_PROG_CC_C_O([TAGNAME]) +# --------------------------------- +# Check to see if options -c and -o are simultaneously supported by compiler +AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O], +[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl +AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], + [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)], + [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no + $rm -r conftest 2>/dev/null + mkdir conftest + cd conftest + mkdir out + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + lt_compiler_flag="-o out/conftest2.$ac_objext" + # Insert the option either (1) after the last *FLAGS variable, or + # (2) before a word containing "conftest.", or (3) at the end. + # Note that $ac_compile itself does not contain backslashes and begins + # with a dollar sign (not a hyphen), so the echo should work correctly. + lt_compile=`echo "$ac_compile" | $SED \ + -e 's:.*FLAGS}? :&$lt_compiler_flag :; t' \ + -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ + -e 's:$: $lt_compiler_flag:'` + (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD) + (eval "$lt_compile" 2>out/conftest.err) + ac_status=$? + cat out/conftest.err >&AS_MESSAGE_LOG_FD + echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + if (exit $ac_status) && test -s out/conftest2.$ac_objext + then + # The compiler can only warn and ignore the option if not recognized + # So say no if there are warnings + $echo "X$_lt_compiler_boilerplate" | $Xsed > out/conftest.exp + $SED '/^$/d' out/conftest.err >out/conftest.er2 + if test ! -s out/conftest.err || diff out/conftest.exp out/conftest.er2 >/dev/null; then + _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes + fi + fi + chmod u+w . + $rm conftest* + # SGI C++ compiler will create directory out/ii_files/ for + # template instantiation + test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files + $rm out/* && rmdir out + cd .. + rmdir conftest + $rm conftest* +]) +])# AC_LIBTOOL_PROG_CC_C_O + + +# AC_LIBTOOL_SYS_HARD_LINK_LOCKS([TAGNAME]) +# ----------------------------------------- +# Check to see if we can do hard links to lock some files if needed +AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], +[AC_REQUIRE([_LT_AC_LOCK])dnl + +hard_links="nottested" +if test "$_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then + # do not overwrite the value of need_locks provided by the user + AC_MSG_CHECKING([if we can lock with hard links]) + hard_links=yes + $rm conftest* + ln conftest.a conftest.b 2>/dev/null && hard_links=no + touch conftest.a + ln conftest.a conftest.b 2>&5 || hard_links=no + ln conftest.a conftest.b 2>/dev/null && hard_links=no + AC_MSG_RESULT([$hard_links]) + if test "$hard_links" = no; then + AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) + need_locks=warn + fi +else + need_locks=no +fi +])# AC_LIBTOOL_SYS_HARD_LINK_LOCKS + + +# AC_LIBTOOL_OBJDIR +# ----------------- +AC_DEFUN([AC_LIBTOOL_OBJDIR], +[AC_CACHE_CHECK([for objdir], [lt_cv_objdir], +[rm -f .libs 2>/dev/null +mkdir .libs 2>/dev/null +if test -d .libs; then + lt_cv_objdir=.libs +else + # MS-DOS does not allow filenames that begin with a dot. + lt_cv_objdir=_libs +fi +rmdir .libs 2>/dev/null]) +objdir=$lt_cv_objdir +])# AC_LIBTOOL_OBJDIR + + +# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH([TAGNAME]) +# ---------------------------------------------- +# Check hardcoding attributes. +AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], +[AC_MSG_CHECKING([how to hardcode library paths into programs]) +_LT_AC_TAGVAR(hardcode_action, $1)= +if test -n "$_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)" || \ + test -n "$_LT_AC_TAGVAR(runpath_var, $1)" || \ + test "X$_LT_AC_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then + + # We can hardcode non-existant directories. + if test "$_LT_AC_TAGVAR(hardcode_direct, $1)" != no && + # If the only mechanism to avoid hardcoding is shlibpath_var, we + # have to relink, otherwise we might link with an installed library + # when we should be linking with a yet-to-be-installed one + ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)" != no && + test "$_LT_AC_TAGVAR(hardcode_minus_L, $1)" != no; then + # Linking always hardcodes the temporary library directory. + _LT_AC_TAGVAR(hardcode_action, $1)=relink + else + # We can link without hardcoding, and we can hardcode nonexisting dirs. + _LT_AC_TAGVAR(hardcode_action, $1)=immediate + fi +else + # We cannot hardcode anything, or else we can only hardcode existing + # directories. + _LT_AC_TAGVAR(hardcode_action, $1)=unsupported +fi +AC_MSG_RESULT([$_LT_AC_TAGVAR(hardcode_action, $1)]) + +if test "$_LT_AC_TAGVAR(hardcode_action, $1)" = relink; then + # Fast installation is not supported + enable_fast_install=no +elif test "$shlibpath_overrides_runpath" = yes || + test "$enable_shared" = no; then + # Fast installation is not necessary + enable_fast_install=needless +fi +])# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH + + +# AC_LIBTOOL_SYS_LIB_STRIP +# ------------------------ +AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP], +[striplib= +old_striplib= +AC_MSG_CHECKING([whether stripping libraries is possible]) +if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then + test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" + test -z "$striplib" && striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) +else +# FIXME - insert some real tests, host_os isn't really good enough + case $host_os in + darwin*) + if test -n "$STRIP" ; then + striplib="$STRIP -x" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) +fi + ;; + *) + AC_MSG_RESULT([no]) + ;; + esac +fi +])# AC_LIBTOOL_SYS_LIB_STRIP + + +# AC_LIBTOOL_SYS_DYNAMIC_LINKER +# ----------------------------- +# PORTME Fill in your ld.so characteristics +AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER], +[AC_MSG_CHECKING([dynamic linker characteristics]) +library_names_spec= +libname_spec='lib$name' +soname_spec= +shrext_cmds=".so" +postinstall_cmds= +postuninstall_cmds= +finish_cmds= +finish_eval= +shlibpath_var= +shlibpath_overrides_runpath=unknown +version_type=none +dynamic_linker="$host_os ld.so" +sys_lib_dlsearch_path_spec="/lib /usr/lib" +if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | grep ';' >/dev/null ; then + # if the path contains ";" then we assume it to be the separator + # otherwise default to the standard path separator (i.e. ":") - it is + # assumed that no part of a normal pathname contains ";" but that should + # okay in the real world where ";" in dirpaths is itself problematic. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi +else + sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" +fi +need_lib_prefix=unknown +hardcode_into_libs=no + +# when you set need_version to no, make sure it does not cause -set_version +# flags to be left without arguments +need_version=unknown + +case $host_os in +aix3*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' + shlibpath_var=LIBPATH + + # AIX 3 has no versioning support, so we append a major version to the name. + soname_spec='${libname}${release}${shared_ext}$major' + ;; + +aix4* | aix5*) + version_type=linux + need_lib_prefix=no + need_version=no + hardcode_into_libs=yes + if test "$host_cpu" = ia64; then + # AIX 5 supports IA64 + library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + else + # With GCC up to 2.95.x, collect2 would create an import file + # for dependence libraries. The import file would start with + # the line `#! .'. This would cause the generated library to + # depend on `.', always an invalid library. This was fixed in + # development snapshots of GCC prior to 3.0. + case $host_os in + aix4 | aix4.[[01]] | aix4.[[01]].*) + if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' + echo ' yes ' + echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then + : + else + can_build_shared=no + fi + ;; + esac + # AIX (on Power*) has no versioning support, so currently we can not hardcode correct + # soname into executable. Probably we can add versioning support to + # collect2, so additional links can be useful in future. + if test "$aix_use_runtimelinking" = yes; then + # If using run time linking (on AIX 4.2 or later) use lib.so + # instead of lib.a to let people know that these are not + # typical AIX shared libraries. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + else + # We preserve .a as extension for shared libraries through AIX4.2 + # and later when we are not doing run time linking. + library_names_spec='${libname}${release}.a $libname.a' + soname_spec='${libname}${release}${shared_ext}$major' + fi + shlibpath_var=LIBPATH + fi + ;; + +amigaos*) + library_names_spec='$libname.ixlibrary $libname.a' + # Create ${libname}_ixlibrary.a entries in /sys/libs. + finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' + ;; + +beos*) + library_names_spec='${libname}${shared_ext}' + dynamic_linker="$host_os ld.so" + shlibpath_var=LIBRARY_PATH + ;; + +bsdi[[45]]*) + version_type=linux + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" + sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" + # the default ld.so.conf also contains /usr/contrib/lib and + # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow + # libtool to hard-code these into programs + ;; + +cygwin* | mingw* | pw32*) + version_type=windows + shrext_cmds=".dll" + need_version=no + need_lib_prefix=no + + case $GCC,$host_os in + yes,cygwin* | yes,mingw* | yes,pw32*) + library_names_spec='$libname.dll.a' + # DLL is installed to $(libdir)/../bin by postinstall_cmds + postinstall_cmds='base_file=`basename \${file}`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + test -d \$dldir || mkdir -p \$dldir~ + $install_prog $dir/$dlname \$dldir/$dlname' + postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ + dlpath=$dir/\$dldll~ + $rm \$dlpath' + shlibpath_overrides_runpath=yes + + case $host_os in + cygwin*) + # Cygwin DLLs use 'cyg' prefix rather than 'lib' + soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib" + ;; + mingw*) + # MinGW DLLs use traditional 'lib' prefix + soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"` + if echo "$sys_lib_search_path_spec" | [grep ';[c-zC-Z]:/' >/dev/null]; then + # It is most probably a Windows format PATH printed by + # mingw gcc, but we are running on Cygwin. Gcc prints its search + # path with ; separators, and with drive letters. We can handle the + # drive letters (cygwin fileutils understands them), so leave them, + # especially as we might pass files found there to a mingw objdump, + # which wouldn't understand a cygwinified path. Ahh. + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` + else + sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` + fi + ;; + pw32*) + # pw32 DLLs use 'pw' prefix rather than 'lib' + library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' + ;; + esac + ;; + + *) + library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' + ;; + esac + dynamic_linker='Win32 ld.exe' + # FIXME: first we should search . and the directory the executable is in + shlibpath_var=PATH + ;; + +darwin* | rhapsody*) + dynamic_linker="$host_os dyld" + version_type=darwin + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext' + soname_spec='${libname}${release}${major}$shared_ext' + shlibpath_overrides_runpath=yes + shlibpath_var=DYLD_LIBRARY_PATH + shrext_cmds='$(test .$module = .yes && echo .so || echo .dylib)' + # Apple's gcc prints 'gcc -print-search-dirs' doesn't operate the same. + if test "$GCC" = yes; then + sys_lib_search_path_spec=`$CC -print-search-dirs | tr "\n" "$PATH_SEPARATOR" | sed -e 's/libraries:/@libraries:/' | tr "@" "\n" | grep "^libraries:" | sed -e "s/^libraries://" -e "s,=/,/,g" -e "s,$PATH_SEPARATOR, ,g" -e "s,.*,& /lib /usr/lib /usr/local/lib,g"` + else + sys_lib_search_path_spec='/lib /usr/lib /usr/local/lib' + fi + sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' + ;; + +dgux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +freebsd1*) + dynamic_linker=no + ;; + +kfreebsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +freebsd* | dragonfly*) + # DragonFly does not have aout. When/if they implement a new + # versioning mechanism, adjust this. + objformat=`test -x /usr/bin/objformat && /usr/bin/objformat || echo aout` + version_type=freebsd-$objformat + case $version_type in + freebsd-elf*) + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' + need_version=no + need_lib_prefix=no + ;; + freebsd-*) + library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' + need_version=yes + ;; + esac + shlibpath_var=LD_LIBRARY_PATH + case $host_os in + freebsd2*) + shlibpath_overrides_runpath=yes + ;; + freebsd3.[[01]]* | freebsdelf3.[[01]]*) + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + *) # from 3.2 on + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + ;; + esac + ;; + +gnu*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + hardcode_into_libs=yes + ;; + +hpux9* | hpux10* | hpux11*) + # Give a soname corresponding to the major version so that dld.sl refuses to + # link against other versions. + version_type=sunos + need_lib_prefix=no + need_version=no + case "$host_cpu" in + ia64*) + shrext_cmds='.so' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.so" + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + if test "X$HPUX_IA64_MODE" = X32; then + sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" + else + sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" + fi + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + hppa*64*) + shrext_cmds='.sl' + hardcode_into_libs=yes + dynamic_linker="$host_os dld.sl" + shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH + shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" + sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec + ;; + *) + shrext_cmds='.sl' + dynamic_linker="$host_os dld.sl" + shlibpath_var=SHLIB_PATH + shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + ;; + esac + # HP-UX runs *really* slowly unless shared libraries are mode 555. + postinstall_cmds='chmod 555 $lib' + ;; + +irix5* | irix6* | nonstopux*) + case $host_os in + nonstopux*) version_type=nonstopux ;; + *) + if test "$lt_cv_prog_gnu_ld" = yes; then + version_type=linux + else + version_type=irix + fi ;; + esac + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' + case $host_os in + irix5* | nonstopux*) + libsuff= shlibsuff= + ;; + *) + case $LD in # libtool.m4 will add one of these switches to LD + *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") + libsuff= shlibsuff= libmagic=32-bit;; + *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") + libsuff=32 shlibsuff=N32 libmagic=N32;; + *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") + libsuff=64 shlibsuff=64 libmagic=64-bit;; + *) libsuff= shlibsuff= libmagic=never-match;; + esac + ;; + esac + shlibpath_var=LD_LIBRARY${shlibsuff}_PATH + shlibpath_overrides_runpath=no + sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" + sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" + hardcode_into_libs=yes + ;; + +# No shared lib support for Linux oldld, aout, or coff. +linux*oldld* | linux*aout* | linux*coff*) + dynamic_linker=no + ;; + +# This must be Linux ELF. +linux*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + # This implies no fast_install, which is unacceptable. + # Some rework will be needed to allow for fast_install + # before this can be enabled. + hardcode_into_libs=yes + + # find out which ABI we are using + libsuff= + case "$host_cpu" in + x86_64*|s390x*|powerpc64*) + echo '[#]line __oline__ "configure"' > conftest.$ac_ext + if AC_TRY_EVAL(ac_compile); then + case `/usr/bin/file conftest.$ac_objext` in + *64-bit*) + libsuff=64 + sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" + ;; + esac + fi + rm -rf conftest* + ;; + esac + + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '` + sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on + # powerpc, because MkLinux only supported shared libraries with the + # GNU dynamic linker. Since this was broken with cross compilers, + # most powerpc-linux boxes support dynamic linking these days and + # people can always --disable-shared, the test was removed, and we + # assume the GNU/Linux dynamic linker is in use. + dynamic_linker='GNU/Linux ld.so' + ;; + +knetbsd*-gnu) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=no + hardcode_into_libs=yes + dynamic_linker='GNU ld.so' + ;; + +netbsd*) + version_type=sunos + need_lib_prefix=no + need_version=no + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + dynamic_linker='NetBSD (a.out) ld.so' + else + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + dynamic_linker='NetBSD ld.elf_so' + fi + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + ;; + +newsos6) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +nto-qnx*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + ;; + +openbsd*) + version_type=sunos + need_lib_prefix=no + # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. + case $host_os in + openbsd3.3 | openbsd3.3.*) need_version=yes ;; + *) need_version=no ;; + esac + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' + shlibpath_var=LD_LIBRARY_PATH + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + case $host_os in + openbsd2.[[89]] | openbsd2.[[89]].*) + shlibpath_overrides_runpath=no + ;; + *) + shlibpath_overrides_runpath=yes + ;; + esac + else + shlibpath_overrides_runpath=yes + fi + ;; + +os2*) + libname_spec='$name' + shrext_cmds=".dll" + need_lib_prefix=no + library_names_spec='$libname${shared_ext} $libname.a' + dynamic_linker='OS/2 ld.exe' + shlibpath_var=LIBPATH + ;; + +osf3* | osf4* | osf5*) + version_type=osf + need_lib_prefix=no + need_version=no + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" + sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" + ;; + +sco3.2v5*) + version_type=osf + soname_spec='${libname}${release}${shared_ext}$major' + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + shlibpath_var=LD_LIBRARY_PATH + ;; + +solaris*) + version_type=linux + need_lib_prefix=no + need_version=no + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + hardcode_into_libs=yes + # ldd complains unless libraries are executable + postinstall_cmds='chmod +x $lib' + ;; + +sunos4*) + version_type=sunos + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' + finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' + shlibpath_var=LD_LIBRARY_PATH + shlibpath_overrides_runpath=yes + if test "$with_gnu_ld" = yes; then + need_lib_prefix=no + fi + need_version=yes + ;; + +sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + case $host_vendor in + sni) + shlibpath_overrides_runpath=no + need_lib_prefix=no + export_dynamic_flag_spec='${wl}-Blargedynsym' + runpath_var=LD_RUN_PATH + ;; + siemens) + need_lib_prefix=no + ;; + motorola) + need_lib_prefix=no + need_version=no + shlibpath_overrides_runpath=no + sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' + ;; + esac + ;; + +sysv4*MP*) + if test -d /usr/nec ;then + version_type=linux + library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' + soname_spec='$libname${shared_ext}.$major' + shlibpath_var=LD_LIBRARY_PATH + fi + ;; + +uts4*) + version_type=linux + library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' + soname_spec='${libname}${release}${shared_ext}$major' + shlibpath_var=LD_LIBRARY_PATH + ;; + +*) + dynamic_linker=no + ;; +esac +AC_MSG_RESULT([$dynamic_linker]) +test "$dynamic_linker" = no && can_build_shared=no +])# AC_LIBTOOL_SYS_DYNAMIC_LINKER + + +# _LT_AC_TAGCONFIG +# ---------------- +AC_DEFUN([_LT_AC_TAGCONFIG], +[AC_ARG_WITH([tags], + [AC_HELP_STRING([--with-tags@<:@=TAGS@:>@], + [include additional configurations @<:@automatic@:>@])], + [tagnames="$withval"]) + +if test -f "$ltmain" && test -n "$tagnames"; then + if test ! -f "${ofile}"; then + AC_MSG_WARN([output file `$ofile' does not exist]) + fi + + if test -z "$LTCC"; then + eval "`$SHELL ${ofile} --config | grep '^LTCC='`" + if test -z "$LTCC"; then + AC_MSG_WARN([output file `$ofile' does not look like a libtool script]) + else + AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile']) + fi + fi + + # Extract list of available tagged configurations in $ofile. + # Note that this assumes the entire list is on one line. + available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'` + + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for tagname in $tagnames; do + IFS="$lt_save_ifs" + # Check whether tagname contains only valid characters + case `$echo "X$tagname" | $Xsed -e 's:[[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]]::g'` in + "") ;; + *) AC_MSG_ERROR([invalid tag name: $tagname]) + ;; + esac + + if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null + then + AC_MSG_ERROR([tag name \"$tagname\" already exists]) + fi + + # Update the list of available tags. + if test -n "$tagname"; then + echo appending configuration tag \"$tagname\" to $ofile + + case $tagname in + CXX) + if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_LIBTOOL_LANG_CXX_CONFIG + else + tagname="" + fi + ;; + + F77) + if test -n "$F77" && test "X$F77" != "Xno"; then + AC_LIBTOOL_LANG_F77_CONFIG + else + tagname="" + fi + ;; + + GCJ) + if test -n "$GCJ" && test "X$GCJ" != "Xno"; then + AC_LIBTOOL_LANG_GCJ_CONFIG + else + tagname="" + fi + ;; + + RC) + AC_LIBTOOL_LANG_RC_CONFIG + ;; + + *) + AC_MSG_ERROR([Unsupported tag name: $tagname]) + ;; + esac + + # Append the new tag name to the list of available tags. + if test -n "$tagname" ; then + available_tags="$available_tags $tagname" + fi + fi + done + IFS="$lt_save_ifs" + + # Now substitute the updated list of available tags. + if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then + mv "${ofile}T" "$ofile" + chmod +x "$ofile" + else + rm -f "${ofile}T" + AC_MSG_ERROR([unable to update list of available tagged configurations.]) + fi +fi +])# _LT_AC_TAGCONFIG + + +# AC_LIBTOOL_DLOPEN +# ----------------- +# enable checks for dlopen support +AC_DEFUN([AC_LIBTOOL_DLOPEN], + [AC_BEFORE([$0],[AC_LIBTOOL_SETUP]) +])# AC_LIBTOOL_DLOPEN + + +# AC_LIBTOOL_WIN32_DLL +# -------------------- +# declare package support for building win32 dll's +AC_DEFUN([AC_LIBTOOL_WIN32_DLL], +[AC_BEFORE([$0], [AC_LIBTOOL_SETUP]) +])# AC_LIBTOOL_WIN32_DLL + + +# AC_ENABLE_SHARED([DEFAULT]) +# --------------------------- +# implement the --enable-shared flag +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +AC_DEFUN([AC_ENABLE_SHARED], +[define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([shared], + [AC_HELP_STRING([--enable-shared@<:@=PKGS@:>@], + [build shared libraries @<:@default=]AC_ENABLE_SHARED_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_shared=yes ;; + no) enable_shared=no ;; + *) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_shared=]AC_ENABLE_SHARED_DEFAULT) +])# AC_ENABLE_SHARED + + +# AC_DISABLE_SHARED +# ----------------- +#- set the default shared flag to --disable-shared +AC_DEFUN([AC_DISABLE_SHARED], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_SHARED(no) +])# AC_DISABLE_SHARED + + +# AC_ENABLE_STATIC([DEFAULT]) +# --------------------------- +# implement the --enable-static flag +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +AC_DEFUN([AC_ENABLE_STATIC], +[define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([static], + [AC_HELP_STRING([--enable-static@<:@=PKGS@:>@], + [build static libraries @<:@default=]AC_ENABLE_STATIC_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_static=yes ;; + no) enable_static=no ;; + *) + enable_static=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_static=]AC_ENABLE_STATIC_DEFAULT) +])# AC_ENABLE_STATIC + + +# AC_DISABLE_STATIC +# ----------------- +# set the default static flag to --disable-static +AC_DEFUN([AC_DISABLE_STATIC], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_STATIC(no) +])# AC_DISABLE_STATIC + + +# AC_ENABLE_FAST_INSTALL([DEFAULT]) +# --------------------------------- +# implement the --enable-fast-install flag +# DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. +AC_DEFUN([AC_ENABLE_FAST_INSTALL], +[define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE([fast-install], + [AC_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], + [optimize for fast installation @<:@default=]AC_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], + [p=${PACKAGE-default} + case $enableval in + yes) enable_fast_install=yes ;; + no) enable_fast_install=no ;; + *) + enable_fast_install=no + # Look at the argument we got. We use all the common list separators. + lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," + for pkg in $enableval; do + IFS="$lt_save_ifs" + if test "X$pkg" = "X$p"; then + enable_fast_install=yes + fi + done + IFS="$lt_save_ifs" + ;; + esac], + [enable_fast_install=]AC_ENABLE_FAST_INSTALL_DEFAULT) +])# AC_ENABLE_FAST_INSTALL + + +# AC_DISABLE_FAST_INSTALL +# ----------------------- +# set the default to --disable-fast-install +AC_DEFUN([AC_DISABLE_FAST_INSTALL], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_FAST_INSTALL(no) +])# AC_DISABLE_FAST_INSTALL + + +# AC_LIBTOOL_PICMODE([MODE]) +# -------------------------- +# implement the --with-pic flag +# MODE is either `yes' or `no'. If omitted, it defaults to `both'. +AC_DEFUN([AC_LIBTOOL_PICMODE], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +pic_mode=ifelse($#,1,$1,default) +])# AC_LIBTOOL_PICMODE + + +# AC_PROG_EGREP +# ------------- +# This is predefined starting with Autoconf 2.54, so this conditional +# definition can be removed once we require Autoconf 2.54 or later. +m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP], +[AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep], + [if echo a | (grep -E '(a|b)') >/dev/null 2>&1 + then ac_cv_prog_egrep='grep -E' + else ac_cv_prog_egrep='egrep' + fi]) + EGREP=$ac_cv_prog_egrep + AC_SUBST([EGREP]) +])]) + + +# AC_PATH_TOOL_PREFIX +# ------------------- +# find a file program which can recognise shared library +AC_DEFUN([AC_PATH_TOOL_PREFIX], +[AC_REQUIRE([AC_PROG_EGREP])dnl +AC_MSG_CHECKING([for $1]) +AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, +[case $MAGIC_CMD in +[[\\/*] | ?:[\\/]*]) + lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. + ;; +*) + lt_save_MAGIC_CMD="$MAGIC_CMD" + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR +dnl $ac_dummy forces splitting on constant user-supplied paths. +dnl POSIX.2 word splitting is done only on the output of word expansions, +dnl not every word. This closes a longstanding sh security hole. + ac_dummy="ifelse([$2], , $PATH, [$2])" + for ac_dir in $ac_dummy; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$1; then + lt_cv_path_MAGIC_CMD="$ac_dir/$1" + if test -n "$file_magic_test_file"; then + case $deplibs_check_method in + "file_magic "*) + file_magic_regex="`expr \"$deplibs_check_method\" : \"file_magic \(.*\)\"`" + MAGIC_CMD="$lt_cv_path_MAGIC_CMD" + if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | + $EGREP "$file_magic_regex" > /dev/null; then + : + else + cat <&2 + +*** Warning: the command libtool uses to detect shared libraries, +*** $file_magic_cmd, produces output that libtool cannot recognize. +*** The result is that libtool may fail to recognize shared libraries +*** as such. This will affect the creation of libtool libraries that +*** depend on shared libraries, but programs linked with such libtool +*** libraries will work regardless of this problem. Nevertheless, you +*** may want to report the problem to your system manager and/or to +*** bug-libtool@gnu.org + +EOF + fi ;; + esac + fi + break + fi + done + IFS="$lt_save_ifs" + MAGIC_CMD="$lt_save_MAGIC_CMD" + ;; +esac]) +MAGIC_CMD="$lt_cv_path_MAGIC_CMD" +if test -n "$MAGIC_CMD"; then + AC_MSG_RESULT($MAGIC_CMD) +else + AC_MSG_RESULT(no) +fi +])# AC_PATH_TOOL_PREFIX + + +# AC_PATH_MAGIC +# ------------- +# find a file program which can recognise a shared library +AC_DEFUN([AC_PATH_MAGIC], +[AC_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) +if test -z "$lt_cv_path_MAGIC_CMD"; then + if test -n "$ac_tool_prefix"; then + AC_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) + else + MAGIC_CMD=: + fi +fi +])# AC_PATH_MAGIC + + +# AC_PROG_LD +# ---------- +# find the pathname to the GNU or non-GNU linker +AC_DEFUN([AC_PROG_LD], +[AC_ARG_WITH([gnu-ld], + [AC_HELP_STRING([--with-gnu-ld], + [assume the C compiler uses GNU ld @<:@default=no@:>@])], + [test "$withval" = no || with_gnu_ld=yes], + [with_gnu_ld=no]) +AC_REQUIRE([LT_AC_PROG_SED])dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl +AC_REQUIRE([AC_CANONICAL_BUILD])dnl +ac_prog=ld +if test "$GCC" = yes; then + # Check if gcc -print-prog-name=ld gives a path. + AC_MSG_CHECKING([for ld used by $CC]) + case $host in + *-*-mingw*) + # gcc leaves a trailing carriage return which upsets mingw + ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; + *) + ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; + esac + case $ac_prog in + # Accept absolute paths. + [[\\/]]* | ?:[[\\/]]*) + re_direlt='/[[^/]][[^/]]*/\.\./' + # Canonicalize the pathname of ld + ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'` + while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do + ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"` + done + test -z "$LD" && LD="$ac_prog" + ;; + "") + # If it fails, then pretend we aren't using GCC. + ac_prog=ld + ;; + *) + # If it is relative, then search for the first ld in PATH. + with_gnu_ld=unknown + ;; + esac +elif test "$with_gnu_ld" = yes; then + AC_MSG_CHECKING([for GNU ld]) +else + AC_MSG_CHECKING([for non-GNU ld]) +fi +AC_CACHE_VAL(lt_cv_path_LD, +[if test -z "$LD"; then + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then + lt_cv_path_LD="$ac_dir/$ac_prog" + # Check to see if the program is GNU ld. I'd rather use --version, + # but apparently some GNU ld's only accept -v. + # Break only if it was the GNU/non-GNU ld that we prefer. + case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null; then + case $host_cpu in + i*86 ) + # Not sure whether the presence of OpenBSD here was a mistake. + # Let's accept both of them until this is cleared up. + lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` + ;; + esac + else + lt_cv_deplibs_check_method=pass_all + fi + ;; + +gnu*) + lt_cv_deplibs_check_method=pass_all + ;; + +hpux10.20* | hpux11*) + lt_cv_file_magic_cmd=/usr/bin/file + case "$host_cpu" in + ia64*) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' + lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so + ;; + hppa*64*) + [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]'] + lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl + ;; + *) + lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library' + lt_cv_file_magic_test_file=/usr/lib/libc.sl + ;; + esac + ;; + +irix5* | irix6* | nonstopux*) + case $LD in + *-32|*"-32 ") libmagic=32-bit;; + *-n32|*"-n32 ") libmagic=N32;; + *-64|*"-64 ") libmagic=64-bit;; + *) libmagic=never-match;; + esac + lt_cv_deplibs_check_method=pass_all + ;; + +# This must be Linux ELF. +linux*) + lt_cv_deplibs_check_method=pass_all + ;; + +netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' + fi + ;; + +newos6*) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' + lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_test_file=/usr/lib/libnls.so + ;; + +nto-qnx*) + lt_cv_deplibs_check_method=unknown + ;; + +openbsd*) + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' + else + lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' + fi + ;; + +osf3* | osf4* | osf5*) + lt_cv_deplibs_check_method=pass_all + ;; + +sco3.2v5*) + lt_cv_deplibs_check_method=pass_all + ;; + +solaris*) + lt_cv_deplibs_check_method=pass_all + ;; + +sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + case $host_vendor in + motorola) + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' + lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` + ;; + ncr) + lt_cv_deplibs_check_method=pass_all + ;; + sequent) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' + ;; + sni) + lt_cv_file_magic_cmd='/bin/file' + lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" + lt_cv_file_magic_test_file=/lib/libc.so + ;; + siemens) + lt_cv_deplibs_check_method=pass_all + ;; + esac + ;; + +sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[[78]]* | unixware7* | sysv4*uw2*) + lt_cv_deplibs_check_method=pass_all + ;; +esac +]) +file_magic_cmd=$lt_cv_file_magic_cmd +deplibs_check_method=$lt_cv_deplibs_check_method +test -z "$deplibs_check_method" && deplibs_check_method=unknown +])# AC_DEPLIBS_CHECK_METHOD + + +# AC_PROG_NM +# ---------- +# find the pathname to a BSD-compatible name lister +AC_DEFUN([AC_PROG_NM], +[AC_CACHE_CHECK([for BSD-compatible nm], lt_cv_path_NM, +[if test -n "$NM"; then + # Let the user override the test. + lt_cv_path_NM="$NM" +else + lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR + for ac_dir in $PATH /usr/ccs/bin /usr/ucb /bin; do + IFS="$lt_save_ifs" + test -z "$ac_dir" && ac_dir=. + tmp_nm="$ac_dir/${ac_tool_prefix}nm" + if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then + # Check to see if the nm accepts a BSD-compat flag. + # Adding the `sed 1q' prevents false positives on HP-UX, which says: + # nm: unknown option "B" ignored + # Tru64's nm complains that /dev/null is an invalid object file + case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in + */dev/null* | *'Invalid file or object type'*) + lt_cv_path_NM="$tmp_nm -B" + break + ;; + *) + case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + */dev/null*) + lt_cv_path_NM="$tmp_nm -p" + break + ;; + *) + lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but + continue # so that we can try to find one that supports BSD flags + ;; + esac + esac + fi + done + IFS="$lt_save_ifs" + test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm +fi]) +NM="$lt_cv_path_NM" +])# AC_PROG_NM + + +# AC_CHECK_LIBM +# ------------- +# check for math library +AC_DEFUN([AC_CHECK_LIBM], +[AC_REQUIRE([AC_CANONICAL_HOST])dnl +LIBM= +case $host in +*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") + AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") + ;; +*) + AC_CHECK_LIB(m, cos, LIBM="-lm") + ;; +esac +])# AC_CHECK_LIBM + + +# AC_LIBLTDL_CONVENIENCE([DIRECTORY]) +# ----------------------------------- +# sets LIBLTDL to the link flags for the libltdl convenience library and +# LTDLINCL to the include flags for the libltdl header and adds +# --enable-ltdl-convenience to the configure arguments. Note that LIBLTDL +# and LTDLINCL are not AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If +# DIRECTORY is not provided, it is assumed to be `libltdl'. LIBLTDL will +# be prefixed with '${top_builddir}/' and LTDLINCL will be prefixed with +# '${top_srcdir}/' (note the single quotes!). If your package is not +# flat and you're not using automake, define top_builddir and +# top_srcdir appropriately in the Makefiles. +AC_DEFUN([AC_LIBLTDL_CONVENIENCE], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl + case $enable_ltdl_convenience in + no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;; "") enable_ltdl_convenience=yes ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;; esac - LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la - INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl']) + LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la + LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl']) + # For backwards non-gettext consistent compatibility... + INCLTDL="$LTDLINCL" +])# AC_LIBLTDL_CONVENIENCE + + +# AC_LIBLTDL_INSTALLABLE([DIRECTORY]) +# ----------------------------------- +# sets LIBLTDL to the link flags for the libltdl installable library and +# LTDLINCL to the include flags for the libltdl header and adds +# --enable-ltdl-install to the configure arguments. Note that LIBLTDL +# and LTDLINCL are not AC_SUBSTed, nor is AC_CONFIG_SUBDIRS called. If +# DIRECTORY is not provided and an installed libltdl is not found, it is +# assumed to be `libltdl'. LIBLTDL will be prefixed with '${top_builddir}/' +# and LTDLINCL will be prefixed with '${top_srcdir}/' (note the single +# quotes!). If your package is not flat and you're not using automake, +# define top_builddir and top_srcdir appropriately in the Makefiles. +# In the future, this macro may have to be called after AC_PROG_LIBTOOL. +AC_DEFUN([AC_LIBLTDL_INSTALLABLE], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl + AC_CHECK_LIB(ltdl, lt_dlinit, + [test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no], + [if test x"$enable_ltdl_install" = xno; then + AC_MSG_WARN([libltdl not installed, but installation disabled]) + else + enable_ltdl_install=yes + fi + ]) + if test x"$enable_ltdl_install" = x"yes"; then + ac_configure_args="$ac_configure_args --enable-ltdl-install" + LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la + LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl']) + else + ac_configure_args="$ac_configure_args --enable-ltdl-install=no" + LIBLTDL="-lltdl" + LTDLINCL= + fi + # For backwards non-gettext consistent compatibility... + INCLTDL="$LTDLINCL" +])# AC_LIBLTDL_INSTALLABLE + + +# AC_LIBTOOL_CXX +# -------------- +# enable support for C++ libraries +AC_DEFUN([AC_LIBTOOL_CXX], +[AC_REQUIRE([_LT_AC_LANG_CXX]) +])# AC_LIBTOOL_CXX + + +# _LT_AC_LANG_CXX +# --------------- +AC_DEFUN([_LT_AC_LANG_CXX], +[AC_REQUIRE([AC_PROG_CXX]) +AC_REQUIRE([_LT_AC_PROG_CXXCPP]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}CXX]) +])# _LT_AC_LANG_CXX + +# _LT_AC_PROG_CXXCPP +# --------------- +AC_DEFUN([_LT_AC_PROG_CXXCPP], +[ +AC_REQUIRE([AC_PROG_CXX]) +if test -n "$CXX" && ( test "X$CXX" != "Xno" && + ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || + (test "X$CXX" != "Xg++"))) ; then + AC_PROG_CXXCPP +fi +])# _LT_AC_PROG_CXXCPP + +# AC_LIBTOOL_F77 +# -------------- +# enable support for Fortran 77 libraries +AC_DEFUN([AC_LIBTOOL_F77], +[AC_REQUIRE([_LT_AC_LANG_F77]) +])# AC_LIBTOOL_F77 + + +# _LT_AC_LANG_F77 +# --------------- +AC_DEFUN([_LT_AC_LANG_F77], +[AC_REQUIRE([AC_PROG_F77]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}F77]) +])# _LT_AC_LANG_F77 + + +# AC_LIBTOOL_GCJ +# -------------- +# enable support for GCJ libraries +AC_DEFUN([AC_LIBTOOL_GCJ], +[AC_REQUIRE([_LT_AC_LANG_GCJ]) +])# AC_LIBTOOL_GCJ + + +# _LT_AC_LANG_GCJ +# --------------- +AC_DEFUN([_LT_AC_LANG_GCJ], +[AC_PROVIDE_IFELSE([AC_PROG_GCJ],[], + [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],[], + [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],[], + [ifdef([AC_PROG_GCJ],[AC_REQUIRE([AC_PROG_GCJ])], + [ifdef([A][M_PROG_GCJ],[AC_REQUIRE([A][M_PROG_GCJ])], + [AC_REQUIRE([A][C_PROG_GCJ_OR_A][M_PROG_GCJ])])])])])]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}GCJ]) +])# _LT_AC_LANG_GCJ + + +# AC_LIBTOOL_RC +# -------------- +# enable support for Windows resource files +AC_DEFUN([AC_LIBTOOL_RC], +[AC_REQUIRE([LT_AC_PROG_RC]) +_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}RC]) +])# AC_LIBTOOL_RC + + +# AC_LIBTOOL_LANG_C_CONFIG +# ------------------------ +# Ensure that the configuration vars for the C compiler are +# suitably defined. Those variables are subsequently used by +# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'. +AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG], [_LT_AC_LANG_C_CONFIG]) +AC_DEFUN([_LT_AC_LANG_C_CONFIG], +[lt_save_CC="$CC" +AC_LANG_PUSH(C) + +# Source file extension for C test sources. +ac_ext=c + +# Object file extension for compiled C test sources. +objext=o +_LT_AC_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(){return(0);}\n' + +_LT_AC_SYS_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# +# Check for any special shared library compilation flags. +# +_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)= +if test "$GCC" = no; then + case $host_os in + sco3.2v5*) + _LT_AC_TAGVAR(lt_prog_cc_shlib, $1)='-belf' + ;; + esac +fi +if test -n "$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)"; then + AC_MSG_WARN([`$CC' requires `$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)' to build shared libraries]) + if echo "$old_CC $old_CFLAGS " | grep "[[ ]]$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)[[ ]]" >/dev/null; then : + else + AC_MSG_WARN([add `$_LT_AC_TAGVAR(lt_prog_cc_shlib, $1)' to the CC or CFLAGS env variable and reconfigure]) + _LT_AC_TAGVAR(lt_cv_prog_cc_can_build_shared, $1)=no + fi +fi + + +# +# Check to make sure the static flag actually works. +# +AC_LIBTOOL_LINKER_OPTION([if $compiler static flag $_LT_AC_TAGVAR(lt_prog_compiler_static, $1) works], + _LT_AC_TAGVAR(lt_prog_compiler_static_works, $1), + $_LT_AC_TAGVAR(lt_prog_compiler_static, $1), + [], + [_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=]) + + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1) +AC_LIBTOOL_PROG_COMPILER_PIC($1) +AC_LIBTOOL_PROG_CC_C_O($1) +AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1) +AC_LIBTOOL_PROG_LD_SHLIBS($1) +AC_LIBTOOL_SYS_DYNAMIC_LINKER($1) +AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1) +AC_LIBTOOL_SYS_LIB_STRIP +AC_LIBTOOL_DLOPEN_SELF($1) + +# Report which librarie types wil actually be built +AC_MSG_CHECKING([if libtool supports shared libraries]) +AC_MSG_RESULT([$can_build_shared]) + +AC_MSG_CHECKING([whether to build shared libraries]) +test "$can_build_shared" = "no" && enable_shared=no + +# On AIX, shared libraries and static libraries use the same namespace, and +# are all built from PIC. +case "$host_os" in +aix3*) + test "$enable_shared" = yes && enable_static=no + if test -n "$RANLIB"; then + archive_cmds="$archive_cmds~\$RANLIB \$lib" + postinstall_cmds='$RANLIB $lib' + fi + ;; + +aix4* | aix5*) + if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then + test "$enable_shared" = yes && enable_static=no + fi + ;; +esac +AC_MSG_RESULT([$enable_shared]) + +AC_MSG_CHECKING([whether to build static libraries]) +# Make sure either enable_shared or enable_static is yes. +test "$enable_shared" = yes || enable_static=yes +AC_MSG_RESULT([$enable_static]) + +AC_LIBTOOL_CONFIG($1) + +AC_LANG_POP +CC="$lt_save_CC" +])# AC_LIBTOOL_LANG_C_CONFIG + + +# AC_LIBTOOL_LANG_CXX_CONFIG +# -------------------------- +# Ensure that the configuration vars for the C compiler are +# suitably defined. Those variables are subsequently used by +# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'. +AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG], [_LT_AC_LANG_CXX_CONFIG(CXX)]) +AC_DEFUN([_LT_AC_LANG_CXX_CONFIG], +[AC_LANG_PUSH(C++) +AC_REQUIRE([AC_PROG_CXX]) +AC_REQUIRE([_LT_AC_PROG_CXXCPP]) + +_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no +_LT_AC_TAGVAR(allow_undefined_flag, $1)= +_LT_AC_TAGVAR(always_export_symbols, $1)=no +_LT_AC_TAGVAR(archive_expsym_cmds, $1)= +_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)= +_LT_AC_TAGVAR(hardcode_direct, $1)=no +_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= +_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= +_LT_AC_TAGVAR(hardcode_libdir_separator, $1)= +_LT_AC_TAGVAR(hardcode_minus_L, $1)=no +_LT_AC_TAGVAR(hardcode_automatic, $1)=no +_LT_AC_TAGVAR(module_cmds, $1)= +_LT_AC_TAGVAR(module_expsym_cmds, $1)= +_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown +_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds +_LT_AC_TAGVAR(no_undefined_flag, $1)= +_LT_AC_TAGVAR(whole_archive_flag_spec, $1)= +_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no + +# Dependencies to place before and after the object being linked: +_LT_AC_TAGVAR(predep_objects, $1)= +_LT_AC_TAGVAR(postdep_objects, $1)= +_LT_AC_TAGVAR(predeps, $1)= +_LT_AC_TAGVAR(postdeps, $1)= +_LT_AC_TAGVAR(compiler_lib_search_path, $1)= + +# Source file extension for C++ test sources. +ac_ext=cc + +# Object file extension for compiled C++ test sources. +objext=o +_LT_AC_TAGVAR(objext, $1)=$objext + +# Code to be used in simple compile tests +lt_simple_compile_test_code="int some_variable = 0;\n" + +# Code to be used in simple link tests +lt_simple_link_test_code='int main(int, char *[]) { return(0); }\n' + +# ltmain only uses $CC for tagged configurations so make sure $CC is set. +_LT_AC_SYS_COMPILER + +# save warnings/boilerplate of simple test code +_LT_COMPILER_BOILERPLATE +_LT_LINKER_BOILERPLATE + +# Allow CC to be a program name with arguments. +lt_save_CC=$CC +lt_save_LD=$LD +lt_save_GCC=$GCC +GCC=$GXX +lt_save_with_gnu_ld=$with_gnu_ld +lt_save_path_LD=$lt_cv_path_LD +if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then + lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx +else + unset lt_cv_prog_gnu_ld +fi +if test -n "${lt_cv_path_LDCXX+set}"; then + lt_cv_path_LD=$lt_cv_path_LDCXX +else + unset lt_cv_path_LD +fi +test -z "${LDCXX+set}" || LD=$LDCXX +CC=${CXX-"c++"} +compiler=$CC +_LT_AC_TAGVAR(compiler, $1)=$CC +_LT_CC_BASENAME([$compiler]) + +# We don't want -fno-exception wen compiling C++ code, so set the +# no_builtin_flag separately +if test "$GXX" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' +else + _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= +fi + +if test "$GXX" = yes; then + # Set up default GNU C++ configuration + + AC_PROG_LD + + # Check if GNU C++ uses GNU ld as the underlying linker, since the + # archiving commands below assume that GNU ld is being used. + if test "$with_gnu_ld" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # If archive_cmds runs LD, not CC, wlarc should be empty + # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to + # investigate it a little bit more. (MM) + wlarc='${wl}' + + # ancient GNU ld didn't support --whole-archive et. al. + if eval "`$CC -print-prog-name=ld` --help 2>&1" | \ + grep 'no-whole-archive' > /dev/null; then + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + fi + else + with_gnu_ld=no + wlarc= + + # A generic and very simple default shared library creation + # command for GNU C++ for the case where it uses the native + # linker, instead of GNU ld. If possible, this setting should + # overridden to take advantage of the native linker features on + # the platform it is being used on. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + fi + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + +else + GXX=no + with_gnu_ld=no + wlarc= +fi + +# PORTME: fill in a description of your system's C++ link characteristics +AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +_LT_AC_TAGVAR(ld_shlibs, $1)=yes +case $host_os in + aix3*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*) + for ld_flag in $LDFLAGS; do + case $ld_flag in + *-brtl*) + aix_use_runtimelinking=yes + break + ;; + esac + done + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_AC_TAGVAR(archive_cmds, $1)='' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + if test "$GXX" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + else + # We have old collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # -bexpall does not export symbols beginning with underscore (_) + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + # Exported symbols can be pulled into shared objects from archives + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=' ' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds it's shared libraries. + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + chorus*) + case $cc_basename in + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(always_export_symbols, $1)=no + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + darwin* | rhapsody*) + case "$host_os" in + rhapsody* | darwin1.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_automatic, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + if test "$GXX" = yes ; then + lt_int_apple_cc_single_mod=no + output_verbose_link_cmd='echo' + if $CC -dumpspecs 2>&1 | $EGREP 'single_module' >/dev/null ; then + lt_int_apple_cc_single_mod=yes + fi + if test "X$lt_int_apple_cc_single_mod" = Xyes ; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + fi + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's + if test "X$lt_int_apple_cc_single_mod" = Xyes ; then + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib -single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -r -keep_private_externs -nostdlib -o ${lib}-master.o $libobjs~$CC -dynamiclib $allow_undefined_flag -o $lib ${lib}-master.o $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + fi + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + fi + ;; + + dgux*) + case $cc_basename in + ec++*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + ghcx*) + # Green Hills C++ Compiler + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + freebsd[[12]]*) + # C++ shared libraries reported to be fairly broken before switch to ELF + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + freebsd-elf*) + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + freebsd* | kfreebsd*-gnu | dragonfly*) + # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF + # conventions + _LT_AC_TAGVAR(ld_shlibs, $1)=yes + ;; + gnu*) + ;; + hpux9*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[[-]]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + hpux10*|hpux11*) + if test $with_gnu_ld = no; then + case "$host_cpu" in + hppa*64*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + ia64*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + ;; + *) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + esac + fi + case "$host_cpu" in + hppa*64*) + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + ia64*) + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + *) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, + # but as the default + # location of the library. + ;; + esac + + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + aCC*) + case "$host_cpu" in + hppa*64*|ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $linker_flags $libobjs $deplibs' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes; then + if test $with_gnu_ld = no; then + case "$host_cpu" in + ia64*|hppa*64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $linker_flags $libobjs $deplibs' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + ;; + esac + fi + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + irix5* | irix6*) + case $cc_basename in + CC*) + # SGI C++ + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + + # Archives containing C++ object files must be created using + # "CC -ar", where "CC" is the IRIX C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' + ;; + *) + if test "$GXX" = yes; then + if test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib' + fi + fi + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + ;; + esac + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + linux*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + ;; + icpc*) + # Intel C++ + with_gnu_ld=yes + # version 8.0 and above of icpc choke on multiply defined symbols + # if we add $predep_objects and $postdep_objects, however 7.1 and + # earlier do not add the objects themselves. + case `$CC -V 2>&1` in + *"Version 7."*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + *) # Version 8.0 or newer + tmp_idyn= + case $host_cpu in + ia64*) tmp_idyn=' -i_dynamic';; + esac + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + ;; + esac + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' + ;; + pgCC*) + # Portland Group C++ compiler + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive,`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + ;; + cxx*) + # Compaq C++ + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' + + runpath_var=LD_RUN_PATH + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + esac + ;; + lynxos*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + m88k*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + mvs*) + case $cc_basename in + cxx*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' + wlarc= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + fi + # Workaround some broken pre-1.5 toolchains + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' + ;; + openbsd2*) + # C++ shared libraries are fairly broken + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + openbsd*) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + fi + output_verbose_link_cmd='echo' + ;; + osf3*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # "CC -Bstatic", where "CC" is the KAI C++ compiler. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' + + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + osf4* | osf5*) + case $cc_basename in + KCC*) + # Kuck and Associates, Inc. (KAI) C++ Compiler + + # KCC will only create a shared library if the output file + # ends with ".so" (or ".sl" for HP-UX), so rename the library + # to its proper name (with version) after linking. + _LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Archives containing C++ object files must be created using + # the KAI C++ compiler. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' + ;; + RCC*) + # Rational C++ 2.4.1 + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + cxx*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ + echo "-hidden">> $lib.exp~ + $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~ + $rm $lib.exp' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + ;; + *) + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"' + + else + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + ;; + psos*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + sco*) + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + case $cc_basename in + CC*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + lcc*) + # Lucid + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -nolib -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -G${allow_undefined_flag} -nolib ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The C++ compiler is used as linker so we must use $wl + # flag to pass the commands to the underlying system + # linker. We must also pass each convience library through + # to the system linker between allextract/defaultextract. + # The C++ compiler will combine linker options so we + # cannot just pass the convience library names through + # without $wl. + # Supported since Solaris 2.6 (maybe 2.5.1?) + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' + ;; + esac + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + # + # There doesn't appear to be a way to prevent this compiler from + # explicitly linking system object files so we need to strip them + # from the output so that they don't get included in the library + # dependencies. + output_verbose_link_cmd='templist=`$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep "\-[[LR]]"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list' + + # Archives containing C++ object files must be created using + # "CC -xar", where "CC" is the Sun C++ compiler. This is + # necessary to make sure instantiated templates are included + # in the archive. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + + # The C++ compiler must be used to create the archive. + _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' + ;; + *) + # GNU C++ compiler with Solaris linker + if test "$GXX" = yes && test "$with_gnu_ld" = no; then + _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' + if $CC --version | grep -v '^2\.7' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\"" + else + # g++ 2.7 appears to require `-G' NOT `-shared' on this + # platform. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp' + + # Commands to make compiler produce verbose output that lists + # what "hidden" libraries, object files and flags are used when + # linking a shared library. + output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\"" + fi + + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' + fi + ;; + esac + ;; + sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[[78]]* | unixware7*) + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + ;; + vxworks*) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + *) + # FIXME: insert proper C++ library support + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; +esac +AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)]) +test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +_LT_AC_TAGVAR(GCC, $1)="$GXX" +_LT_AC_TAGVAR(LD, $1)="$LD" + +## CAVEAT EMPTOR: +## There is no encapsulation within the following macros, do not change +## the running order or otherwise move them around unless you know exactly +## what you are doing... +AC_LIBTOOL_POSTDEP_PREDEP($1) +AC_LIBTOOL_PROG_COMPILER_PIC($1) +AC_LIBTOOL_PROG_CC_C_O($1) +AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1) +AC_LIBTOOL_PROG_LD_SHLIBS($1) +AC_LIBTOOL_SYS_DYNAMIC_LINKER($1) +AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1) +AC_LIBTOOL_SYS_LIB_STRIP +AC_LIBTOOL_DLOPEN_SELF($1) + +AC_LIBTOOL_CONFIG($1) + +AC_LANG_POP +CC=$lt_save_CC +LDCXX=$LD +LD=$lt_save_LD +GCC=$lt_save_GCC +with_gnu_ldcxx=$with_gnu_ld +with_gnu_ld=$lt_save_with_gnu_ld +lt_cv_path_LDCXX=$lt_cv_path_LD +lt_cv_path_LD=$lt_save_path_LD +lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld +lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld +])# AC_LIBTOOL_LANG_CXX_CONFIG + +# AC_LIBTOOL_POSTDEP_PREDEP([TAGNAME]) +# ------------------------ +# Figure out "hidden" library dependencies from verbose +# compiler output when linking a shared library. +# Parse the compiler output and extract the necessary +# objects, libraries and library flags. +AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP],[ +dnl we can't use the lt_simple_compile_test_code here, +dnl because it contains code intended for an executable, +dnl not a library. It's possible we should let each +dnl tag define a new lt_????_link_test_code variable, +dnl but it's only used here... +ifelse([$1],[],[cat > conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext < conftest.$ac_ext <> "$cfgfile" +ifelse([$1], [], +[#! $SHELL + +# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services. +# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP) +# NOTE: Changes made to this file will be lost: look at ltmain.sh. +# +# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. +# +# This file is part of GNU Libtool: +# Originally by Gordon Matzigkeit , 1996 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# A sed program that does not truncate output. +SED=$lt_SED + +# Sed that helps us avoid accidentally triggering echo(1) options like -n. +Xsed="$SED -e 1s/^X//" + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +# The names of the tagged configurations supported by this script. +available_tags= + +# ### BEGIN LIBTOOL CONFIG], +[# ### BEGIN LIBTOOL TAG CONFIG: $tagname]) + +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: + +# Shell to use when invoking shell scripts. +SHELL=$lt_SHELL + +# Whether or not to build shared libraries. +build_libtool_libs=$enable_shared + +# Whether or not to build static libraries. +build_old_libs=$enable_static + +# Whether or not to add -lc for building shared libraries. +build_libtool_need_lc=$_LT_AC_TAGVAR(archive_cmds_need_lc, $1) + +# Whether or not to disallow shared libs when runtime libs are static +allow_libtool_libs_with_static_runtimes=$_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1) + +# Whether or not to optimize for fast installation. +fast_install=$enable_fast_install + +# The host system. +host_alias=$host_alias +host=$host +host_os=$host_os + +# The build system. +build_alias=$build_alias +build=$build +build_os=$build_os + +# An echo program that does not interpret backslashes. +echo=$lt_echo + +# The archiver. +AR=$lt_AR +AR_FLAGS=$lt_AR_FLAGS + +# A C compiler. +LTCC=$lt_LTCC + +# A language-specific compiler. +CC=$lt_[]_LT_AC_TAGVAR(compiler, $1) + +# Is the compiler the GNU C compiler? +with_gcc=$_LT_AC_TAGVAR(GCC, $1) + +# An ERE matcher. +EGREP=$lt_EGREP + +# The linker used to build libraries. +LD=$lt_[]_LT_AC_TAGVAR(LD, $1) + +# Whether we need hard or soft links. +LN_S=$lt_LN_S + +# A BSD-compatible nm program. +NM=$lt_NM + +# A symbol stripping program +STRIP=$lt_STRIP + +# Used to examine libraries when file_magic_cmd begins "file" +MAGIC_CMD=$MAGIC_CMD + +# Used on cygwin: DLL creation program. +DLLTOOL="$DLLTOOL" + +# Used on cygwin: object dumper. +OBJDUMP="$OBJDUMP" + +# Used on cygwin: assembler. +AS="$AS" + +# The name of the directory that contains temporary libtool files. +objdir=$objdir + +# How to create reloadable object files. +reload_flag=$lt_reload_flag +reload_cmds=$lt_reload_cmds + +# How to pass a linker flag through the compiler. +wl=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) + +# Object file suffix (normally "o"). +objext="$ac_objext" + +# Old archive suffix (normally "a"). +libext="$libext" + +# Shared library suffix (normally ".so"). +shrext_cmds='$shrext_cmds' + +# Executable file suffix (normally ""). +exeext="$exeext" + +# Additional compiler flags for building library objects. +pic_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) +pic_mode=$pic_mode + +# What is the maximum length of a command? +max_cmd_len=$lt_cv_sys_max_cmd_len + +# Does compiler simultaneously support -c and -o options? +compiler_c_o=$lt_[]_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1) + +# Must we lock files when doing compilation? +need_locks=$lt_need_locks + +# Do we need the lib prefix for modules? +need_lib_prefix=$need_lib_prefix + +# Do we need a version for libraries? +need_version=$need_version + +# Whether dlopen is supported. +dlopen_support=$enable_dlopen + +# Whether dlopen of programs is supported. +dlopen_self=$enable_dlopen_self + +# Whether dlopen of statically linked programs is supported. +dlopen_self_static=$enable_dlopen_self_static + +# Compiler flag to prevent dynamic linking. +link_static_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_static, $1) + +# Compiler flag to turn off builtin functions. +no_builtin_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) + +# Compiler flag to allow reflexive dlopens. +export_dynamic_flag_spec=$lt_[]_LT_AC_TAGVAR(export_dynamic_flag_spec, $1) + +# Compiler flag to generate shared objects directly from archives. +whole_archive_flag_spec=$lt_[]_LT_AC_TAGVAR(whole_archive_flag_spec, $1) + +# Compiler flag to generate thread-safe objects. +thread_safe_flag_spec=$lt_[]_LT_AC_TAGVAR(thread_safe_flag_spec, $1) + +# Library versioning type. +version_type=$version_type + +# Format of library name prefix. +libname_spec=$lt_libname_spec + +# List of archive names. First name is the real one, the rest are links. +# The last name is the one that the linker finds with -lNAME. +library_names_spec=$lt_library_names_spec + +# The coded name of the library, if different from the real name. +soname_spec=$lt_soname_spec + +# Commands used to build and install an old-style archive. +RANLIB=$lt_RANLIB +old_archive_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_cmds, $1) +old_postinstall_cmds=$lt_old_postinstall_cmds +old_postuninstall_cmds=$lt_old_postuninstall_cmds + +# Create an old-style archive from a shared archive. +old_archive_from_new_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_new_cmds, $1) + +# Create a temporary old-style archive to link instead of a shared archive. +old_archive_from_expsyms_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) + +# Commands used to build and install a shared archive. +archive_cmds=$lt_[]_LT_AC_TAGVAR(archive_cmds, $1) +archive_expsym_cmds=$lt_[]_LT_AC_TAGVAR(archive_expsym_cmds, $1) +postinstall_cmds=$lt_postinstall_cmds +postuninstall_cmds=$lt_postuninstall_cmds + +# Commands used to build a loadable module (assumed same as above if empty) +module_cmds=$lt_[]_LT_AC_TAGVAR(module_cmds, $1) +module_expsym_cmds=$lt_[]_LT_AC_TAGVAR(module_expsym_cmds, $1) + +# Commands to strip libraries. +old_striplib=$lt_old_striplib +striplib=$lt_striplib + +# Dependencies to place before the objects being linked to create a +# shared library. +predep_objects=$lt_[]_LT_AC_TAGVAR(predep_objects, $1) + +# Dependencies to place after the objects being linked to create a +# shared library. +postdep_objects=$lt_[]_LT_AC_TAGVAR(postdep_objects, $1) + +# Dependencies to place before the objects being linked to create a +# shared library. +predeps=$lt_[]_LT_AC_TAGVAR(predeps, $1) + +# Dependencies to place after the objects being linked to create a +# shared library. +postdeps=$lt_[]_LT_AC_TAGVAR(postdeps, $1) + +# The library search path used internally by the compiler when linking +# a shared library. +compiler_lib_search_path=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1) + +# Method to check whether dependent libraries are shared objects. +deplibs_check_method=$lt_deplibs_check_method + +# Command to use when deplibs_check_method == file_magic. +file_magic_cmd=$lt_file_magic_cmd + +# Flag that allows shared libraries with undefined symbols to be built. +allow_undefined_flag=$lt_[]_LT_AC_TAGVAR(allow_undefined_flag, $1) + +# Flag that forces no undefined symbols. +no_undefined_flag=$lt_[]_LT_AC_TAGVAR(no_undefined_flag, $1) + +# Commands used to finish a libtool library installation in a directory. +finish_cmds=$lt_finish_cmds + +# Same as above, but a single script fragment to be evaled but not shown. +finish_eval=$lt_finish_eval + +# Take the output of nm and produce a listing of raw symbols and C names. +global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe + +# Transform the output of nm in a proper C declaration +global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl + +# Transform the output of nm in a C name address pair +global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address + +# This is the shared library runtime path variable. +runpath_var=$runpath_var + +# This is the shared library path variable. +shlibpath_var=$shlibpath_var + +# Is shlibpath searched before the hard-coded library search path? +shlibpath_overrides_runpath=$shlibpath_overrides_runpath + +# How to hardcode a shared library path into an executable. +hardcode_action=$_LT_AC_TAGVAR(hardcode_action, $1) + +# Whether we should hardcode library paths into libraries. +hardcode_into_libs=$hardcode_into_libs + +# Flag to hardcode \$libdir into a binary during linking. +# This must work even if \$libdir does not exist. +hardcode_libdir_flag_spec=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) + +# If ld is used when linking, flag to hardcode \$libdir into +# a binary during linking. This must work even if \$libdir does +# not exist. +hardcode_libdir_flag_spec_ld=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1) + +# Whether we need a single -rpath flag with a separated argument. +hardcode_libdir_separator=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_separator, $1) + +# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the +# resulting binary. +hardcode_direct=$_LT_AC_TAGVAR(hardcode_direct, $1) + +# Set to yes if using the -LDIR flag during linking hardcodes DIR into the +# resulting binary. +hardcode_minus_L=$_LT_AC_TAGVAR(hardcode_minus_L, $1) + +# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into +# the resulting binary. +hardcode_shlibpath_var=$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1) + +# Set to yes if building a shared library automatically hardcodes DIR into the library +# and all subsequent libraries and executables linked against it. +hardcode_automatic=$_LT_AC_TAGVAR(hardcode_automatic, $1) + +# Variables whose values should be saved in libtool wrapper scripts and +# restored at relink time. +variables_saved_for_relink="$variables_saved_for_relink" + +# Whether libtool must link a program against all its dependency libraries. +link_all_deplibs=$_LT_AC_TAGVAR(link_all_deplibs, $1) + +# Compile-time system search path for libraries +sys_lib_search_path_spec=$lt_sys_lib_search_path_spec + +# Run-time system search path for libraries +sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec + +# Fix the shell variable \$srcfile for the compiler. +fix_srcfile_path="$_LT_AC_TAGVAR(fix_srcfile_path, $1)" + +# Set to yes if exported symbols are required. +always_export_symbols=$_LT_AC_TAGVAR(always_export_symbols, $1) + +# The commands to list exported symbols. +export_symbols_cmds=$lt_[]_LT_AC_TAGVAR(export_symbols_cmds, $1) + +# The commands to extract the exported symbol list from a shared archive. +extract_expsyms_cmds=$lt_extract_expsyms_cmds + +# Symbols that should not be listed in the preloaded symbols. +exclude_expsyms=$lt_[]_LT_AC_TAGVAR(exclude_expsyms, $1) + +# Symbols that must always be exported. +include_expsyms=$lt_[]_LT_AC_TAGVAR(include_expsyms, $1) + +ifelse([$1],[], +[# ### END LIBTOOL CONFIG], +[# ### END LIBTOOL TAG CONFIG: $tagname]) + +__EOF__ + +ifelse([$1],[], [ + case $host_os in + aix3*) + cat <<\EOF >> "$cfgfile" + +# AIX sometimes has problems with the GCC collect2 program. For some +# reason, if we set the COLLECT_NAMES environment variable, the problems +# vanish in a puff of smoke. +if test "X${COLLECT_NAMES+set}" != Xset; then + COLLECT_NAMES= + export COLLECT_NAMES +fi +EOF + ;; + esac + + # We use sed instead of cat because bash on DJGPP gets confused if + # if finds mixed CR/LF and LF-only lines. Since sed operates in + # text mode, it properly converts lines to CR/LF. This bash problem + # is reportedly fixed, but why not run on old versions too? + sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1) + + mv -f "$cfgfile" "$ofile" || \ + (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") + chmod +x "$ofile" +]) +else + # If there is no Makefile yet, we rely on a make rule to execute + # `config.status --recheck' to rerun these tests and create the + # libtool script then. + ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'` + if test -f "$ltmain_in"; then + test -f Makefile && make "$ltmain" + fi +fi +])# AC_LIBTOOL_CONFIG + + +# AC_LIBTOOL_PROG_COMPILER_NO_RTTI([TAGNAME]) +# ------------------------------------------- +AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], +[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl + +_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= + +if test "$GCC" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' + + AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], + lt_cv_prog_compiler_rtti_exceptions, + [-fno-rtti -fno-exceptions], [], + [_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) +fi +])# AC_LIBTOOL_PROG_COMPILER_NO_RTTI + + +# AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE +# --------------------------------- +AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], +[AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_NM]) +AC_REQUIRE([AC_OBJEXT]) +# Check for command to grab the raw symbol name followed by C symbol from nm. +AC_MSG_CHECKING([command to parse $NM output from $compiler object]) +AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], +[ +# These are sane defaults that work on at least a few old systems. +# [They come from Ultrix. What could be older than Ultrix?!! ;)] + +# Character class describing NM global symbol codes. +symcode='[[BCDEGRST]]' + +# Regexp to match symbols that can be accessed directly from C. +sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' + +# Transform an extracted symbol line into a proper C declaration +lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'" + +# Transform an extracted symbol line into symbol name and symbol address +lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + +# Define system-specific variables. +case $host_os in +aix*) + symcode='[[BCDT]]' + ;; +cygwin* | mingw* | pw32*) + symcode='[[ABCDGISTW]]' + ;; +hpux*) # Its linker distinguishes data from code symbols + if test "$host_cpu" = ia64; then + symcode='[[ABCDEGRST]]' + fi + lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + ;; +linux*) + if test "$host_cpu" = ia64; then + symcode='[[ABCDGIRSTW]]' + lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" + lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/ {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (lt_ptr) \&\2},/p'" + fi + ;; +irix* | nonstopux*) + symcode='[[BCDEGRST]]' + ;; +osf*) + symcode='[[BCDEGQRST]]' + ;; +solaris* | sysv5*) + symcode='[[BDRT]]' + ;; +sysv4) + symcode='[[DFNSTU]]' + ;; +esac + +# Handle CRLF in mingw tool chain +opt_cr= +case $build_os in +mingw*) + opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp + ;; +esac + +# If we're using GNU nm, then use its standard symbol codes. +case `$NM -V 2>&1` in +*GNU* | *'with BFD'*) + symcode='[[ABCDGIRSTW]]' ;; +esac + +# Try without a prefix undercore, then with it. +for ac_symprfx in "" "_"; do + + # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. + symxfrm="\\1 $ac_symprfx\\2 \\2" + + # Write the raw and C identifiers. + lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + + # Check to see that the pipe works correctly. + pipe_works=no + + rm -f conftest* + cat > conftest.$ac_ext < $nlist) && test -s "$nlist"; then + # Try sorting and uniquifying the output. + if sort "$nlist" | uniq > "$nlist"T; then + mv -f "$nlist"T "$nlist" + else + rm -f "$nlist"T + fi + + # Make sure that we snagged all the symbols we need. + if grep ' nm_test_var$' "$nlist" >/dev/null; then + if grep ' nm_test_func$' "$nlist" >/dev/null; then + cat < conftest.$ac_ext +#ifdef __cplusplus +extern "C" { +#endif + +EOF + # Now generate the symbol file. + eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext' + + cat <> conftest.$ac_ext +#if defined (__STDC__) && __STDC__ +# define lt_ptr_t void * +#else +# define lt_ptr_t char * +# define const +#endif + +/* The mapping between symbol names and symbols. */ +const struct { + const char *name; + lt_ptr_t address; +} +lt_preloaded_symbols[[]] = +{ +EOF + $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext + cat <<\EOF >> conftest.$ac_ext + {0, (lt_ptr_t) 0} +}; + +#ifdef __cplusplus +} +#endif +EOF + # Now try linking the two files. + mv conftest.$ac_objext conftstm.$ac_objext + lt_save_LIBS="$LIBS" + lt_save_CFLAGS="$CFLAGS" + LIBS="conftstm.$ac_objext" + CFLAGS="$CFLAGS$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" + if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then + pipe_works=yes + fi + LIBS="$lt_save_LIBS" + CFLAGS="$lt_save_CFLAGS" + else + echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD + fi + else + echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD + fi + else + echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD + cat conftest.$ac_ext >&5 + fi + rm -f conftest* conftst* + + # Do not use the global_symbol_pipe unless it works. + if test "$pipe_works" = yes; then + break + else + lt_cv_sys_global_symbol_pipe= + fi +done +]) +if test -z "$lt_cv_sys_global_symbol_pipe"; then + lt_cv_sys_global_symbol_to_cdecl= +fi +if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then + AC_MSG_RESULT(failed) +else + AC_MSG_RESULT(ok) +fi +]) # AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE + + +# AC_LIBTOOL_PROG_COMPILER_PIC([TAGNAME]) +# --------------------------------------- +AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC], +[_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)= +_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= +_LT_AC_TAGVAR(lt_prog_compiler_static, $1)= + +AC_MSG_CHECKING([for $compiler option to produce PIC]) + ifelse([$1],[CXX],[ + # C++ specific cases for pic, static, wl, etc. + if test "$GXX" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + mingw* | os2* | pw32*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT' + ;; + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + *djgpp*) + # DJGPP does not support shared libraries at all + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + sysv4*MP*) + if test -d /usr/nec; then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case "$host_cpu" in + hppa*64*|ia64*) + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + case $host_os in + aix4* | aix5*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + chorus*) + case $cc_basename in + cxch68*) + # Green Hills C++ Compiler + # _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" + ;; + esac + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon' + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + esac + ;; + dgux*) + case $cc_basename in + ec++*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + ghcx*) + # Green Hills C++ Compiler + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + freebsd* | kfreebsd*-gnu | dragonfly*) + # FreeBSD uses GNU C++ + ;; + hpux9* | hpux10* | hpux11*) + case $cc_basename in + CC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="${ac_cv_prog_cc_wl}-a ${ac_cv_prog_cc_wl}archive" + if test "$host_cpu" != ia64; then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + fi + ;; + aCC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="${ac_cv_prog_cc_wl}-a ${ac_cv_prog_cc_wl}archive" + case "$host_cpu" in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + ;; + *) + ;; + esac + ;; + irix5* | irix6* | nonstopux*) + case $cc_basename in + CC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + # CC pic flag -KPIC is the default. + ;; + *) + ;; + esac + ;; + linux*) + case $cc_basename in + KCC*) + # KAI C++ Compiler + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + icpc* | ecpc*) + # Intel C++ + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgCC*) + # Portland Group C++ compiler. + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + cxx*) + # Compaq C++ + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + lynxos*) + ;; + m88k*) + ;; + mvs*) + case $cc_basename in + cxx*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' + ;; + *) + ;; + esac + ;; + netbsd*) + ;; + osf3* | osf4* | osf5*) + case $cc_basename in + KCC*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' + ;; + RCC*) + # Rational C++ 2.4.1 + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + cxx*) + # Digital/Compaq C++ + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # Make sure the PIC flag is empty. It appears that all Alpha + # Linux and Compaq Tru64 Unix objects are PIC. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + *) + ;; + esac + ;; + psos*) + ;; + sco*) + case $cc_basename in + CC*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + *) + ;; + esac + ;; + solaris*) + case $cc_basename in + CC*) + # Sun C++ 4.2, 5.x and Centerline C++ + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + ;; + gcx*) + # Green Hills C++ Compiler + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + ;; + *) + ;; + esac + ;; + sunos4*) + case $cc_basename in + CC*) + # Sun C++ 4.x + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + lcc*) + # Lucid + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + ;; + *) + ;; + esac + ;; + tandem*) + case $cc_basename in + NCC*) + # NonStop-UX NCC 3.20 + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + ;; + *) + ;; + esac + ;; + unixware*) + ;; + vxworks*) + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi +], +[ + if test "$GCC" = yes; then + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + + case $host_os in + aix*) + # All AIX code is PIC. + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + amigaos*) + # FIXME: we need at least 68020 code to build shared libraries, but + # adding the `-m68020' flag to GCC prevents building anything better, + # like `-m68040'. + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' + ;; + + beos* | cygwin* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) + # PIC is the default for these OSes. + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT' + ;; + + darwin* | rhapsody*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' + ;; + + msdosdjgpp*) + # Just because we use GCC doesn't mean we suddenly get shared libraries + # on systems that don't support them. + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + enable_shared=no + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic + fi + ;; + + hpux*) + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case "$host_cpu" in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + ;; + + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + ;; + esac + else + # PORTME Check for flag to pass linker flags through the system compiler. + case $host_os in + aix*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + if test "$host_cpu" = ia64; then + # AIX 5 now supports IA64 processor + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + else + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' + fi + ;; + darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + case $cc_basename in + xlc*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon' + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + ;; + esac + ;; + + mingw* | pw32* | os2*) + # This hack is so that the source file can tell whether it is being + # built for inclusion in a dll (and should export symbols for example). + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT' + ;; + + hpux9* | hpux10* | hpux11*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but + # not for PA HP-UX. + case "$host_cpu" in + hppa*64*|ia64*) + # +Z the default + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z' + ;; + esac + # Is there a better lt_prog_compiler_static that works with the bundled CC? + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' + ;; + + irix5* | irix6* | nonstopux*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # PIC (with -KPIC) is the default. + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + newsos6) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + linux*) + case $cc_basename in + icc* | ecc*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + pgcc* | pgf77* | pgf90*) + # Portland Group compilers (*not* the Pentium gcc compiler, + # which looks to be a dead project) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; + ccc*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All Alpha code is PIC. + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + esac + ;; + + osf3* | osf4* | osf5*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + # All OSF/1 code is PIC. + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' + ;; + + sco3.2v5*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kpic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-dn' + ;; + + solaris*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + case $cc_basename in + f77* | f90* | f95*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; + *) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; + esac + ;; + + sunos4*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + sysv4*MP*) + if test -d /usr/nec ;then + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + fi + ;; + + unicos*) + _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + + uts4*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic' + _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' + ;; + + *) + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no + ;; + esac + fi ]) +AC_MSG_RESULT([$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)]) -# AC_LIBLTDL_INSTALLABLE[(dir)] - sets LIBLTDL to the link flags for -# the libltdl installable library and INCLTDL to the include flags for -# the libltdl header and adds --enable-ltdl-install to the configure -# arguments. Note that LIBLTDL and INCLTDL are not AC_SUBSTed, nor is -# AC_CONFIG_SUBDIRS called. If DIR is not provided and an installed -# libltdl is not found, it is assumed to be `libltdl'. LIBLTDL will -# be prefixed with '${top_builddir}/' and INCLTDL will be prefixed -# with '${top_srcdir}/' (note the single quotes!). If your package is -# not flat and you're not using automake, define top_builddir and -# top_srcdir appropriately in the Makefiles. -# In the future, this macro may have to be called after AC_PROG_LIBTOOL. -AC_DEFUN([AC_LIBLTDL_INSTALLABLE], [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl - AC_CHECK_LIB(ltdl, main, - [test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no], - [if test x"$enable_ltdl_install" = xno; then - AC_MSG_WARN([libltdl not installed, but installation disabled]) - else - enable_ltdl_install=yes - fi - ]) - if test x"$enable_ltdl_install" = x"yes"; then - ac_configure_args="$ac_configure_args --enable-ltdl-install" - LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la - INCLTDL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl']) +# +# Check to make sure the PIC flag actually works. +# +if test -n "$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)"; then + AC_LIBTOOL_COMPILER_OPTION([if $compiler PIC flag $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) works], + _LT_AC_TAGVAR(lt_prog_compiler_pic_works, $1), + [$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])], [], + [case $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) in + "" | " "*) ;; + *) _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)" ;; + esac], + [_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) +fi +case "$host_os" in + # For platforms which do not support PIC, -DPIC is meaningless: + *djgpp*) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)= + ;; + *) + _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])" + ;; +esac +]) + + +# AC_LIBTOOL_PROG_LD_SHLIBS([TAGNAME]) +# ------------------------------------ +# See if the linker supports building shared libraries. +AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS], +[AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) +ifelse([$1],[CXX],[ + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + case $host_os in + aix4* | aix5*) + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + else + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + fi + ;; + pw32*) + _LT_AC_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" + ;; + cygwin* | mingw*) + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]] /s/.* \([[^ ]]*\)/\1 DATA/;/^.* __nm__/s/^.* __nm__\([[^ ]]*\) [[^ ]]*/\1 DATA/;/^I /d;/^[[AITW]] /s/.* //'\'' | sort | uniq > $export_symbols' + ;; + *) + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + ;; + esac +],[ + runpath_var= + _LT_AC_TAGVAR(allow_undefined_flag, $1)= + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no + _LT_AC_TAGVAR(archive_cmds, $1)= + _LT_AC_TAGVAR(archive_expsym_cmds, $1)= + _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)= + _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)= + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + _LT_AC_TAGVAR(thread_safe_flag_spec, $1)= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)= + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)= + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_minus_L, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_AC_TAGVAR(link_all_deplibs, $1)=unknown + _LT_AC_TAGVAR(hardcode_automatic, $1)=no + _LT_AC_TAGVAR(module_cmds, $1)= + _LT_AC_TAGVAR(module_expsym_cmds, $1)= + _LT_AC_TAGVAR(always_export_symbols, $1)=no + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' + # include_expsyms should be a list of space-separated symbols to be *always* + # included in the symbol list + _LT_AC_TAGVAR(include_expsyms, $1)= + # exclude_expsyms can be an extended regexp of symbols to exclude + # it will be wrapped by ` (' and `)$', so one must not match beginning or + # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', + # as well as any symbol that contains `d'. + _LT_AC_TAGVAR(exclude_expsyms, $1)="_GLOBAL_OFFSET_TABLE_" + # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out + # platforms (ab)use it in PIC code, but their linkers get confused if + # the symbol is explicitly referenced. Since portable code cannot + # rely on this symbol name, it's probably fine to never include it in + # preloaded symbol tables. + extract_expsyms_cmds= + # Just being paranoid about ensuring that cc_basename is set. + _LT_CC_BASENAME([$compiler]) + case $host_os in + cygwin* | mingw* | pw32*) + # FIXME: the MSVC++ port hasn't been tested in a loooong time + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + if test "$GCC" != yes; then + with_gnu_ld=no + fi + ;; + openbsd*) + with_gnu_ld=no + ;; + esac + + _LT_AC_TAGVAR(ld_shlibs, $1)=yes + if test "$with_gnu_ld" = yes; then + # If archive_cmds runs LD, not CC, wlarc should be empty + wlarc='${wl}' + + # Set some defaults for GNU ld with shared library support. These + # are reset later if shared libraries are not supported. Putting them + # here allows them to be overridden if necessary. + runpath_var=LD_RUN_PATH + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' + # ancient GNU ld didn't support --whole-archive et. al. + if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' + else + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + fi + supports_anon_versioning=no + case `$LD -v 2>/dev/null` in + *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 + *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... + *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... + *\ 2.11.*) ;; # other 2.11 versions + *) supports_anon_versioning=yes ;; + esac + + # See if GNU ld supports shared libraries. + case $host_os in + aix3* | aix4* | aix5*) + # On AIX/PPC, the GNU linker is very broken + if test "$host_cpu" != ia64; then + _LT_AC_TAGVAR(ld_shlibs, $1)=no + cat <&2 + +*** Warning: the GNU linker, at least up to release 2.9.1, is reported +*** to be unable to reliably create shared libraries on AIX. +*** Therefore, libtool is disabling shared libraries support. If you +*** really care for shared libraries, you may want to modify your PATH +*** so that a non-GNU linker is found, and then restart. + +EOF + fi + ;; + + amigaos*) + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + + # Samuel A. Falvo II reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we can't use + # them. + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + + beos*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + # Joseph Beckenbach says some releases of gcc + # support --undefined. This deserves some investigation. FIXME + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + cygwin* | mingw* | pw32*) + # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, + # as there is no search path for DLLs. + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(always_export_symbols, $1)=no + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]] /s/.* \([[^ ]]*\)/\1 DATA/'\'' | $SED -e '\''/^[[AITW]] /s/.* //'\'' | sort | uniq > $export_symbols' + + if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib' + # If the export-symbols file already is a .def file (1st line + # is EXPORTS), use it as is; otherwise, prepend... + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then + cp $export_symbols $output_objdir/$soname.def; + else + echo EXPORTS > $output_objdir/$soname.def; + cat $export_symbols >> $output_objdir/$soname.def; + fi~ + $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--image-base=0x10000000 ${wl}--out-implib,$lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + linux*) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + tmp_addflag= + case $cc_basename,$host_cpu in + pgcc*) # Portland Group C compiler + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive,`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag' + ;; + pgf77* | pgf90* ) # Portland Group f77 and f90 compilers + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive,`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive' + tmp_addflag=' $pic_flag -Mnomain' ;; + ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 + tmp_addflag=' -i_dynamic' ;; + efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 + tmp_addflag=' -i_dynamic -nofor_main' ;; + ifc* | ifort*) # Intel Fortran compiler + tmp_addflag=' -nofor_main' ;; + esac + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + + if test $supports_anon_versioning = yes; then + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $output_objdir/$libname.ver~ + cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + $echo "local: *; };" >> $output_objdir/$libname.ver~ + $CC -shared'"$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' + fi + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' + wlarc= + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + fi + ;; + + solaris* | sysv5*) + if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then + _LT_AC_TAGVAR(ld_shlibs, $1)=no + cat <&2 + +*** Warning: The releases 2.8.* of the GNU linker cannot reliably +*** create shared libraries on Solaris systems. Therefore, libtool +*** is disabling shared libraries support. We urge you to upgrade GNU +*** binutils to release 2.9.1 or newer. Another option is to modify +*** your PATH or compiler configuration so that the native linker is +*** used, and then restart. + +EOF + elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + + sunos4*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' + wlarc= + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' + else + _LT_AC_TAGVAR(ld_shlibs, $1)=no + fi + ;; + esac + + if test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no; then + runpath_var= + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)= + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)= + fi else - ac_configure_args="$ac_configure_args --enable-ltdl-install=no" - LIBLTDL="-lltdl" - INCLTDL= + # PORTME fill in a description of your system's linker (not GNU ld) + case $host_os in + aix3*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' + # Note: this linker hardcodes the directories in LIBPATH if there + # are no directories specified by -L. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + if test "$GCC" = yes && test -z "$link_static_flag"; then + # Neither direct hardcoding nor static linking is supported with a + # broken collect2. + _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported + fi + ;; + + aix4* | aix5*) + if test "$host_cpu" = ia64; then + # On IA64, the linker does run time linking by default, so we don't + # have to do anything special. + aix_use_runtimelinking=no + exp_sym_flag='-Bexport' + no_entry_flag="" + else + # If we're using GNU nm, then we don't want the "-C" option. + # -C means demangle to AIX nm, but means don't demangle with GNU nm + if $NM -V 2>&1 | grep 'GNU' > /dev/null; then + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + else + _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols' + fi + aix_use_runtimelinking=no + + # Test if we are trying to use run time linking or normal + # AIX style linking. If -brtl is somewhere in LDFLAGS, we + # need to do runtime linking. + case $host_os in aix4.[[23]]|aix4.[[23]].*|aix5*) + for ld_flag in $LDFLAGS; do + if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then + aix_use_runtimelinking=yes + break + fi + done + esac + + exp_sym_flag='-bexport' + no_entry_flag='-bnoentry' + fi + + # When large executables or shared objects are built, AIX ld can + # have problems creating the table of contents. If linking a library + # or program results in "error TOC overflow" add -mminimal-toc to + # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not + # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. + + _LT_AC_TAGVAR(archive_cmds, $1)='' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + + if test "$GCC" = yes; then + case $host_os in aix4.[[012]]|aix4.[[012]].*) + # We only want to do this on AIX 4.2 and lower, the check + # below for broken collect2 doesn't work under 4.3+ + collect2name=`${CC} -print-prog-name=collect2` + if test -f "$collect2name" && \ + strings "$collect2name" | grep resolve_lib_name >/dev/null + then + # We have reworked collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + else + # We have old collect2 + _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported + # It fails to find uninstalled libraries when the uninstalled + # path is not listed in the libpath. Setting hardcode_minus_L + # to unsupported forces relinking + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)= + fi + esac + shared_flag='-shared' + if test "$aix_use_runtimelinking" = yes; then + shared_flag="$shared_flag "'${wl}-G' + fi + else + # not using gcc + if test "$host_cpu" = ia64; then + # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release + # chokes on -Wl,-G. The following line is correct: + shared_flag='-G' + else + if test "$aix_use_runtimelinking" = yes; then + shared_flag='${wl}-G' + else + shared_flag='${wl}-bM:SRE' + fi + fi + fi + + # It seems that -bexpall does not export symbols beginning with + # underscore (_), so it is better to generate a list of symbols to export. + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + if test "$aix_use_runtimelinking" = yes; then + # Warning - without using the other runtime loading flags (-brtl), + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok' + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols $shared_flag" + else + if test "$host_cpu" = ia64; then + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' + _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs" + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols" + else + # Determine the default libpath from the value encoded in an empty executable. + _LT_AC_SYS_LIBPATH_AIX + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" + # Warning - without using the other run time loading flags, + # -berok will link without error, but may produce a broken library. + _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' + # -bexpall does not export symbols beginning with underscore (_) + _LT_AC_TAGVAR(always_export_symbols, $1)=yes + # Exported symbols can be pulled into shared objects from archives + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=' ' + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + # This is similar to how AIX traditionally builds it's shared libraries. + _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' + fi + fi + ;; + + amigaos*) + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + # see comment about different semantics on the GNU ld section + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + + bsdi[[45]]*) + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic + ;; + + cygwin* | mingw* | pw32*) + # When not using gcc, we currently assume that we are using + # Microsoft Visual C++. + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + # Tell ltmain to make .lib files, not .a files. + libext=lib + # Tell ltmain to make .dll files, not .so files. + shrext_cmds=".dll" + # FIXME: Setting linknames here is a bad hack. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames=' + # The linker will automatically build a .lib file if we build a DLL. + _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='true' + # FIXME: Should let the user specify the lib program. + _LT_AC_TAGVAR(old_archive_cmds, $1)='lib /OUT:$oldlib$oldobjs$old_deplibs' + _LT_AC_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`' + _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + ;; + + darwin* | rhapsody*) + case "$host_os" in + rhapsody* | darwin1.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress' + ;; + *) # Darwin 1.3 on + if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + else + case ${MACOSX_DEPLOYMENT_TARGET} in + 10.[[012]]) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' + ;; + 10.*) + _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup' + ;; + esac + fi + ;; + esac + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_automatic, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='' + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + if test "$GCC" = yes ; then + output_verbose_link_cmd='echo' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring' + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags -install_name $rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + else + case $cc_basename in + xlc*) + output_verbose_link_cmd='echo' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $verstring' + _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags' + # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin ld's + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $verstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[ ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}' + ;; + *) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + fi + ;; + + dgux*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + freebsd1*) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + + # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor + # support. Future versions do this automatically, but an explicit c++rt0.o + # does not break anything, and helps significantly (at the cost of a little + # extra space). + freebsd2.2*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # Unfortunately, older versions of FreeBSD 2 do not have this feature. + freebsd2*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + # FreeBSD 3 and greater uses gcc -shared to do shared libraries. + freebsd* | kfreebsd*-gnu | dragonfly*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + hpux9*) + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + ;; + + hpux10* | hpux11*) + if test "$GCC" = yes -a "$with_gnu_ld" = no; then + case "$host_cpu" in + hppa*64*|ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' + ;; + esac + else + case "$host_cpu" in + hppa*64*|ia64*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname -o $lib $libobjs $deplibs $linker_flags' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' + ;; + esac + fi + if test "$with_gnu_ld" = no; then + case "$host_cpu" in + hppa*64*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + ia64*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + ;; + *) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + + # hardcode_minus_L: Not really in the search PATH, + # but as the default location of the library. + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + ;; + esac + fi + ;; + + irix5* | irix6* | nonstopux*) + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + ;; + + netbsd*) + if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + newsos6) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + openbsd*) + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' + else + case $host_os in + openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + ;; + *) + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' + ;; + esac + fi + ;; + + os2*) + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported + _LT_AC_TAGVAR(archive_cmds, $1)='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' + _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' + ;; + + osf3*) + if test "$GCC" = yes; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + else + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + osf4* | osf5*) # as osf3* with the addition of -msym flag + if test "$GCC" = yes; then + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' + else + _LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~ + $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp' + + # Both c and cxx compiler support -rpath directly + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' + fi + _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=: + ;; + + sco3.2v5*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + ;; + + solaris*) + _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text' + if test "$GCC" = yes; then + wlarc='${wl}' + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp' + else + wlarc='' + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + case $host_os in + solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; + *) + # The compiler driver will combine linker options so we + # cannot just pass the convience library names through + # without $wl, iff we do not link with $LD. + # Luckily, gcc supports the same syntax we need for Sun Studio. + # Supported since Solaris 2.6 (maybe 2.5.1?) + case $wlarc in + '') + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' ;; + *) + _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}-z ${wl}defaultextract' ;; + esac ;; + esac + _LT_AC_TAGVAR(link_all_deplibs, $1)=yes + ;; + + sunos4*) + if test "x$host_vendor" = xsequent; then + # Use $CC to link under sequent, because it throws in some extra .o + # files that make .init and .fini sections work. + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' + fi + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4) + case $host_vendor in + sni) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes # is this really true??? + ;; + siemens) + ## LD is ld it makes a PLAMLIB + ## CC just makes a GrossModule. + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' + _LT_AC_TAGVAR(hardcode_direct, $1)=no + ;; + motorola) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie + ;; + esac + runpath_var='LD_RUN_PATH' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv4.3*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' + ;; + + sysv4*MP*) + if test -d /usr/nec; then + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var=LD_RUN_PATH + hardcode_runpath_var=yes + _LT_AC_TAGVAR(ld_shlibs, $1)=yes + fi + ;; + + sysv4.2uw2*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_direct, $1)=yes + _LT_AC_TAGVAR(hardcode_minus_L, $1)=no + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + hardcode_runpath_var=yes + runpath_var=LD_RUN_PATH + ;; + + sysv5OpenUNIX8* | sysv5UnixWare7* | sysv5uw[[78]]* | unixware7*) + _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z ${wl}text' + if test "$GCC" = yes; then + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + else + _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' + fi + runpath_var='LD_RUN_PATH' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + sysv5*) + _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text' + # $CC -shared without GNU ld will not create a library from C++ + # object files and a static libstdc++, better avoid it by now + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~ + $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)= + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + runpath_var='LD_RUN_PATH' + ;; + + uts4*) + _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' + _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no + ;; + + *) + _LT_AC_TAGVAR(ld_shlibs, $1)=no + ;; + esac + fi +]) +AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)]) +test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no + +variables_saved_for_relink="PATH $shlibpath_var $runpath_var" +if test "$GCC" = yes; then + variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" +fi + +# +# Do we need to explicitly link libc? +# +case "x$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)" in +x|xyes) + # Assume -lc should be added + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + + if test "$enable_shared" = yes && test "$GCC" = yes; then + case $_LT_AC_TAGVAR(archive_cmds, $1) in + *'~'*) + # FIXME: we may have to deal with multi-command sequences. + ;; + '$CC '*) + # Test whether the compiler implicitly links with -lc since on some + # systems, -lgcc has to come before -lc. If gcc already passes -lc + # to ld, don't add -lc before -lgcc. + AC_MSG_CHECKING([whether -lc should be explicitly linked in]) + $rm conftest* + printf "$lt_simple_compile_test_code" > conftest.$ac_ext + + if AC_TRY_EVAL(ac_compile) 2>conftest.err; then + soname=conftest + lib=conftest + libobjs=conftest.$ac_objext + deplibs= + wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) + compiler_flags=-v + linker_flags=-v + verstring= + output_objdir=. + libname=conftest + lt_save_allow_undefined_flag=$_LT_AC_TAGVAR(allow_undefined_flag, $1) + _LT_AC_TAGVAR(allow_undefined_flag, $1)= + if AC_TRY_EVAL(_LT_AC_TAGVAR(archive_cmds, $1) 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1) + then + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no + else + _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes + fi + _LT_AC_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag + else + cat conftest.err 1>&5 + fi + $rm conftest* + AC_MSG_RESULT([$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)]) + ;; + esac fi + ;; +esac +])# AC_LIBTOOL_PROG_LD_SHLIBS + + +# _LT_AC_FILE_LTDLL_C +# ------------------- +# Be careful that the start marker always follows a newline. +AC_DEFUN([_LT_AC_FILE_LTDLL_C], [ +# /* ltdll.c starts here */ +# #define WIN32_LEAN_AND_MEAN +# #include +# #undef WIN32_LEAN_AND_MEAN +# #include +# +# #ifndef __CYGWIN__ +# # ifdef __CYGWIN32__ +# # define __CYGWIN__ __CYGWIN32__ +# # endif +# #endif +# +# #ifdef __cplusplus +# extern "C" { +# #endif +# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved); +# #ifdef __cplusplus +# } +# #endif +# +# #ifdef __CYGWIN__ +# #include +# DECLARE_CYGWIN_DLL( DllMain ); +# #endif +# HINSTANCE __hDllInstance_base; +# +# BOOL APIENTRY +# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved) +# { +# __hDllInstance_base = hInst; +# return TRUE; +# } +# /* ltdll.c ends here */ +])# _LT_AC_FILE_LTDLL_C + + +# _LT_AC_TAGVAR(VARNAME, [TAGNAME]) +# --------------------------------- +AC_DEFUN([_LT_AC_TAGVAR], [ifelse([$2], [], [$1], [$1_$2])]) + + +# old names +AC_DEFUN([AM_PROG_LIBTOOL], [AC_PROG_LIBTOOL]) +AC_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) +AC_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) +AC_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) +AC_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) +AC_DEFUN([AM_PROG_LD], [AC_PROG_LD]) +AC_DEFUN([AM_PROG_NM], [AC_PROG_NM]) + +# This is just to silence aclocal about the macro not being used +ifelse([AC_DISABLE_FAST_INSTALL]) + +AC_DEFUN([LT_AC_PROG_GCJ], +[AC_CHECK_TOOL(GCJ, gcj, no) + test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" + AC_SUBST(GCJFLAGS) +]) + +AC_DEFUN([LT_AC_PROG_RC], +[AC_CHECK_TOOL(RC, windres, no) ]) -dnl old names -AC_DEFUN([AM_PROG_LIBTOOL], [indir([AC_PROG_LIBTOOL])])dnl -AC_DEFUN([AM_ENABLE_SHARED], [indir([AC_ENABLE_SHARED], $@)])dnl -AC_DEFUN([AM_ENABLE_STATIC], [indir([AC_ENABLE_STATIC], $@)])dnl -AC_DEFUN([AM_DISABLE_SHARED], [indir([AC_DISABLE_SHARED], $@)])dnl -AC_DEFUN([AM_DISABLE_STATIC], [indir([AC_DISABLE_STATIC], $@)])dnl -AC_DEFUN([AM_PROG_LD], [indir([AC_PROG_LD])])dnl -AC_DEFUN([AM_PROG_NM], [indir([AC_PROG_NM])])dnl - -dnl This is just to silence aclocal about the macro not being used -ifelse([AC_DISABLE_FAST_INSTALL])dnl +############################################################ +# NOTE: This macro has been submitted for inclusion into # +# GNU Autoconf as AC_PROG_SED. When it is available in # +# a released version of Autoconf we should remove this # +# macro and use it instead. # +############################################################ +# LT_AC_PROG_SED +# -------------- +# Check for a fully-functional sed program, that truncates +# as few characters as possible. Prefer GNU sed if found. +AC_DEFUN([LT_AC_PROG_SED], +[AC_MSG_CHECKING([for a sed that does not truncate output]) +AC_CACHE_VAL(lt_cv_path_SED, +[# Loop through the user's path and test for sed and gsed. +# Then use that list of sed's as ones to test for truncation. +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for lt_ac_prog in sed gsed; do + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then + lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" + fi + done + done +done +lt_ac_max=0 +lt_ac_count=0 +# Add /usr/xpg4/bin/sed as it is typically found on Solaris +# along with /bin/sed that truncates output. +for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do + test ! -f $lt_ac_sed && continue + cat /dev/null > conftest.in + lt_ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >conftest.in + # Check for GNU sed and select it if it is found. + if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then + lt_cv_path_SED=$lt_ac_sed + break + fi + while true; do + cat conftest.in conftest.in >conftest.tmp + mv conftest.tmp conftest.in + cp conftest.in conftest.nl + echo >>conftest.nl + $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break + cmp -s conftest.out conftest.nl || break + # 10000 chars as input seems more than enough + test $lt_ac_count -gt 10 && break + lt_ac_count=`expr $lt_ac_count + 1` + if test $lt_ac_count -gt $lt_ac_max; then + lt_ac_max=$lt_ac_count + lt_cv_path_SED=$lt_ac_sed + fi + done +done +]) +SED=$lt_cv_path_SED +AC_MSG_RESULT([$SED]) +]) diff --git a/adm_local_without_kernel/unix/config_files/python.m4 b/adm_local_without_kernel/unix/config_files/python.m4 index a8013e290..84263a6e9 100644 --- a/adm_local_without_kernel/unix/config_files/python.m4 +++ b/adm_local_without_kernel/unix/config_files/python.m4 @@ -57,7 +57,7 @@ AC_DEFUN([CHECK_PYTHON], changequote([, ])dnl AC_SUBST(PYTHON_VERSION) - PY_MAKEFILE=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/config/Makefile + PY_MAKEFILE=$PYTHON_PREFIX/lib${LIB_LOCATION_SUFFIX}/python$PYTHON_VERSION/config/Makefile if test ! -f "$PY_MAKEFILE"; then AC_MSG_ERROR([*** Couldn't find ${PY_MAKEFILE}. Maybe you are *** missing the development portion of the python installation]) @@ -67,9 +67,9 @@ AC_DEFUN([CHECK_PYTHON], AC_SUBST(PYTHON_LIBS) PYTHON_INCLUDES=-I$PYTHON_PREFIX/include/python$PYTHON_VERSION - PYTHON_LIBS="-L${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/config -lpython${PYTHON_VERSION}" + PYTHON_LIBS="-L${PYTHON_PREFIX}/lib${LIB_LOCATION_SUFFIX}/python${PYTHON_VERSION}/config -lpython${PYTHON_VERSION}" PYTHON_LIB=$PYTHON_LIBS - PYTHON_LIBA=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/config/libpython$PYTHON_VERSION.a + PYTHON_LIBA=$PYTHON_PREFIX/lib${LIB_LOCATION_SUFFIX}/python$PYTHON_VERSION/config/libpython$PYTHON_VERSION.a dnl At times (like when building shared libraries) you may want dnl to know which OS Python thinks this is. @@ -86,12 +86,12 @@ dnl modification : by default, we install python script in salome root tree dnl [PYTHON_SITE="$withval" dnl python_site_given=yes], -dnl [PYTHON_SITE=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages +dnl [PYTHON_SITE=$PYTHON_PREFIX"/lib${LIB_LOCATION_SUFFIX}/python"$PYTHON_VERSION/site-packages dnl python_site_given=no]) [PYTHON_SITE="$withval" python_site_given=yes], -[PYTHON_SITE=$prefix"/lib/python"$PYTHON_VERSION/site-packages +[PYTHON_SITE=$prefix"/lib${LIB_LOCATION_SUFFIX}/python"$PYTHON_VERSION/site-packages python_site_given=no]) AC_SUBST(PYTHON_SITE_PACKAGE) @@ -109,7 +109,7 @@ python_site_given=no]) [if test "$python_site_given" = yes; then PYTHON_SITE_EXEC=$PYTHON_SITE else - PYTHON_SITE_EXEC=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages + PYTHON_SITE_EXEC=$PYTHON_EXEC_PREFIX"/lib${LIB_LOCATION_SUFFIX}/python"$PYTHON_VERSION/site-packages fi]) dnl Set up the install directory @@ -120,7 +120,7 @@ fi]) dnl Also lets automake think PYTHON means something. - pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/ + pythondir=$PYTHON_PREFIX"/lib${LIB_LOCATION_SUFFIX}/python"$PYTHON_VERSION/ AC_SUBST(pythondir) AC_MSG_CHECKING([if we need libdb]) diff --git a/adm_local_without_kernel/unix/make_module.in b/adm_local_without_kernel/unix/make_module.in index 9ba19557b..843465d13 100644 --- a/adm_local_without_kernel/unix/make_module.in +++ b/adm_local_without_kernel/unix/make_module.in @@ -56,9 +56,9 @@ resources: resources-cp (cd $$d && $(MAKE) $@) || exit 1; \ done -resources-cp: $(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/%) +resources-cp: $(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/$(MODULE_NAME)/%) -$(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/%): $(top_builddir)/share/salome/resources/% : % +$(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/$(MODULE_NAME)/%): $(top_builddir)/share/salome/resources/$(MODULE_NAME)/% : % cp -fr $< $@; data: @@ -104,15 +104,15 @@ distclean: clean @@SETX@; for d in $(SUBDIRS); do \ (cd $$d && $(MAKE) $@) || exit 1; \ done - -$(RM) $(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/%) + -$(RM) $(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/$(MODULE_NAME)/%) -$(RM) Makefile install-resources: resources-cp # one resources directory for all salome modules - $(INSTALL) -d $(datadir)/resources - @for f in X $(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/%); do \ + $(INSTALL) -d $(datadir)/resources/$(MODULE_NAME) + @for f in X $(RESOURCES_FILES:%=$(top_builddir)/share/salome/resources/$(MODULE_NAME)/%); do \ if test $$f != X; then \ - ($(INSTALL_DATA) $$f $(datadir)/resources/. || exit 1); \ + ($(INSTALL_DATA) $$f $(datadir)/resources/$(MODULE_NAME)/. || exit 1); \ fi; \ done @@ -120,7 +120,7 @@ install-resources: resources-cp uninstall-resources: @for f in X $(RESOURCES_FILES); do \ if test $$f != X; then \ - $(LT_UNINSTALL) $(datadir)/resources/$$f ; \ + $(LT_UNINSTALL) $(datadir)/resources/$(MODULE_NAME)/$$f ; \ fi; \ done diff --git a/bin/Makefile.am b/bin/Makefile.am new file mode 100644 index 000000000..e81b2089a --- /dev/null +++ b/bin/Makefile.am @@ -0,0 +1,22 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +nodist_salomescript_DATA= VERSION +EXTRA_DIST+= VERSION.in diff --git a/build_configure b/build_configure index 872aa0f63..e928e0d10 100755 --- a/build_configure +++ b/build_configure @@ -11,6 +11,8 @@ # Date : 10/10/2002 # $Header$ # +# 14/03/2007: Mikhail PONIKAROV - OCN +# Reorganization for uage of autotools ORIG_DIR=`pwd` CONF_DIR=`echo $0 | sed -e "s,[^/]*$,,;s,/$,,;s,^$,.,"` @@ -19,275 +21,146 @@ CONF_DIR=`echo $0 | sed -e "s,[^/]*$,,;s,/$,,;s,^$,.,"` # Check --with-kernel option MED_WITH_KERNEL="yes" +MED_WITH_GUI="yes" for option do case $option in -with-kernel | --with-kernel) MED_WITH_KERNEL="yes" + MED_WITH_GUI="yes" break;; -without-kernel | --without-kernel | -with-kernel=no | --with-kernel=no) MED_WITH_KERNEL="no" + MED_WITH_GUI="no" break;; esac done +for option +do + case $option in + -with-ihm | --with-ihm) + MED_WITH_GUI="yes" + break;; + -without-ihm | --without-ihm | -with-ihm=no | --with-ihm=no) + MED_WITH_GUI="no" + break;; + esac +done +######################################################################## +# Test if the KERNEL_ROOT_DIR is set correctly if KERNEL required + +if test ${MED_WITH_KERNEL} = yes; then + if test ! -d "${KERNEL_ROOT_DIR}"; then + echo "failed : KERNEL_ROOT_DIR variable is not correct !" + exit + fi +fi ######################################################################## # Test if the GUI_ROOT_DIR is set correctly if GUI required -if test "$MED_WITH_KERNEL" = "yes"; then +if test ${MED_WITH_GUI} = yes; then if test ! -d "${GUI_ROOT_DIR}"; then echo "failed : GUI_ROOT_DIR variable is not correct !" exit fi fi -######################################################################## -# find_in - utility function -# -# usage : -# find_in directory filename -# -# Finds files following the *.in pattern, recursively in the -# directory (first argument). -# Results are appended into the file (second argument) -# -# Difference from the standard unix find is that files are tested -# before directories -# - -find_in() -{ - i=0 - f=$2 - -# if the first argument is not a directory, returns - - if [ ! -d "$1" ] ; then - return - fi - -# dont look in the CVS directories - - case $1 in - */CVS) return ;; - */adm_local/*) return ;; - *) ;; - esac - -# for each regular file contained in the directory -# test if it's a .in file - - for i in "$1"/* - do - if [ -f "$i" ] ; then - case $i in - *.in) echo " "$i" \\" >> $f;; - *) ;; - esac - fi - done - -# for each subdirectory of the first argument, proceeds recursively - - for i in "$1"/* - do - if [ -d "$i" ] ; then - find_in "$i" "$f" - fi - done -} - - -####################################################################### -# Generate list of .in files (Makefile.in, config.h.in, etc) -# appending it in file configure.in - cd ${CONF_DIR} ABS_CONF_DIR=`pwd` -# -# Common part of the configure.in file -# -if \cp -f configure.in.base configure.in_tmp1 -then - echo - chmod u+w configure.in_tmp1 -else - echo - echo "error : can't create files in" ${CONF_DIR} - echo "aborting ..." - exit -fi -chmod u-w configure.in.base - -if [ -e "${CONF_DIR}/salome_adm" ] ; then - \rm -f ${CONF_DIR}/salome_adm -fi - -# insert header and AC_INIT(src) which must go before anything else -cat > configure.in_tmp1 <> configure.in_tmp1 - -# insert the configure.in.base -cat configure.in.base >> configure.in_tmp1 - -# make a link allowing AC_OUTPUT to find the salome_adm/.../*.in files -echo "" >> configure.in_tmp1 -echo 'if test ${MED_WITH_KERNEL} = yes; then' >> configure.in_tmp1 -echo ' ln -fs ${KERNEL_ROOT_DIR}/salome_adm ${ROOT_SRCDIR}/.' >> configure.in_tmp1 -echo 'else' >> configure.in_tmp1 -echo ' ln -fs ${ROOT_SRCDIR}/adm_local_without_kernel ${ROOT_SRCDIR}/salome_adm' >> configure.in_tmp1 -echo 'fi' >> configure.in_tmp1 - - -# -# List of .in files in the adm/unix directory -# These files MUST be on top of AC_OUTPUT list so we -# put them "manually" -# -# Attention, l'ordre d'entrĂ©e des fichiers doit Ăªtre choisi avec -# prĂ©cision -# -echo "" >> configure.in_tmp1 -echo "AC_OUTPUT([ \\" >> configure.in_tmp1 -echo " ./salome_adm/unix/SALOMEconfig.h \\" >> configure.in_tmp1 -echo " ./salome_adm/unix/sstream \\" >> configure.in_tmp1 -echo " ./salome_adm/unix/depend \\" >> configure.in_tmp1 -echo " ])" >> configure.in_tmp1 -echo "" >> configure.in_tmp1 -echo 'if test $MED_WITH_KERNEL = yes; then' >> configure.in_tmp1 -echo "{" >> configure.in_tmp1 -echo "AC_OUTPUT([ \\" >> configure.in_tmp1 -echo " ./salome_adm/unix/F77config.h \\" >> configure.in_tmp1 -echo " ./adm_local/unix/make_omniorb:${ABS_CONF_DIR}/adm_local/unix/make_omniorb.in \\" >> configure.in_tmp1 -echo " ./salome_adm/unix/envScript \\" >> configure.in_tmp1 -echo " ])" >> configure.in_tmp1 -echo "}" >> configure.in_tmp1 -echo "fi" >> configure.in_tmp1 -echo "" >> configure.in_tmp1 -echo "AC_OUTPUT([ \\" >> configure.in_tmp1 -echo " ./salome_adm/unix/make_module \\" >> configure.in_tmp1 - -# _CS_gbo Pour assurer ls construction correct de la chaĂ®ne de -# dĂ©pendance, il apparaĂ®t nĂ©cessaire de surcharger le make_conclude -# (resp. make_commence) pardĂ©faut, c'est Ă  dire le make_conclude de -# salome_adm, par le make_conclude (resp. make_commence) du module, -# c'est Ă  dire le make_conclude (resp. make_commence) du rĂ©pertoire -# adm_local -echo " ./adm_local/unix/make_commence:${ABS_CONF_DIR}/adm_local/unix/make_commence.in \\" >> configure.in_tmp1 -echo " ./adm_local/unix/make_conclude:${ABS_CONF_DIR}/adm_local/unix/make_conclude.in \\" >> configure.in_tmp1 - -\rm -f configure.in_tmp2 configure.in_tmp3 -touch configure.in_tmp2 - -find_in . configure.in_tmp2 - -# _CS_gbo_100204 Mise Ă  jour du filtre pour prise en compte des -# restrictions imposĂ©es par les versions rĂ©cente de autoconf. - sed -e '/^...salome_adm/d' \ - -e '/configure.in/d' \ - -e 's/.in / /' configure.in_tmp2 >> configure.in_tmp1 - -echo " ])" >> configure.in_tmp1 - - -# delete the link created for AC_OUTPUT -#echo 'rm -f ${ROOT_SRCDIR}/salome_adm' >> configure.in_tmp1 -\mv configure.in_tmp1 configure.in_new -\rm -f configure.in_tmp2 configure.in_tmp3 - - -######################################################################## -# Create new (or replace old) configure.in file -# Print a message if the file is write protected -# - -echo -if test ! -f configure.in -then - echo -n "Creating new file 'configure.in' ... " - if \mv configure.in_new configure.in >& /dev/null - then - echo "done" - else - echo "error, check your file permissions" - fi -else - echo -n "Updating 'configure.in' file ... " - if \cp configure.in configure.in_old >& /dev/null - then - echo - else - echo - echo - echo "Can't backup previous configure.in" - echo -n "Continue (you will not be able to revert) - (Y/N) ? " - read R - case "x$R" in - xn*) exit;; - xN*) exit;; - esac - echo - echo -n " " - fi - if \cp configure.in_new configure.in >& /dev/null - then - echo "done" - else - echo - echo "error, can't update previous configure.in" - fi -fi - -######################################################################## -# Use autoconf to rebuild the configure script -# - -if test -f configure -then - echo -n "Updating 'configure' script ... " -else - echo -n "Creating 'configure' script ... " -fi - -if test "x${MED_WITH_KERNEL}" != "xno"; then - AUX_CONFIG_INC="-I ${KERNEL_ROOT_DIR}/salome_adm/unix/config_files -I ${GUI_ROOT_DIR}/adm_local/unix/config_files" -else - AUX_CONFIG_INC="-I adm_local_without_kernel/unix/config_files" +####################################################################### +# Update configure.ac script: to set MED_WITH_KERNEL and MED_WITH_GUI variables +sed -e s/MED_WITH_KERNEL=[a-z]*/MED_WITH_KERNEL=${MED_WITH_KERNEL}/g configure.ac > configure.tmp +sed -e s/MED_WITH_GUI=[a-z]*/MED_WITH_GUI=${MED_WITH_GUI}/g configure.tmp > configure.ac +rm configure.tmp + +# copy configure files +CONFIGURE_SOURCE_DIR=${KERNEL_ROOT_DIR}/salome_adm +if test ${MED_WITH_KERNEL} = no; then + CONFIGURE_SOURCE_DIR=${ABS_CONF_DIR}/adm_local_without_kernel fi -aclocal -I adm_local/unix/config_files ${AUX_CONFIG_INC} -if autoconf -then - echo "done" +rm -rf salome_adm +mkdir -p salome_adm/unix/config_files +#cp -f ${CONFIGURE_SOURCE_DIR}/unix/config_files/* salome_adm/unix/config_files +cp -f ${CONFIGURE_SOURCE_DIR}/unix/SALOMEconfig.h.in salome_adm/unix +#if test ${MED_WITH_KERNEL} = yes; then +# cp -f ${CONFIGURE_SOURCE_DIR}/unix/pythonbe.py salome_adm/unix +#fi + +# if with GUI, cofy configure files from it +#if test ${MED_WITH_GUI} = yes; then +# cp -f ${GUI_ROOT_DIR}/adm_local/unix/config_files/* salome_adm/unix/config_files +#fi + +# remove KERNEL deprecated configure files +#for deprecated in ac_cc_warnings.m4 ac_cxx_partial_specialization.m4 \ +# check_mico.m4 config.guess ltmain.sh ac_cxx_bool.m4 ltconfig ac_cxx_typename.m4 \ +# check_pthreads.m4 config.sub libtool.m4 ac_cxx_mutable.m4 missing +#do +# rm -f salome_adm/unix/config_files/${deprecated} +#done + +# ____________________________________________________________________ +# aclocal creates the aclocal.m4 file from the standard macro and the +# custom macro embedded in the directory salome_adm/unix/config_files +# and KERNEL config_files directory. +# output: +# aclocal.m4 +# autom4te.cache (directory) +echo "====================================================== aclocal" + +if test ${MED_WITH_GUI} = yes; then + aclocal -I adm_local/unix/config_files \ + -I ${CONFIGURE_SOURCE_DIR}/unix/config_files \ + -I ${GUI_ROOT_DIR}/adm_local/unix/config_files || exit 1 else - echo "failed (check file permissions and/or user quotas ...)" + aclocal -I adm_local/unix/config_files \ + -I ${CONFIGURE_SOURCE_DIR}/unix/config_files || exit 1 fi -cd ${ORIG_DIR} - -echo +# ____________________________________________________________________ +# libtoolize creates some configuration files (ltmain.sh, +# config.guess and config.sub). It only depends on the libtool +# version. The files are created in the directory specified with the +# AC_CONFIG_AUX_DIR() tag (see configure.ac). +# output: +# salome_adm/unix/config_files/config.guess +# salome_adm/unix/config_files/config.sub +# salome_adm/unix/config_files/ltmain.sh +#echo "====================================================== libtoolize" + +libtoolize --force --copy --automake || exit 1 + +# ____________________________________________________________________ +# make link to KERNEL configuration files to +#ln -sf ${KERNEL_ROOT_DIR}/salome_adm . + +# ____________________________________________________________________ +# autoconf creates the configure script from the file configure.ac (or +# configure.in if configure.ac doesn't exist) +# output: +# configure +echo "====================================================== autoconf" + +autoconf + +# ____________________________________________________________________ +# automake creates some scripts used in building process +# (install-sh, missing, ...). It only depends on the automake +# version. The files are created in the directory specified with the +# AC_CONFIG_AUX_DIR() tag (see configure.ac). This step also +# creates the Makefile.in files from the Makefile.am files. +# output: +# salome_adm/unix/config_files/compile +# salome_adm/unix/config_files/depcomp +# salome_adm/unix/config_files/install-sh +# salome_adm/unix/config_files/missing +# salome_adm/unix/config_files/py-compile +# Makefile.in (from Makefile.am) +echo "====================================================== automake" + +automake --copy --gnu --add-missing diff --git a/clean_configure b/clean_configure new file mode 100755 index 000000000..be0b5427f --- /dev/null +++ b/clean_configure @@ -0,0 +1,15 @@ +#!/bin/sh + +rm -rf autom4te.cache aclocal.m4 configure make_config +find . -name "*~" -print -exec rm {} \; +find . -name "*.pyc" -print -exec rm {} \; +#exit +# ==================== ON SORT AVANT + +find bin -name Makefile.in | xargs rm -f +find doc -name Makefile.in | xargs rm -f +find idl -name Makefile.in | xargs rm -f +find resources -name Makefile.in | xargs rm -f +find salome_adm -name Makefile.in | xargs rm -f +find src -name Makefile.in | xargs rm -f +rm -f Makefile.in diff --git a/configure.ac b/configure.ac new file mode 100644 index 000000000..cb4879c02 --- /dev/null +++ b/configure.ac @@ -0,0 +1,652 @@ +# Author : Marc Tajchman (CEA) +# Date : 28/06/2001 +# Modified by : Patrick GOLDBRONN (CEA) +# Modified by : Marc Tajchman (CEA) +# Modified by : Mikhail PONIKAROV (OCN) +# + +AC_INIT([Salome2 Project MED module], [4.1.1], [webmaster.salome@opencascade.com], [salome]) +AC_CONFIG_AUX_DIR(salome_adm/unix/config_files) +AC_CANONICAL_HOST +AC_CANONICAL_TARGET +AM_INIT_AUTOMAKE + +XVERSION=`echo $VERSION | awk -F. '{printf("0x%02x%02x%02x",$1,$2,$3)}'` +AC_SUBST(XVERSION) + +# set up MODULE_NAME variable for dynamic construction of directories (resources, etc.) +MODULE_NAME=med +AC_SUBST(MODULE_NAME) + +dnl +dnl Initialize source and build root directories +dnl +ROOT_BUILDDIR=`pwd` +ROOT_SRCDIR=`echo $0 | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` +cd $ROOT_SRCDIR +ROOT_SRCDIR=`pwd` +cd $ROOT_BUILDDIR + +AC_SUBST(ROOT_SRCDIR) +AC_SUBST(ROOT_BUILDDIR) + +echo +echo Source root directory : $ROOT_SRCDIR +echo Build root directory : $ROOT_BUILDDIR +echo +echo + +dnl remember MED_WITH_KERNEL set by build configure +MED_WITH_KERNEL=yes +MED_WITH_GUI=yes +old_with_kernel=${MED_WITH_KERNEL} + +dnl +dnl Check --with-kernel option +echo +dnl --------------------------------------------- + WITH_KERNEL +dnl --------------------------------------------- +dnl + +dnl Update and re-run configure if there was build_configure --without-kernel +dnl but configure --with-kernel=DIR is being called + +if test "x${old_with_kernel}" != "x${MED_WITH_KERNEL}"; then + if test "x${old_with_kernel}" = "xno" ; then + if test ! -d "${KERNEL_ROOT_DIR}"; then + echo "failed : KERNEL_ROOT_DIR variable is not correct !" + exit + fi + kernel_check_in_aclocal=`grep KERNEL_ROOT_DIR ${ROOT_SRCDIR}/aclocal.m4` + if test "x${kernel_check_in_aclocal}" = "x"; then + echo "Configuration changed: without KERNEL -> with KERNEL" + echo -n "Updating 'configure' script ... " + cd $ROOT_SRCDIR + if build_configure --with-kernel={MED_WITH_KERNEL} --with-gui={MED_WITH_GUI}; then + echo "... done" + else + echo "... failed" + cd $ROOT_BUILDDIR + exit 1 + fi + cd $ROOT_BUILDDIR + $0 $* + exit + fi + fi +fi + +AM_CONDITIONAL(MED_ENABLE_KERNEL, [test "$MED_WITH_KERNEL" = yes]) +AM_CONDITIONAL(MED_ENABLE_GUI, [test "$MED_WITH_GUI" = yes]) + +dnl Modification B. Secher portage sur osf CCRT +AC_CHECK_PROG(SHELL,sh,,) +AC_SUBST(SHELL) + +if test -z "$AR"; then + AC_CHECK_PROGS(AR,ar xar,:,$PATH) +fi +AC_SUBST(AR) + +dnl Export the AR macro so that it will be placed in the libtool file +dnl correctly. +export AR + +echo +echo --------------------------------------------- +echo testing make +echo --------------------------------------------- +echo + +AC_PROG_MAKE_SET +AC_PROG_INSTALL +dnl +dnl libtool macro check for CC, LD, NM, LN_S, RANLIB, STRIP + pour les librairies dynamiques ! + +AC_ENABLE_DEBUG(yes) +AC_DISABLE_PRODUCTION + +echo --------------------------------------------- +echo testing libtool +echo --------------------------------------------- + +dnl first, we set static to no! +dnl if we want it, use --enable-static +AC_ENABLE_STATIC(no) + +AC_LIBTOOL_DLOPEN +AC_PROG_LIBTOOL + +dnl Fix up the INSTALL macro if it s a relative path. We want the +dnl full-path to the binary instead. +case "$INSTALL" in + *install-sh*) + INSTALL='\${ROOT_BUILDDIR}'/salome_adm/unix/config_files/install-sh + ;; +esac + +echo +echo --------------------------------------------- +echo testing C/C++ +echo --------------------------------------------- +echo + +cc_ok=no +dnl inutil car libtool +dnl AC_PROG_CC +AC_PROG_CXX +AC_CXX_WARNINGS +AC_CXX_TEMPLATE_OPTIONS +AC_DEPEND_FLAG +# AC_CC_WARNINGS([ansi]) +cc_ok=yes + +dnl Library libdl : +AC_CHECK_LIB(dl,dlopen) + +dnl Library librt : for alpha/osf +AC_CHECK_LIB(rt,nanosleep) + +dnl add library libm : +AC_CHECK_LIB(m,ceil) + +dnl +dnl Check if we use std iostream by default or if we must add +dnl a compiler directive for that +dnl + +AC_CXX_USE_STD_IOSTREAM + +dnl +dnl Well we use sstream which is not in gcc pre-2.95.3 +dnl We must test if it exists. If not, add it in include ! +dnl + +AC_CXX_HAVE_SSTREAM +AM_CONDITIONAL(MED_ENABLE_SSTREAM, [test "$HAVE_SSTREAM" = yes]) + +dnl +dnl --------------------------------------------- +dnl testing linker +dnl --------------------------------------------- +dnl + +AC_LINKER_OPTIONS + +echo +echo --------------------------------------------- +echo testing threads +echo --------------------------------------------- +echo + +ENABLE_PTHREADS + +echo +echo --------------------------------------------- +echo testing python +echo --------------------------------------------- +echo + +CHECK_PYTHON + +echo +echo --------------------------------------------- +echo testing swig +echo --------------------------------------------- +echo + +AM_PATH_PYTHON(2.3) +CHECK_SWIG +AM_CONDITIONAL(MED_SWIG_1_3_21, [test "$SWIG_VERSION" = 1.3.21]) + +echo +echo --------------------------------------------- +echo testing HDF5 +echo --------------------------------------------- +echo + +CHECK_HDF5 + + +echo +echo --------------------------------------------- +echo BOOST Library +echo --------------------------------------------- +echo + +CHECK_BOOST + + +echo +echo --------------------------------------------- +echo testing MED2 +echo --------------------------------------------- +echo + +CHECK_MED2 + +echo +echo --------------------------------------------- +echo "MED_WITH_KERNEL: ${MED_WITH_KERNEL}" +echo "MED_WITH_GUI : ${MED_WITH_GUI}" +echo --------------------------------------------- + +openpbs_ok=no +# CHECK_OPENPBS ONLY if MED_WITH_KERNEL=yes +# echo +# echo --------------------------------------------- +# echo testing OpenPBS +# echo --------------------------------------------- +# echo + +# CHECK_OPENPBS +# dnl openpbs_ok is set to yes by CHECK_OPENPBS + +# CHECK_LSF ONLY if MED_WITH_KERNEL=yes +# echo +# echo --------------------------------------------- +# echo testing LSF +# echo --------------------------------------------- +# echo + +lsf_ok=no +# CHECK_LSF +# dnl lsf_ok is set to yes by CHECK_LSF + +echo +echo ---------------------------------------------- +echo testing CPPUNIT only required for unit testing +echo ---------------------------------------------- +echo +CHECK_CPPUNIT +#AM_CONDITIONAL(CPPUNIT_IS_OK, test) + +echo +echo --------------------------------------------- +echo checking SPLITTER +echo --------------------------------------------- +echo +AC_ENABLE_SPLITTER(yes) +AM_CONDITIONAL(MED_ENABLE_SPLITTER, [test "$ENABLE_SPLITTER" = yes]) + +if test "x$ENABLE_SPLITTER" = "xyes"; then + + echo + echo --------------------------------------------- + echo testing METIS + echo --------------------------------------------- + echo + metis_ok=no + CHECK_METIS dnl metis_ok is set to yes by CHECK_METIS + + + echo + echo --------------------------------------------- + echo testing SCOTCH + echo --------------------------------------------- + echo scotch_ok=no + CHECK_SCOTCH + dnl scotch_ok is set to yes by CHECK_SCOTCH + + + echo + echo --------------------------------------------- + echo testing LIBXML2 + echo --------------------------------------------- + echo libxml_ok=no + CHECK_LIBXML + dnl libxml_ok is set to yes by CHECK_LIBXML + +fi + +AM_CONDITIONAL(MED_ENABLE_METIS, [test "$ENABLE_METIS" = yes]) +AM_CONDITIONAL(MED_ENABLE_SCOTCH, [test "$ENABLE_SCOTCH" = yes]) + + +if test "${MED_WITH_KERNEL}" = "yes"; then +{ + + + echo + echo --------------------------------------------- + echo testing OpenPBS + echo --------------------------------------------- + echo + + CHECK_OPENPBS + + echo + echo --------------------------------------------- + echo testing LSF + echo --------------------------------------------- + echo + + CHECK_LSF + + dnl + dnl --------------------------------------------- + dnl testing sockets + dnl --------------------------------------------- + dnl + + CHECK_SOCKETS + + dnl + dnl --------------------------------------------- + dnl testing Batch + dnl --------------------------------------------- + dnl + + WITH_BATCH=no + test x$openpbs_ok = xyes || test x$lsf_ok = xyes && WITH_BATCH=yes + AC_SUBST(WITH_BATCH) + + if test "${MED_WITH_GUI}" = "yes"; then + echo + echo --------------------------------------------- + echo testing LEX \& YACC + echo --------------------------------------------- + echo + + lex_yacc_ok=no + AC_PROG_YACC + AC_PROG_LEX + lex_yacc_ok=yes + fi + + dnl + dnl --------------------------------------------- + dnl testing MPI + dnl --------------------------------------------- + dnl + + CHECK_MPI + CHECK_MPICH + + dnl echo + dnl echo --------------------------------------------- + dnl echo testing java + dnl echo --------------------------------------------- + dnl echo + + dnl CHECK_JAVA + + echo + echo --------------------------------------------- + echo testing omniORB + echo --------------------------------------------- + echo + + CHECK_OMNIORB + + echo + echo --------------------------------------------- + echo default ORB : omniORB + echo --------------------------------------------- + echo + + DEFAULT_ORB=omniORB + CHECK_CORBA + + AC_SUBST_FILE(CORBA) + corba=make_$ORB + CORBA=adm_local/unix/$corba + + if test "${MED_WITH_GUI}" = "yes"; then + + echo + echo --------------------------------------------- + echo testing openGL + echo --------------------------------------------- + echo + + CHECK_OPENGL + + echo + echo --------------------------------------------- + echo testing QT + echo --------------------------------------------- + echo + + CHECK_QT + + echo + echo --------------------------------------------- + echo testing VTK + echo --------------------------------------------- + echo + + CHECK_VTK + fi + + echo + echo --------------------------------------------- + echo Testing OpenCascade + echo --------------------------------------------- + echo + + CHECK_CAS + + echo + echo --------------------------------------------- + echo Testing Kernel + echo --------------------------------------------- + echo + + CHECK_KERNEL + + dnl echo + dnl echo --------------------------------------------- + dnl echo testing mico + dnl echo --------------------------------------------- + dnl echo + + dnl CHECK_MICO + + if test "${MED_WITH_GUI}" = "yes"; then + echo + echo --------------------------------------------- + echo testing MSG2QM + echo --------------------------------------------- + echo + + CHECK_MSG2QM + fi + + echo + echo --------------------------------------------- + echo Testing html generators + echo --------------------------------------------- + echo + + CHECK_HTML_GENERATORS +} +else +{ + WITHIHM="no" + WITHOPENPBS="no" + + AC_SUBST(WITHIHM) + AC_SUBST(WITHOPENPBS) + CPPFLAGS="$CPPFLAGS -DMED_WITHOUT_KERNEL" +} +fi # MED_WITH_KERNEL + +if test "${MED_WITH_GUI}" = "yes"; then +{ + echo + echo --------------------------------------------- + echo Testing GUI + echo --------------------------------------------- + echo + + CHECK_SALOME_GUI + + echo + echo --------------------------------------------- + echo Testing full GUI + echo --------------------------------------------- + echo + + CHECK_CORBA_IN_GUI + if test "x${CORBA_IN_GUI}" != "xyes"; then + echo "failed : For configure MED module necessary full GUI !" + exit + fi +} +fi # MED_WITH_GUI + +echo +echo --------------------------------------------- +echo Summary +echo --------------------------------------------- +echo + +if test "$MED_WITH_KERNEL" = "no"; then + echo "Configure (without Kernel)" +else + echo Configure +fi + +#variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok hdf5_ok med2_ok boost_ok doxygen_ok graphviz_ok OpenGL_ok qt_ok vtk_ok omniORB_ok occ_ok Kernel_ok" + +if test "${MED_WITH_GUI}" = "yes"; then +variables="cc_ok lex_yacc_ok mpi_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok med2_ok omniORB_ok occ_ok sip_ok pyqt_ok qwt_ok Kernel_ok cppunit_ok" +fi + +if test "${MED_WITH_GUI}" = "no"; then +variables="cc_ok mpi_ok python_ok swig_ok threads_ok hdf5_ok med2_ok omniORB_ok occ_ok Kernel_ok cppunit_ok" +fi + +for var in $variables +do + eval toto=\$$var + if test x$toto != "x"; then + printf " %10s : " `echo \$var | sed -e "s,_ok,,"` + eval echo \$$var + fi +done + +dnl optional variables + +echo "---Optional:" +variables="metis_ok scotch_ok libxml_ok" +for var in $variables + do + eval toto=\$$var + if test x$toto != "x"; then + printf " %10s : " `echo \$var | sed -e "s,_ok,,"` + eval echo \$$var + fi + done + +if test "${MED_WITH_KERNEL}" = "yes"; then +{ + variables="openpbs_ok lsf_ok doxygen_ok graphviz_ok" + + for var in $variables + do + eval toto=\$$var + if test x$toto != "x"; then + printf " %10s : " `echo \$var | sed -e "s,_ok,,"` + eval echo \$$var + fi + done +} +fi + +echo +echo "Default ORB : $DEFAULT_ORB" +echo + +dnl We don t need to say when we re entering directories if we re using +dnl GNU make becuase make does it for us. +if test "X$GMAKE" = "Xyes"; then + AC_SUBST(SETX) SETX=":" +else + AC_SUBST(SETX) SETX="set -x" +fi + +echo +echo --------------------------------------------- +echo generating Makefiles and configure files +echo --------------------------------------------- +echo + +AC_OUTPUT_COMMANDS([ \ + chmod +x ./bin/* \ +]) + +AC_OUTPUT([ \ + ./salome_adm/unix/SALOMEconfig.h \ + ./adm_local_without_kernel/unix/sstream \ + Makefile \ + ./MED_version.h \ + ./adm_local/unix/config_files/Makefile \ + ./adm_local/unix/Makefile \ + ./adm_local/Makefile \ + ./adm_local_without_kernel/unix/config_files/Makefile \ + ./adm_local_without_kernel/unix/Makefile \ + ./adm_local_without_kernel/Makefile \ + ./resources/Makefile + ./resources/MEDCatalog.xml \ + ./bin/Makefile \ + ./bin/VERSION \ + ./idl/Makefile \ + ./src/Makefile \ + ./src/MEDWrapper/Makefile \ + ./src/MEDWrapper/Base/Makefile \ + ./src/MEDWrapper/Factory/Makefile \ + ./src/MEDWrapper/V2_1/Makefile \ + ./src/MEDWrapper/V2_1/Core/Makefile \ + ./src/MEDWrapper/V2_1/Wrapper/Makefile \ + ./src/MEDWrapper/V2_2/Makefile \ + ./src/MEDMEM/Doxyfile_med_devel \ + ./src/MEDMEM/Doxyfile_med_user \ + ./src/MEDMEM/Makefile \ + ./src/MEDMEM/Test/Makefile \ + ./src/INTERPOLATION/Makefile \ + ./src/MEDMEM_SWIG/Makefile \ + ./src/MEDSPLITTER/Makefile \ + ./src/MEDSPLITTER/Test/Makefile \ + ./src/MULTIPR/Makefile \ + ./src/MEDMEM_I/Makefile \ + ./src/MED/Makefile \ + ./src/MedCorba_Swig/Makefile \ + ./src/MED_SWIG/Makefile \ + ./src/MedClient/Makefile \ + ./src/MedClient/src/Makefile \ + ./src/MedClient/test/Makefile \ + ./src/MedClient/test/environ/Makefile \ + ./src/MedClient/test/environ/runContainer \ + ./src/MedClient/test/environ/runEnvironTests \ + ./src/MedClient/test/environ/runTestMedCorba \ + ./src/MedClient/test/environ/stopContainer \ + ./src/MedClient/test/environ/csh/init1 \ + ./src/MedClient/test/environ/csh/init2 \ + ./src/MedClient/test/environ/csh/init3 \ + ./src/MedClient/test/environ/csh/Makefile \ + ./src/MedClient/test/environ/csh/runContainer \ + ./src/MedClient/test/environ/csh/runEnvironTests \ + ./src/MedClient/test/environ/csh/stopContainer \ + ./src/MedClient/test/test1/Makefile \ + ./src/MedClient/test/test2/Makefile \ + ./src/MEDGUI/Makefile \ + ./doc/Makefile \ + ./doc/MEDMEM/Makefile \ + ./doc/MEDMEM/MEDMEM_Content.tex \ + ./doc/MEDMEM/MEDMEM_UML_light.png \ + ./doc/MEDMEM/MEDMEM_UML.png \ + ./doc/MEDMEM/MEDMEM_UsersGuide.tex \ + ./doc/salome/Makefile \ + ./doc/salome/tui/Makefile \ + ./doc/salome/tui/MED/Makefile \ + ./doc/salome/tui/MED/sources/Makefile \ + ./doc/salome/tui/MED/sources/static/Makefile \ + ./doc/salome/tui/MED/doxyfile \ + ./doc/salome/tui/MED/sources/static/tree.js +]) + +dnl To avoid recompiling half of the sources because of SALOMEconfig.h recreating +touch -d 01Jan2007 ./salome_adm/unix/SALOMEconfig.h diff --git a/configure.in.base b/configure.in.base deleted file mode 100644 index a36871aa8..000000000 --- a/configure.in.base +++ /dev/null @@ -1,584 +0,0 @@ - -PACKAGE=salome -AC_SUBST(PACKAGE) - -VERSION=3.2.0 -XVERSION=0x030200 -AC_SUBST(VERSION) -AC_SUBST(XVERSION) - -dnl -dnl Initialize source and build root directories -dnl - -ROOT_BUILDDIR=`pwd` -ROOT_SRCDIR=`echo $0 | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` -cd $ROOT_SRCDIR -ROOT_SRCDIR=`pwd` -cd $ROOT_BUILDDIR - -AC_SUBST(ROOT_SRCDIR) -AC_SUBST(ROOT_BUILDDIR) - -echo -echo Source root directory : $ROOT_SRCDIR -echo Build root directory : $ROOT_BUILDDIR -echo -echo - -dnl remember MED_WITH_KERNEL set by build configure -old_with_kernel=${MED_WITH_KERNEL} - -dnl -dnl Check --with-kernel option -echo -dnl --------------------------------------------- - WITH_KERNEL -dnl --------------------------------------------- -dnl - -dnl Update and re-run configure if there was build_configure --without-kernel -dnl but configure --with-kernel=DIR is being called - -if test "x${old_with_kernel}" != "x${MED_WITH_KERNEL}"; then - if test "x${old_with_kernel}" = "xno" ; then - if test ! -d "${KERNEL_ROOT_DIR}"; then - echo "failed : KERNEL_ROOT_DIR variable is not correct !" - exit - fi - kernel_check_in_aclocal=`grep KERNEL_ROOT_DIR ${ROOT_SRCDIR}/aclocal.m4` - if test "x${kernel_check_in_aclocal}" = "x"; then - echo "Configuration changed: without KERNEL -> with KERNEL" - echo -n "Updating 'configure' script ... " - cd $ROOT_SRCDIR - aclocal -I adm_local/unix/config_files -I ${KERNEL_ROOT_DIR}/salome_adm/unix/config_files - if autoconf; then - echo "done" - else - echo "failed (check file permissions and/or user quotas ...)" - cd $ROOT_BUILDDIR - exit - fi - cd $ROOT_BUILDDIR - $0 $* - exit - fi - fi -fi - - -dnl AC_CONFIG_AUX_DIR - path to install-sh, config.sub, config.guess, -dnl Automake and Libtool scripts etc. -dnl config.sub, config.guess are needed for AC_CANONICAL_HOST - -WITHOUT_KERNEL_CONFIG_DIR=${ROOT_SRCDIR}/adm_local_without_kernel/unix/config_files -AUX_CONFIG_DIR="" -if test "${MED_WITH_KERNEL}" = "yes"; then - AUX_CONFIG_DIR=${KERNEL_ROOT_DIR}/salome_adm/unix/config_files -else - AUX_CONFIG_DIR=${WITHOUT_KERNEL_CONFIG_DIR} -fi -AC_CONFIG_AUX_DIR(${AUX_CONFIG_DIR}) -AC_CANONICAL_HOST - - -dnl Modification B. Secher portage sur osf CCRT -AC_CHECK_PROG(SHELL,sh,,) -AC_SUBST(SHELL) - -if test -z "$AR"; then - AC_CHECK_PROGS(AR,ar xar,:,$PATH) -fi -AC_SUBST(AR) - -dnl Export the AR macro so that it will be placed in the libtool file -dnl correctly. -export AR - -echo -echo --------------------------------------------- -echo testing make -echo --------------------------------------------- -echo - -AC_PROG_MAKE_SET -AC_PROG_INSTALL -dnl -dnl libtool macro check for CC, LD, NM, LN_S, RANLIB, STRIP + pour les librairies dynamiques ! - -AC_ENABLE_DEBUG(yes) -AC_DISABLE_PRODUCTION - -echo --------------------------------------------- -echo testing libtool -echo --------------------------------------------- - -dnl first, we set static to no! -dnl if we want it, use --enable-static -AC_ENABLE_STATIC(no) - -AC_LIBTOOL_DLOPEN -AC_PROG_LIBTOOL - -dnl Fix up the INSTALL macro if it s a relative path. We want the -dnl full-path to the binary instead. -case "$INSTALL" in - *install-sh*) - case $host_os in - osf*) - INSTALL="${AUX_CONFIG_DIR}/install-sh -c" - ;; - *) - INSTALL="\${AUX_CONFIG_DIR}/install-sh -c" - ;; - esac -esac - -echo -echo --------------------------------------------- -echo testing C/C++ -echo --------------------------------------------- -echo - -cc_ok=no -dnl inutil car libtool -dnl AC_PROG_CC -AC_PROG_CXX -AC_CXX_WARNINGS -AC_CXX_TEMPLATE_OPTIONS -AC_DEPEND_FLAG -# AC_CC_WARNINGS([ansi]) -cc_ok=yes - -dnl Library libdl : -AC_CHECK_LIB(dl,dlopen) - -dnl Library librt : for alpha/osf -AC_CHECK_LIB(rt,nanosleep) - -dnl add library libm : -AC_CHECK_LIB(m,ceil) - -dnl -dnl Check if we use std iostream by default or if we must add -dnl a compiler directive for that -dnl - -AC_CXX_USE_STD_IOSTREAM - -dnl -dnl Well we use sstream which is not in gcc pre-2.95.3 -dnl We must test if it exists. If not, add it in include ! -dnl - -AC_CXX_HAVE_SSTREAM - -dnl -dnl --------------------------------------------- -dnl testing linker -dnl --------------------------------------------- -dnl - -AC_LINKER_OPTIONS - -echo -echo --------------------------------------------- -echo testing threads -echo --------------------------------------------- -echo - -ENABLE_PTHREADS - -echo -echo --------------------------------------------- -echo testing python -echo --------------------------------------------- -echo - -CHECK_PYTHON - -echo -echo --------------------------------------------- -echo testing swig -echo --------------------------------------------- -echo - -CHECK_SWIG - -echo -echo --------------------------------------------- -echo testing HDF5 -echo --------------------------------------------- -echo - -CHECK_HDF5 - -echo -echo --------------------------------------------- -echo testing MED2 -echo --------------------------------------------- -echo - -CHECK_MED2 - -echo -echo --------------------------------------------- -echo "MED_WITH_KERNEL: ${MED_WITH_KERNEL}" -echo --------------------------------------------- - -openpbs_ok=no -echo -echo --------------------------------------------- -echo testing OpenPBS -echo --------------------------------------------- -echo - -CHECK_OPENPBS -dnl openpbs_ok is set to yes by CHECK_OPENPBS - -echo -echo --------------------------------------------- -echo testing LSF -echo --------------------------------------------- -echo - -lsf_ok=no -CHECK_LSF -dnl lsf_ok is set to yes by CHECK_LSF - -if test "${MED_WITH_KERNEL}" = "yes"; then -{ - echo - echo --------------------------------------------- - echo BOOST Library - echo --------------------------------------------- - echo - - CHECK_BOOST - - dnl - dnl --------------------------------------------- - dnl testing WITHIHM - dnl --------------------------------------------- - dnl - - CHECK_WITHIHM - - dnl - dnl --------------------------------------------- - dnl testing sockets - dnl --------------------------------------------- - dnl - - CHECK_SOCKETS - - dnl - dnl --------------------------------------------- - dnl testing Batch - dnl --------------------------------------------- - dnl - - WITH_BATCH=no - test x$openpbs_ok = xyes || test x$lsf_ok = xyes && WITH_BATCH=yes - AC_SUBST(WITH_BATCH) - - if test "X$WITHIHM" = "Xyes"; then - echo - echo --------------------------------------------- - echo testing LEX \& YACC - echo --------------------------------------------- - echo - - lex_yacc_ok=no - AC_PROG_YACC - AC_PROG_LEX - lex_yacc_ok=yes - fi - - dnl - dnl --------------------------------------------- - dnl testing MPI - dnl --------------------------------------------- - dnl - - CHECK_MPI - CHECK_MPICH - - dnl echo - dnl echo --------------------------------------------- - dnl echo testing java - dnl echo --------------------------------------------- - dnl echo - - dnl CHECK_JAVA - - echo - echo --------------------------------------------- - echo testing omniORB - echo --------------------------------------------- - echo - - CHECK_OMNIORB - - echo - echo --------------------------------------------- - echo default ORB : omniORB - echo --------------------------------------------- - echo - - DEFAULT_ORB=omniORB - CHECK_CORBA - - AC_SUBST_FILE(CORBA) - corba=make_$ORB - CORBA=adm_local/unix/$corba - - echo - echo --------------------------------------------- - echo testing openGL - echo --------------------------------------------- - echo - - CHECK_OPENGL - - echo - echo --------------------------------------------- - echo testing QT - echo --------------------------------------------- - echo - - CHECK_QT - - if test "X$WITHIHM" = "Xyes"; then - echo - echo --------------------------------------------- - echo testing VTK - echo --------------------------------------------- - echo - - CHECK_VTK - fi - - echo - echo --------------------------------------------- - echo Testing OpenCascade - echo --------------------------------------------- - echo - - CHECK_CAS - - echo - echo --------------------------------------------- - echo Testing Kernel - echo --------------------------------------------- - echo - - CHECK_KERNEL - - dnl echo - dnl echo --------------------------------------------- - dnl echo testing mico - dnl echo --------------------------------------------- - dnl echo - - dnl CHECK_MICO - - echo - echo --------------------------------------------- - echo testing MSG2QM - echo --------------------------------------------- - echo - - CHECK_MSG2QM - - echo - echo --------------------------------------------- - echo Testing html generators - echo --------------------------------------------- - echo - - CHECK_HTML_GENERATORS - - echo - echo --------------------------------------------- - echo Testing GUI - echo --------------------------------------------- - echo - - CHECK_SALOME_GUI - - echo - echo --------------------------------------------- - echo Testing full GUI - echo --------------------------------------------- - echo - - CHECK_CORBA_IN_GUI - if test "x${CORBA_IN_GUI}" != "xyes"; then - echo "failed : For configure MED module necessary full GUI !" - exit - fi - - echo - echo ---------------------------------------------- - echo testing CPPUNIT only required for unit testing - echo ---------------------------------------------- - echo - - CHECK_CPPUNIT - -} -else -{ - WITHIHM="no" - WITHOPENPBS="no" - - AC_SUBST(WITHIHM) - AC_SUBST(WITHOPENPBS) - CPPFLAGS="$CPPFLAGS -DMED_WITHOUT_KERNEL" -} -fi # MED_WITH_KERNEL - -echo -echo --------------------------------------------- -echo Summary -echo --------------------------------------------- -echo - -if test "$MED_WITH_KERNEL" = "no"; then - echo "Configure (without Kernel)" -else - echo Configure -fi - -#variables="cc_ok lex_yacc_ok python_ok swig_ok threads_ok hdf5_ok med2_ok boost_ok doxygen_ok graphviz_ok OpenGL_ok qt_ok vtk_ok omniORB_ok occ_ok Kernel_ok" - -if test "X$WITHIHM" = "Xyes"; then -variables="cc_ok lex_yacc_ok mpi_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok med2_ok omniORB_ok occ_ok sip_ok pyqt_ok qwt_ok Kernel_ok" -fi -if test "X$WITHIHM" = "Xno"; then -variables="cc_ok mpi_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok hdf5_ok med2_ok omniORB_ok occ_ok Kernel_ok" -fi - -for var in $variables -do - eval toto=\$$var - if test x$toto != "x"; then - printf " %10s : " `echo \$var | sed -e "s,_ok,,"` - eval echo \$$var - fi -done - -if test "${MED_WITH_KERNEL}" = "yes"; then -{ - echo "---Optional:" - variables="cppunit_ok openpbs_ok lsf_ok doxygen_ok graphviz_ok" - - for var in $variables - do - eval toto=\$$var - if test x$toto != "x"; then - printf " %10s : " `echo \$var | sed -e "s,_ok,,"` - eval echo \$$var - fi - done -} -fi - -echo -echo "Default ORB : $DEFAULT_ORB" -echo - -dnl generals files which could be included in every makefile - -AC_SUBST_FILE(COMMENCE) COMMENCE=adm_local/unix/make_commence -AC_SUBST_FILE(CONCLUDE) CONCLUDE=adm_local/unix/make_conclude -AC_SUBST_FILE(MODULE) MODULE=salome_adm/unix/make_module - -dnl les dependences -AC_SUBST_FILE(DEPEND) DEPEND=salome_adm/unix/depend - -dnl We don t need to say when we re entering directories if we re using -dnl GNU make becuase make does it for us. -if test "X$GMAKE" = "Xyes"; then - AC_SUBST(SETX) SETX=":" -else - AC_SUBST(SETX) SETX="set -x" -fi - -# make other build directories -for rep in salome_adm adm_local doc bin/salome include/salome lib${LIB_LOCATION_SUFFIX}/salome share/salome/resources idl -do -# if test ! -d $rep ; then -# eval mkdir $rep -# fi -# $INSTALL -d $rep - mkdir -p $rep -done - -echo -echo --------------------------------------------- -echo copying resource files, shell scripts, and -echo xml files -echo --------------------------------------------- -echo - - -dnl copy resources directories - -#for i in `find $ROOT_SRCDIR -name 'resources' -print` -#do -# local_res=`echo $i | sed -e "s,$ROOT_SRCDIR,.,"` -# local_res_dir=`echo $local_res | sed -e "s,[[^/]]*$,,;s,/$,,;s,^$,.,"` -# mkdir -p $local_res_dir -# cd $local_res_dir -# ln -fs $i -# echo $local_res -# cd $ROOT_BUILDDIR -#done - -dnl copy shells and utilities contained in the bin directory -dnl excluding .in files (treated in AC-OUTPUT below) and CVS -dnl directory - -mkdir -p bin/salome -cd bin/salome - -for i in $ROOT_SRCDIR/bin/* -do - local_bin=`echo $i | sed -e "s,$ROOT_SRCDIR,.,"` - case "$local_bin" in - *.in | *~) ;; - ./bin/CVS | ./bin/salome) ;; - *) ln -fs $i .; echo $local_bin ;; - esac -done -cd $ROOT_BUILDDIR - -if test ${MED_WITH_KERNEL} = "yes"; then -AC_SUBST_FILE(ENVSCRIPT) ENVSCRIPT=salome_adm/unix/envScript -fi - -dnl copy xml files to the build tree (lib directory) -dnl pourquoi ???? - -#cd lib -#for i in `find $ROOT_SRCDIR -name "*.xml" -print` -#do -# ln -fs $i -# echo `echo $i | sed -e "s,$ROOT_SRCDIR,.,"` -#done -#cd $ROOT_BUILDDIR - - -echo -echo --------------------------------------------- -echo generating Makefiles and configure files -echo --------------------------------------------- -echo - -AC_OUTPUT_COMMANDS([ \ - chmod +x ./bin/* \ -]) - -## do not delete this line diff --git a/doc/MEDMEM/HOWTO Create A New Driver.txt b/doc/MEDMEM/HOWTO Create A New Driver.txt deleted file mode 100644 index 660f6266c..000000000 --- a/doc/MEDMEM/HOWTO Create A New Driver.txt +++ /dev/null @@ -1,40 +0,0 @@ -Within MEDMEM_GenDriver.hxx : - /* Modify the following line to add a new driver type (step 1) */ - typedef enum { MED_DRIVER = 0, GIBI_DRIVER = 1, VTK_DRIVER = 254, NO_DRIVER = 255 } driverTypes; - -Note : MED Drivers with no Mesh or Field drivers must have a number of 255-i ! - -Within MEDMEM_Object.hxx - // Add your personnal driver header & line (step 2) - // At least one line must exist - // You have to respect the syntax. - #include "MEDMEM_TypeObjectDriver.hxx" - - friend class MED_OBJECT_RDONLY_DRIVER; - friend class MED_OBJECT_WRONLY_DRIVER; - friend class MED_OBJECT_RDWR_DRIVER; - - // Add a similar line for your personnal driver (step 3) - static INSTANCE_DE inst_med ; - -Within MEDMEM_Object.cxx - // Add a similar line for your personnal driver (step 3) - static INSTANCE_DE inst_med ; - - // Add your own driver in the driver list (step 4) - // Note the list must be coherent with the driver type list defined in MEDMEM_DRIVER.hxx. - const OBJECT::INSTANCE * const OBJECT::instances[] = { &OBJECT::inst_med } ; - -Within MEDMEM_TypeObjectDriver.hxx (ypu can use MEDMEM_TypeObjectDriver.hxx as a pattern for your driver !) - - // Faux : you have to create at least create a TYPE_OBJECT_RDWR_DRIVER even if it only throw an exception - // Faux : because RDONLY or WRONLY doesn't exists. - - Whatever is your driver : RDONLY,WRONLY,RDWR, you must inplement the write & read methods ( even if it only throw an exception) - -TODO : - -Gerer l'appartenance d'un driver type 3 Within l'objet - -Within les mĂ©thodes addDriver : - driver = instances[driverType]->run(fileName, this) ; --> Il faut vĂ©rifier que le numĂ©ro auquel on accède existe ! diff --git a/doc/MEDMEM/HOWTO_Create_A_New_Driver.txt b/doc/MEDMEM/HOWTO_Create_A_New_Driver.txt new file mode 100644 index 000000000..660f6266c --- /dev/null +++ b/doc/MEDMEM/HOWTO_Create_A_New_Driver.txt @@ -0,0 +1,40 @@ +Within MEDMEM_GenDriver.hxx : + /* Modify the following line to add a new driver type (step 1) */ + typedef enum { MED_DRIVER = 0, GIBI_DRIVER = 1, VTK_DRIVER = 254, NO_DRIVER = 255 } driverTypes; + +Note : MED Drivers with no Mesh or Field drivers must have a number of 255-i ! + +Within MEDMEM_Object.hxx + // Add your personnal driver header & line (step 2) + // At least one line must exist + // You have to respect the syntax. + #include "MEDMEM_TypeObjectDriver.hxx" + + friend class MED_OBJECT_RDONLY_DRIVER; + friend class MED_OBJECT_WRONLY_DRIVER; + friend class MED_OBJECT_RDWR_DRIVER; + + // Add a similar line for your personnal driver (step 3) + static INSTANCE_DE inst_med ; + +Within MEDMEM_Object.cxx + // Add a similar line for your personnal driver (step 3) + static INSTANCE_DE inst_med ; + + // Add your own driver in the driver list (step 4) + // Note the list must be coherent with the driver type list defined in MEDMEM_DRIVER.hxx. + const OBJECT::INSTANCE * const OBJECT::instances[] = { &OBJECT::inst_med } ; + +Within MEDMEM_TypeObjectDriver.hxx (ypu can use MEDMEM_TypeObjectDriver.hxx as a pattern for your driver !) + + // Faux : you have to create at least create a TYPE_OBJECT_RDWR_DRIVER even if it only throw an exception + // Faux : because RDONLY or WRONLY doesn't exists. + + Whatever is your driver : RDONLY,WRONLY,RDWR, you must inplement the write & read methods ( even if it only throw an exception) + +TODO : + +Gerer l'appartenance d'un driver type 3 Within l'objet + +Within les mĂ©thodes addDriver : + driver = instances[driverType]->run(fileName, this) ; --> Il faut vĂ©rifier que le numĂ©ro auquel on accède existe ! diff --git a/doc/MEDMEM/Makefile.am b/doc/MEDMEM/Makefile.am new file mode 100644 index 000000000..daf99a22e --- /dev/null +++ b/doc/MEDMEM/Makefile.am @@ -0,0 +1,43 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +EXTRA_DIST += \ + FIELDcreate.cxx \ + FIELDcreate.py \ + FIELDgeneral.cxx \ + FIELDgeneral.py \ + HOWTO_Create_A_New_Driver.txt \ + MEDMEM_InvokingDriverAtObjectCreationTime.cxx \ + MEDMEM_InvokingDriverAtObjectCreationTime.py \ + MEDMEM_InvokingDriverByAttachingItToAnObject.cxx \ + MEDMEM_InvokingDriverByAttachingItToAnObject.py \ + MEDMEM_InvokingDriverFromStandardObjectMethod.cxx \ + MEDMEM_InvokingDriverFromStandardObjectMethod.py \ + MEDMEM_MedAddingAnExistingObject.cxx \ + MEDMEM_UsersGuide.lyx \ + MESHconnectivities.cxx \ + MESHconnectivities.py \ + MESHcoordinates.cxx \ + MESHcoordinates.py \ + MESHgeneral.cxx \ + MESHgeneral.py \ + MESHINGexample.cxx \ + MESHINGexample.py \ + TODO_Drivers.txt diff --git a/doc/MEDMEM/Makefile.in b/doc/MEDMEM/Makefile.in deleted file mode 100644 index ed7de656f..000000000 --- a/doc/MEDMEM/Makefile.in +++ /dev/null @@ -1,175 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -* Makefile *- -# -# Author : Nadir BOUHAMOU (CEA) -# - -# source path -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ -doxygen=@DOXYGEN@ - -@COMMENCE@ - -# Executables targets -BIN = MESHgeneral MESHcoordinates MESHconnectivities MESHINGexample FIELDcreate FIELDgeneral MEDMEM_InvokingDriverByAttachingItToAnObject MEDMEM_InvokingDriverFromStandardObjectMethod MEDMEM_InvokingDriverAtObjectCreationTime - -LDFLAGS+= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN+= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS+=$(MED2_INCLUDES) $(HDF5_INCLUDES) - -CXXFLAGS+=@CXXTMPDPTHFLAGS@ -#LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -# change motivated by the bug KERNEL4778. -LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lmedmem -lmed_V2_1 $(STDLIB) - -#LDFLAGSFORBIN+=$(MED2_LIBS) $(HDF5_LIBS) -# change motivated by the bug KERNEL4778. -LDFLAGSFORBIN+=-lm $(MED2_LIBS) $(HDF5_LIBS) -lmedmem -lmed_V2_1 - -ifeq ($(MED_WITH_KERNEL),yes) - CPPFLAGS+= ${KERNEL_CXXFLAGS} - CXXFLAGS+= ${KERNEL_CXXFLAGS} - LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace - LDFLAGSFORBIN+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace -lSALOMEBasics -endif - -LIBSFORBIN= - -LIBS= - -@CONCLUDE@ - -doc: .doxygen_user .doxygen_devel ps - -ps: .doxygen_user .doxygen_devel MedMemory_user.ps MedMemory_devel.ps MEDMEM_UsersGuide.ps - -ps_2on1: .doxygen_user .doxygen_devel MedMemory_user_2on1.ps MedMemory_devel_2on1.ps MEDMEM_UsersGuide_2on1.ps - -pdf: .doxygen_user .doxygen_devel MedMemory_user.pdf MedMemory_devel.pdf MEDMEM_UsersGuide.pdf - -pdf_2on1: .doxygen_user .doxygen_devel MedMemory_user_2on1.pdf MedMemory_devel_2on1.pdf MEDMEM_UsersGuide_2on1.pdf - -# user doc : - -.doxygen_user: $(top_srcdir)/src/MEDMEM/Doxyfile_med_user.in - cd $(top_builddir) ; ./config.status - cd $(top_builddir)/src/MEDMEM && $(doxygen) Doxyfile_med_user - touch $@ - $(RM) -r doc_ref_user - ln -s $(top_builddir)/src/MEDMEM/doc_ref_user doc_ref_user - -MedMemory_user.ps: - cd ./doc_ref_user/latex && $(MAKE) ps - cp -f ./doc_ref_user/latex/refman.ps $@ - -MedMemory_user_2on1.ps: - cd ./doc_ref_user/latex && $(MAKE) ps_2on1 - cp -f ./doc_ref_user/latex/refman_2on1.ps $@ - -MedMemory_user.pdf: - cd ./doc_ref_user/latex && $(MAKE) pdf - cp -f ./doc_ref_user/latex/refman.pdf $@ - -MedMemory_user_2on1.pdf: - cd ./doc_ref_user/latex && $(MAKE) pdf_2on1 - cp -f ./doc_ref_user/latex/refman_2on1.pdf $@ - -# developper doc - -.doxygen_devel: $(top_srcdir)/src/MEDMEM/Doxyfile_med_devel.in - cd $(top_builddir) ; ./config.status - cd $(top_builddir)/src/MEDMEM && $(doxygen) Doxyfile_med_devel - touch $@ - $(RM) -r doc_ref_devel - ln -s $(top_builddir)/src/MEDMEM/doc_ref_devel doc_ref_devel - -MedMemory_devel.ps: - cd ./doc_ref_devel/latex && $(MAKE) ps - cp -f ./doc_ref_devel/latex/refman.ps $@ - -MedMemory_devel_2on1.ps: - cd ./doc_ref_devel/latex && $(MAKE) ps_2on1 - cp -f ./doc_ref_devel/latex/refman_2on1.ps $@ - -MedMemory_devel.pdf: - cd ./doc_ref_devel/latex && $(MAKE) pdf - cp -f ./doc_ref_devel/latex/refman.pdf $@ - -MedMemory_devel_2on1.pdf: - cd ./doc_ref_devel/latex && $(MAKE) pdf_2on1 - cp -f ./doc_ref_devel/latex/refman_2on1.pdf $@ - -# User Guide - -MEDMEM_UsersGuide.ps: MEDMEM_UsersGuide.pdf - pdf2ps MEDMEM_UsersGuide.pdf MEDMEM_UsersGuide.ps - -MEDMEM_UsersGuide_2on1.ps: MEDMEM_UsersGuide.ps - psnup -2 MEDMEM_UsersGuide.ps >MEDMEM_UsersGuide_2on1.ps - -MEDMEM_UsersGuide_2on1.pdf: MEDMEM_UsersGuide_2on1.ps - ps2pdf MEDMEM_UsersGuide_2on1.ps MEDMEM_UsersGuide_2on1.pdf - -MEDMEM_UsersGuide.pdf: MEDMEM_UsersGuide.tex MEDMEM_Content.tex MEDMEM_UML_light.png MEDMEM_UML.png FIELDcreate.cxx FIELDgeneral.cxx MEDMEM_InvokingDriverAtObjectCreationTime.cxx MEDMEM_InvokingDriverByAttachingItToAnObject.cxx MEDMEM_InvokingDriverFromStandardObjectMethod.cxx MEDMEM_MedAddingAnExistingObject.cxx MESHconnectivities.cxx MESHcoordinates.cxx MESHgeneral.cxx MESHINGexample.cxx FIELDcreate.py FIELDgeneral.py MEDMEM_InvokingDriverAtObjectCreationTime.py MEDMEM_InvokingDriverByAttachingItToAnObject.py MEDMEM_InvokingDriverFromStandardObjectMethod.py MESHconnectivities.py MESHcoordinates.py MESHgeneral.py MESHINGexample.py - echo "Running pdflatex..." - pdflatex $< - #echo "Running makeindex..." - #makeindex MEDMEM_UsersGuide.idx - echo "Rerunning latex...." - pdflatex $< - latex_count=5 - while egrep -s 'Rerun (LaTeX|to get cross-references right)' MEDMEM_UsersGuide.log && [ $latex_count -gt 0 ] ;\ - do \ - echo "Rerunning latex...." ;\ - latex $< ;\ - latex_count=`expr $latex_count - 1` ;\ - done - -MEDMEM_UsersGuide.tex:MEDMEM_UsersGuide.tex.in - cd $(top_builddir) && CONFIG_FILES=./doc/MEDMEM/MEDMEM_UsersGuide.tex ./config.status - -MEDMEM_Content.tex:MEDMEM_Content.tex.in - cd $(top_builddir) && CONFIG_FILES=./doc/MEDMEM/MEDMEM_Content.tex ./config.status - -MEDMEM_UML_light.png:MEDMEM_UML_light.png.in - cd $(top_builddir) && CONFIG_FILES=./doc/MEDMEM/MEDMEM_UML_light.png ./config.status - -MEDMEM_UML.png:MEDMEM_UML.png.in - cd $(top_builddir) && CONFIG_FILES=./doc/MEDMEM/MEDMEM_UML.png ./config.status - -# install procedure - -install: $(datadir)/doc ps_2on1 pdf_2on1 - $(RM) -r $(datadir)/doc/html_ref_user $(datadir)/doc/html_ref_devel $(datadir)/doc/*.ps $(datadir)/doc/*.pdf - cp -rf ./doc_ref_user/html $(datadir)/doc/html_ref_user - cp -rf ./doc_ref_devel/html $(datadir)/doc/html_ref_devel - cp -f MedMemory_user_2on1.ps MedMemory_user_2on1.pdf $(datadir)/doc - cp -f MEDMEM_UsersGuide_2on1.ps MEDMEM_UsersGuide_2on1.pdf $(datadir)/doc - cp -f MedMemory_devel_2on1.ps MedMemory_devel_2on1.pdf $(datadir)/doc - -$(datadir)/doc: - $(INSTALL) -d $@ && chmod 755 $@ - -cleandoc: - -$(RM) -r *pdf *ps doc_ref_* $(top_builddir)/src/MEDMEM/doc_ref_* .dep* diff --git a/doc/MEDMEM/TODO Drivers.txt b/doc/MEDMEM/TODO Drivers.txt deleted file mode 100644 index d6cd93c78..000000000 --- a/doc/MEDMEM/TODO Drivers.txt +++ /dev/null @@ -1,4 +0,0 @@ -1- Gerer l'appartenance d'un driver type 3 Within l'objet - -2- Within les mĂ©thodes addDriver : - driver = instances[driverType]->run(fileName, this) ; --> Il faut vĂ©rifier que le numĂ©ro auquel on accède existe ! diff --git a/doc/MEDMEM/TODO_Drivers.txt b/doc/MEDMEM/TODO_Drivers.txt new file mode 100644 index 000000000..d6cd93c78 --- /dev/null +++ b/doc/MEDMEM/TODO_Drivers.txt @@ -0,0 +1,4 @@ +1- Gerer l'appartenance d'un driver type 3 Within l'objet + +2- Within les mĂ©thodes addDriver : + driver = instances[driverType]->run(fileName, this) ; --> Il faut vĂ©rifier que le numĂ©ro auquel on accède existe ! diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 000000000..735b5fa53 --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,22 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SUBDIRS= MEDMEM salome + +EXTRA_DIST= html diff --git a/doc/Makefile.in b/doc/Makefile.in deleted file mode 100644 index c54fc262b..000000000 --- a/doc/Makefile.in +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -# -* Makefile *- -# -# Author : Patrick GOLDBRONN (CEA) -# Date : 30/11/2001 -# $Header$ -# -# source path -top_srcdir=@top_srcdir@ -top_builddir=.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ - -SUBDIRS= salome - -@COMMENCE@ - -dev_docs: - @@SETX@; for d in $(SUBDIRS); do \ - (cd $$d && $(MAKE) $@) || exit 1; \ - done -clean: - @@SETX@; for d in $(SUBDIRS); do \ - (cd $$d && $(MAKE) $@) || exit 1; \ - done - -distclean: clean - @@SETX@; for d in $(SUBDIRS); do \ - (cd $$d && $(MAKE) $@) || exit 1; \ - done - -install: - @@SETX@; for d in $(SUBDIRS); do \ - (cd $$d && $(MAKE) $@) || exit 1; \ - done - -uninstall: - @@SETX@; for d in $(SUBDIRS); do \ - (cd $$d && $(MAKE) $@) || exit 1; \ - done diff --git a/doc/html/INPUT/sources/doxygen.css b/doc/html/INPUT/sources/doxygen.css index 6e2c772fe..acda4606c 100755 --- a/doc/html/INPUT/sources/doxygen.css +++ b/doc/html/INPUT/sources/doxygen.css @@ -15,7 +15,8 @@ TD.mdname1 { background-color: lightblue; font-weight: bold; color: #602020; } TD.mdname { background-color: lightblue; font-weight: bold; color: #602020; width: 600px; } DIV.groupHeader { margin-left: 16px; margin-top: 12px; margin-bottom: 6px; font-weight: bold } DIV.groupText { margin-left: 16px; font-style: italic; font-size: smaller } -BODY { background: url(sources/bg_salomepro.gif) } +BODY { background: #FFFFFF; } +/* BODY { background: url(sources/bg_salomepro.gif) } */ TD.indexkey { background-color: #CCCCCC; font-weight: bold; diff --git a/doc/html/INPUT/sources/static/doxygen.css b/doc/html/INPUT/sources/static/doxygen.css index 0a8e93d50..056702051 100755 --- a/doc/html/INPUT/sources/static/doxygen.css +++ b/doc/html/INPUT/sources/static/doxygen.css @@ -15,7 +15,8 @@ TD.mdname1 { background-color: lightblue; font-weight: bold; color: #602020; } TD.mdname { background-color: lightblue; font-weight: bold; color: #602020; width: 600px; } DIV.groupHeader { margin-left: 16px; margin-top: 12px; margin-bottom: 6px; font-weight: bold } DIV.groupText { margin-left: 16px; font-style: italic; font-size: smaller } -BODY { background: url(sources/bg_salome.gif) } +BODY { background: #FFFFFF; } +/* BODY { background: url(sources/bg_salome.gif) } */ TD.indexkey { background-color: #CCCCCC; font-weight: bold; diff --git a/doc/html/Makefile.in b/doc/html/Makefile.in deleted file mode 100644 index 36943e852..000000000 --- a/doc/html/Makefile.in +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -* Makefile *- -# -# Author : Vasily Rusyaev (Open Cascade NN) -# Date : 13/02/2003 -# $Header: -# -# source path -top_srcdir=@top_srcdir@ -root_srcdir=@ROOT_SRCDIR@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ -doxygen=@DOXYGEN@ - -@COMMENCE@ - -doc: - cp -fr $(srcdir)/INPUT ./; \ - cd INPUT; \ - sed 's|../../../share/salome|$(root_srcdir)|' doxyfile > doxyfile1; \ - mv -f doxyfile1 doxyfile; \ - $(doxygen) ./doxyfile; \ - cd ..; \ - cp -fr $(srcdir)/INPUT/sources/static/*.* ./html/ - cp -fr $(srcdir)/INPUT/sources/ html/ - cp -fr $(srcdir)/INPUT/HTML/ html/ - -clean: - rm -rf html - -distclean: clean - rm -rf INPUT - -install: - $(INSTALL) -d $(docdir); \ - cp -rf html $(docdir) - -uninstall: - rm -rf $(docdir)/html diff --git a/doc/salome/Makefile.am b/doc/salome/Makefile.am new file mode 100644 index 000000000..1bfebe55b --- /dev/null +++ b/doc/salome/Makefile.am @@ -0,0 +1,32 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# -* Makefile *- +# +# Author : Patrick GOLDBRONN (CEA) +# Date : 30/11/2001 +# $Header$ +# + +SUBDIRSTUI= tui + +dev_docs: + @@SETX@; for d in $(SUBDIRSTUI); do \ + (cd $$d && $(MAKE) $@) || exit 1; \ + done; diff --git a/doc/salome/Makefile.in b/doc/salome/Makefile.in deleted file mode 100644 index c88e71139..000000000 --- a/doc/salome/Makefile.in +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -# -* Makefile *- -# -# Author : Patrick GOLDBRONN (CEA) -# Date : 30/11/2001 -# $Header$ -# -# source path -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ - -SUBDIRS= tui - -@COMMENCE@ - -dev_docs: - @@SETX@; for d in $(SUBDIRS); do \ - (cd $$d && $(MAKE) $@) || exit 1; \ - done; \ - -clean: - @@SETX@; for d in $(SUBDIRS); do \ - if test -d $$d/MED; then \ - (cd $$d && $(MAKE) $@) || exit 1; \ - fi; \ - done - -distclean: clean - @@SETX@; for d in $(SUBDIRS); do \ - if test -d $$d/MED; then \ - (cd $$d && $(MAKE) $@) || exit 1; \ - fi; \ - done - -install: - @@SETX@; for d in $(SUBDIRS); do \ - if test -d $$d/MED; then \ - (cd $$d && $(MAKE) $@); \ - fi; \ - done - -uninstall: - @@SETX@; for d in $(SUBDIRS); do \ - if test -d $$d/MED; then \ - (cd $$d && $(MAKE) $@) || exit 1; \ - fi; \ - done; \ diff --git a/doc/salome/tui/MED/Makefile.am b/doc/salome/tui/MED/Makefile.am new file mode 100644 index 000000000..e0b08cffa --- /dev/null +++ b/doc/salome/tui/MED/Makefile.am @@ -0,0 +1,15 @@ +# Copyright (C) 2003 CEA/DEN, EDF R&D +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = sources +EXTRA_DIST += HTML + +#doctuidir= $(docdir)/tui/MED +#nodist_doctui_DATA= doxyfile + +#doctuistaticdir= $(docdir)/tui/MED/sources/static +#nodist_doctuistatic_DATA= MED/sources/static/tree.js diff --git a/doc/salome/tui/MED/sources/Application-About.png b/doc/salome/tui/MED/sources/Application-About.png index 7b58330d5..df0d5a187 100755 Binary files a/doc/salome/tui/MED/sources/Application-About.png and b/doc/salome/tui/MED/sources/Application-About.png differ diff --git a/doc/salome/tui/MED/sources/Makefile.am b/doc/salome/tui/MED/sources/Makefile.am new file mode 100644 index 000000000..db3b477a8 --- /dev/null +++ b/doc/salome/tui/MED/sources/Makefile.am @@ -0,0 +1,24 @@ +# Copyright (C) 2003 CEA/DEN, EDF R&D +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = static +EXTRA_DIST += \ + Application-About1.jpg \ + Application-About.png \ + application.gif \ + application.jpg \ + bg_salome.gif \ + footer.html \ + logocorp.gif \ + myheader.html \ + occ.gif + +#doctuidir= $(docdir)/tui/MED +#nodist_doctui_DATA= doxyfile + +#doctuistaticdir= $(docdir)/tui/MED/sources/static +#nodist_doctuistatic_DATA= MED/sources/static/tree.js diff --git a/doc/salome/tui/MED/sources/static/Makefile.am b/doc/salome/tui/MED/sources/static/Makefile.am new file mode 100644 index 000000000..42b89594a --- /dev/null +++ b/doc/salome/tui/MED/sources/static/Makefile.am @@ -0,0 +1,17 @@ +# Copyright (C) 2003 CEA/DEN, EDF R&D +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +EXTRA_DIST += \ + doxygen.css \ + page2.html \ + treeview.js + +#doctuidir= $(docdir)/tui/MED +#nodist_doctui_DATA= doxyfile + +#doctuistaticdir= $(docdir)/tui/MED/sources/static +#nodist_doctuistatic_DATA= MED/sources/static/tree.js diff --git a/doc/salome/tui/Makefile.am b/doc/salome/tui/Makefile.am new file mode 100644 index 000000000..e1cf0f083 --- /dev/null +++ b/doc/salome/tui/Makefile.am @@ -0,0 +1,40 @@ +# Copyright (C) 2003 CEA/DEN, EDF R&D +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = MED +#EXTRA_DIST+= MED + +dev_docs: + cp -fr $(srcdir)/MED ./INPUT; \ + cp -fr ./MED/doxyfile ./INPUT; \ + cp -fr ./MED/sources/static/tree.js ./INPUT/sources/static; \ + cd INPUT; \ + sed 's|../../../share/salome|$(top_srcdir)|' ./doxyfile > ./doxyfile1; \ + sed 's|../../build/salome|$(top_builddir)|' ./doxyfile1 > ./doxyfile2; \ + mv -f doxyfile2 doxyfile1; \ + echo "DOXYGEN SUPPORT PYTHON - @DOXYGEN_WITH_PYTHON@"; \ + if( test "x@DOXYGEN_WITH_PYTHON@" = "xyes"); then \ + sed 's|python_extension_must_be_here|*.py|' ./doxyfile1 > ./doxyfile2; \ + mv -f doxyfile2 doxyfile1; \ + $(DOXYGEN) -u ./doxyfile1; \ + else \ + sed 's|python_extension_must_be_here||' ./doxyfile1 > ./doxyfile2; \ + mv -f doxyfile2 doxyfile1; \ + fi; \ + mv -f doxyfile1 doxyfile; \ + $(DOXYGEN) ./doxyfile; \ + cd ..; \ + cp -fr $(srcdir)/MED/sources/static/*.* ./MED/ + cp -fr $(srcdir)/MED/sources/ MED/ + cp -fr $(srcdir)/MED/HTML/ MED/ + rm -fr INPUT + +#doctuidir= $(docdir)/tui/MED +#nodist_doctui_DATA= MED/doxyfile + +#doctuistaticdir= $(docdir)/tui/MED/sources/static +#nodist_doctuistatic_DATA= MED/sources/static/tree.js diff --git a/doc/salome/tui/Makefile.in b/doc/salome/tui/Makefile.in deleted file mode 100644 index 8c85f6e65..000000000 --- a/doc/salome/tui/Makefile.in +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2003 CEA/DEN, EDF R&D -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# File : Makefile.in -# Author : Vasily Rusyaev (Open Cascade NN) -# Module : doc -# $Header: - -top_srcdir=@top_srcdir@ -top_builddir=../../.. -root_srcdir=@ROOT_SRCDIR@ -srcdir=@srcdir@ -VPATH=.:@srcdir@ -doxygen=@DOXYGEN@ - -@COMMENCE@ - -dev_docs: - cp -fr $(srcdir)/MED ./INPUT; \ - cp -fr ./MED/doxyfile ./INPUT; \ - cp -fr ./MED/sources/static/tree.js ./INPUT/sources/static; \ - cd INPUT; \ - sed 's|../../../share/salome|$(root_srcdir)|' ./doxyfile > ./doxyfile1; \ - sed 's|../../build/salome|$(top_builddir)|' ./doxyfile1 > ./doxyfile2; \ - mv -f doxyfile2 doxyfile1; \ - echo "DOXYGEN SUPPORT PYTHON - @DOXYGEN_WITH_PYTHON@"; \ - if( test "x@DOXYGEN_WITH_PYTHON@" = "xyes"); then \ - sed 's|python_extension_must_be_here|*.py|' ./doxyfile1 > ./doxyfile2; \ - mv -f doxyfile2 doxyfile1; \ - $(doxygen) -u ./doxyfile1; \ - else \ - sed 's|python_extension_must_be_here||' ./doxyfile1 > ./doxyfile2; \ - mv -f doxyfile2 doxyfile1; \ - fi; \ - mv -f doxyfile1 doxyfile; \ - $(doxygen) ./doxyfile; \ - cd ..; \ - cp -fr $(srcdir)/MED/sources/static/*.* ./MED/ - cp -fr $(srcdir)/MED/sources/ MED/ - cp -fr $(srcdir)/MED/HTML/ MED/ - rm -fr INPUT - -clean: - rm -fr MED - -distclean: clean - rm -fr INPUT - -install: - $(INSTALL) -d $(docdir); \ - mkdir -p $(docdir)/tui - cp -fr MED $(docdir)/tui - -uninstall: - rm -fr $(docdir)/tui/MED diff --git a/idl/MED.idl b/idl/MED.idl index eca82a04e..60b8dac41 100644 --- a/idl/MED.idl +++ b/idl/MED.idl @@ -118,6 +118,7 @@ For example an array of coordinates in 3D; tow storage may be considered: typedef long medModeSwitch; const medModeSwitch MED_FULL_INTERLACE = 0; const medModeSwitch MED_NO_INTERLACE = 1; + const medModeSwitch MED_NO_INTERLACE_BY_TYPE = 2; /*! This enumeration contains a set of elements defining the type of connectivity. @@ -425,8 +426,9 @@ This enumeration contains a set of elements defining the type of connectivity. { long numberOfNodes; medGeometryElement_array meshTypes; - SALOME_MED::long_array numberOfElements; - long entityDimension; + SALOME_MED::long_array numberOfElements; + SALOME_MED::long_array nodalConnectivityLength; + long entityDimension; }; connectivityInfos getConnectGlobal(in medEntityMesh entity) raises (SALOME::SALOME_Exception); @@ -650,6 +652,20 @@ Internal Corba method. SALOME_MED::long_array getNumber(in medGeometryElement geomElement) raises (SALOME::SALOME_Exception); + /*! + If the method %isOnAllElements() returns False, this method returns an array which + contains all numbers of given %medGeometryElement. + + Numbering is from file, ie numbers are bounded by 1 and + MESH::getNumberOfElement(entity,MED_ALL_ELEMENTS) and not by 1 and + MESH::getNumberOfElement(entity,geomElement). + + \note + If %SUPPORT is defined on MED_NODE, use MED_NONE %medGeometryElement type. + */ + SALOME_MED::long_array getNumberFromFile(in medGeometryElement geomElement) + raises (SALOME::SALOME_Exception); + /*! Idem SALOME::Sender getNumber(in medGeometryElement geomElement) but returning Sender.\n It could be used in a Client code using the MED Client classes. @@ -691,7 +707,8 @@ Internal Corba method. medEntityMesh entity; long numberOfGeometricType; medGeometryElement_array types; - SALOME_MED::long_array nbEltTypes; + SALOME_MED::long_array nbEltTypes; + SALOME_MED::long_array nodalConnectivityLength; }; supportInfos getSupportGlobal() raises (SALOME::SALOME_Exception); @@ -826,10 +843,17 @@ Internal Corba method. { /*! - Returns the field name. - */ + * Returns the field name. + */ string getName() raises (SALOME::SALOME_Exception); + /*! + * Changes the field name. + * + * \param theName The new name for this field. + */ + void setName (in string theName) raises (SALOME::SALOME_Exception); + /*! Returns the field description. */ @@ -868,11 +892,10 @@ Internal Corba method. raises (SALOME::SALOME_Exception); /*! - Returns the unit of i-th component. - - \note - i is bounded by 1 and NumberOfComponents. - */ + * Returns the unit of i-th component. + * + * \note i is bounded by 1 and NumberOfComponents. + */ string getComponentUnit(in long i) raises (SALOME::SALOME_Exception); /*! @@ -936,7 +959,9 @@ Internal Corba method. /*! Adds the Field in the StudyManager. */ - void addInStudy(in SALOMEDS::Study myStudy, in FIELD myIor ) + void addInStudy(in SALOMEDS::Study myStudy, in FIELD myIor) + raises (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + void addInStudyToComponent(in SALOMEDS::SComponent myComponent, in FIELD myIor) raises (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); /*! @@ -967,6 +992,9 @@ Internal Corba method. interface FIELDDOUBLENO : FIELDDOUBLE { }; + interface FIELDDOUBLENOBYTYPE : FIELDDOUBLE { + }; + interface FIELDDOUBLEFULL : FIELDDOUBLE { }; @@ -989,6 +1017,9 @@ Internal Corba method. interface FIELDINTNO : FIELDINT { }; + interface FIELDINTNOBYTYPE : FIELDINT { + }; + interface FIELDINTFULL : FIELDINT { }; diff --git a/idl/MED_Gen.idl b/idl/MED_Gen.idl index fd335d6e0..8b5b13a87 100644 --- a/idl/MED_Gen.idl +++ b/idl/MED_Gen.idl @@ -33,7 +33,11 @@ module SALOME_MED { - interface MED_Gen : Engines::Component, SALOMEDS::Driver + interface MED_Gen_Driver : SALOMEDS::Driver + { + }; + + interface MED_Gen : Engines::Component, MED_Gen_Driver { /*! it returns a Corba pointer %MESH on the mesh stored in the .med file @@ -72,7 +76,6 @@ module SALOME_MED in string studyName) raises (SALOME::SALOME_Exception); }; - }; #endif diff --git a/idl/Makefile.am b/idl/Makefile.am new file mode 100644 index 000000000..44eea992d --- /dev/null +++ b/idl/Makefile.am @@ -0,0 +1,97 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# +# This Makefile is responsible of generating the client and server +# implementation of IDL interfaces for both C++ and python usage. +# The building process of the C++ files is in charge of each source +# package and then is not manage here. +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +BASEIDL_FILES= MED.idl MED_Gen.idl Compo1Py.idl + +EXTRA_DIST+= $(BASEIDL_FILES) + +# This variable defines the files to be installed +salomeidl_DATA = $(BASEIDL_FILES) + +# GUI idl common library +lib_LTLIBRARIES = libSalomeIDLMED.la + +# Sources built from idl files +nodist_libSalomeIDLMED_la_SOURCES= MEDSK.cc MED_GenSK.cc Compo1PySK.cc + +# header files must be exported: other modules have to use this library +nodist_salomeinclude_HEADERS= $(BASEIDL_FILES:%.idl=%.hh) + +libSalomeIDLMED_la_CPPFLAGS =\ + -I$(top_builddir)/salome_adm/unix \ + -I$(top_builddir)/idl \ + @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ @KERNEL_CXXFLAGS@ +libSalomeIDLMED_la_LDFLAGS = -no-undefined -version-info=0:0:0 +libSalomeIDLMED_la_LIBADD = \ + @CORBA_LIBS@ \ + $(KERNEL_LDFLAGS) -lSalomeIDLKernel + +# These variables defines the building process of CORBA files +OMNIORB_IDL = @OMNIORB_IDL@ +OMNIORB_IDLCXXFLAGS = @OMNIORB_IDLCXXFLAGS@ +OMNIORB_IDLPYFLAGS = @OMNIORB_IDLPYFLAGS@ -I$(top_builddir)/idl/salome -I$(KERNEL_ROOT_DIR)/idl/salome +IDLCXXFLAGS = -bcxx @IDLCXXFLAGS@ -I$(top_builddir)/idl/salome -I$(KERNEL_ROOT_DIR)/idl/salome -I$(top_builddir)/salome_adm/unix +IDLPYFLAGS = @IDLPYFLAGS@ -I$(KERNEL_ROOT_DIR)/idl/salome + +# potential problem on parallel make on the following - multiple outputs +SUFFIXES = .idl .hh SK.cc +.idlSK.cc: + $(OMNIORB_IDL) $(IDLCXXFLAGS) $(OMNIORB_IDLCXXFLAGS) $< +.idl.hh: + $(OMNIORB_IDL) $(IDLCXXFLAGS) $(OMNIORB_IDLCXXFLAGS) $< + +install-exec-local: $(BASEIDL_FILES:%=$(top_srcdir)/idl/%) + $(INSTALL) -d $(pkgpythondir) + ls $^ | while read file; do \ + $(OMNIORB_IDL) $(IDLPYFLAGS) -C$(pkgpythondir) $$file ; \ + done + +# uninstall-local removes too much, but it works in distcheck +uninstall-local: + rm -rf $(pkgpythondir)/* + +mostlyclean-local: clean-idls + +clean-idls: + -rm -f *.hh *.cc .depidl + +# we use cpp to generate dependencies between idl files. +# option x c tells the preprocessor to consider idl as a c file. +# if an idl is modified, all idl dependencies are rebuilt + +.depidl: $(BASEIDL_FILES) + @echo "" > $@ + @for dep in $^ dummy; do \ + if [ $$dep != "dummy" ]; then \ + echo Building dependencies for $$dep; \ + $(CPP) $(C_DEPEND_FLAG) -x c -I$(srcdir) -I$(KERNEL_ROOT_DIR)/idl/salome $$dep 2>/dev/null | \ + sed 's/\.o/\SK.cc/' >>$@; \ + fi; \ + done ; + +-include .depidl diff --git a/idl/Makefile.in b/idl/Makefile.in deleted file mode 100644 index 99aa659f3..000000000 --- a/idl/Makefile.in +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# generate dependencies for idl file : -# - -# source path -top_srcdir=@top_srcdir@ -top_builddir=.. -srcdir=@srcdir@ -VPATH=.:${KERNEL_ROOT_DIR}/idl/salome - -@COMMENCE@ - -IDL_FILES = \ - MED.idl \ - MED_Gen.idl \ - Compo1Py.idl - -PY_CLIENT_IDL = $(IDL_FILES) - -# we copy all idl file in $(top_builddir)/idl -inc: $(top_builddir)/idl/salome $(IDL_FILES:%=$(top_builddir)/idl/salome/%) - -$(top_builddir)/idl/salome: - mkdir $@ - -$(IDL_FILES:%=$(top_builddir)/idl/salome/%):$(IDL_FILES:%=$(top_srcdir)/idl/%) -# $(CP) $< $@ - cp -f $^ $(top_builddir)/idl/salome - - -lib: pyidl - -PYTHON_BUILD_SITE=$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/python$(PYTHON_VERSION)/site-packages/@PACKAGE@ - -pyidl: $(PYTHON_BUILD_SITE) $(IDL_FILES:%.idl=$(PYTHON_BUILD_SITE)/%_idl.py) - -$(PYTHON_BUILD_SITE): - $(INSTALL) -d $@ - -$(PYTHON_BUILD_SITE)/%_idl.py: $(top_builddir)/idl/salome/%.idl - $(OMNIORB_IDL) $(OMNIORB_IDLPYFLAGS) -C$(PYTHON_BUILD_SITE) $< - - -# install python client (generated from idl file -install: install-pyidl install-idl - -# create directory $(idldir) and copy idl files into it -install-idl: $(IDL_FILES:%=$(top_builddir)/idl/salome/%) - $(INSTALL) -d $(idldir) - $(INSTALL_DATA) $^ $(idldir) - - -install-pyidl: $(IDL_FILES:%=$(top_builddir)/idl/salome/%) - $(INSTALL) -d $(PYTHON_SITE_INSTALL) - @for file in $^ dummy; do \ - if [ $$file != "dummy" ]; then \ - $(OMNIORB_IDL) $(OMNIORB_IDLPYFLAGS) -C$(PYTHON_SITE_INSTALL) $$file ; \ - fi ; \ - done ; - -#@ CONCLUDE @ - -cleandep: - -$(RM) .dep* - -distclean: - -$(RM) *.py - -$(RM) $(IDL_FILES:%=$(top_builddir)/idl/salome/%) - -$(RM) Makefile - diff --git a/resources/MEDCatalog.xml.in b/resources/MEDCatalog.xml.in index 136c99ee7..14cc93a22 100644 --- a/resources/MEDCatalog.xml.in +++ b/resources/MEDCatalog.xml.in @@ -8,6 +8,15 @@ + + + + + + FIELD + + + diff --git a/resources/Makefile.am b/resources/Makefile.am new file mode 100644 index 000000000..1ae9cd770 --- /dev/null +++ b/resources/Makefile.am @@ -0,0 +1,164 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# +# =============================================================== +# Files to be installed +# =============================================================== +# + +dist_salomeres_DATA=\ + boitenew.cnc \ + boitenew.inp \ + boitenew.xyz \ + carre_en_quad4_import22.med \ + carre_en_quad4.med \ + carre_en_quad4_seg2_import22.med \ + carre_en_quad4_seg2.med \ + cas_defaut_domaine_fluide.med \ + Case1.cnc \ + Case1.inp \ + Case1.xyz \ + ChampsDarcy.med \ + cube.cnc \ + cube_hexa8_import22.med \ + cube_hexa8.med \ + cube_hexa8_quad4_import22.med \ + cube_hexa8_quad4.med \ + cube.inp \ + cube.xyz \ + darcy_1.1_res.med \ + darcy_1.3_resCASTEM.med \ + darcy_1.3_resPORFLOW.med \ + darcy_1.3_resTRACES.med \ + darcy2_Castem_EFMH.med \ + darcy2_Castem_qua_EFMH.med \ + darcy2_Castem_qua_VF.med \ + Darcy3_3D_H_10x10x10_2.med \ + Darcy3_3D_H_10x10x10.sauve \ + Data.png \ + Deff_fdt_5.8_castem_efmh_diff_conc_dom.med \ + Deff_fdt_5.8_castem_vf_diff_conc_dom.med \ + dx200_dy1_avec_2couches.sauve \ + elle_2D_QT_10x10.sauve \ + elle_2D_QT_2x2.sauve \ + elle_2D_QT_40x40.sauve \ + elle_2D_QT_4x4.sauve \ + elle_3D_HPr_10x10x10_2.med \ + elle_3D_HPr_10x10x10.sauve \ + elle_3D_HPr_2x2x2_2.med \ + elle_3D_HPr_2x2x2.sauve \ + elle_3D_HPr_4x4x4_2.med \ + elle_3D_HPr_4x4x4.sauve \ + extendedtransport53_triangles.med \ + geomMesh21.med \ + geomMesh22.med \ + H_CastCast_EFMH_I129_COUPLEX1.med \ + H_CastCast_VF_I129_COUPLEX1.med \ + H_CastCast_VF_Se79_COUPLEX1.med \ + H_CastPorf_I129_COUPLEX1.med \ + H_CastPorf_Se79_COUPLEX1.med \ + H_PorfCast_EFMH_I129_COUPLEX1.med \ + H_PorfCast_EFMH_Se79_COUPLEX1.med \ + H_PorfPorf_I129_COUPLEX1.med \ + H_Traces_I129_COUPLEX1.med \ + H_Traces_Se79_COUPLEX1.med \ + inclusion_2d_raf.sauve \ + inclusion_2d.sauve \ + Infos.png \ + mail_ktest1-3-hexa.sauve \ + mail_ktest1-3-tetra.sauve \ + mail_ktest3-1.sauve \ + mail_ktest3-2.sauve \ + maill.00.med \ + maill.00_nofield.med \ + maill.00_nomesh.med \ + maill.00_without_seg2.med \ + maill.0.med \ + maillage_5_5_5.med \ + maillage_andra2_100elts.sauve \ + maillage_cas2_2d.sauve \ + maillage_cas4_234elts.sauve \ + maillage_CHEMVAL_100elts.sauve \ + maillage_CHEMVAL_40elts.sauve \ + maillage_chemvalIV_cas1_100elts.sauve \ + maillage_chemvalIV_cas1_40elts.med \ + maillage_chemvalIV_cas1_40elts.sauve \ + maillage_UniSegFam_import22.med \ + maillage_UniSegFam.med \ + mail_test1-1-qua.sauve \ + mail_test1-1-tri.sauve \ + mail_test1-2-qua.sauve \ + mail_test1-2-tri.sauve \ + mail-test1-4-1.sauve \ + mail-test1-4-2.sauve \ + MED.config \ + MED_en.xml \ + mesh_import22.med \ + mesh.med \ + Mistrat_import22.med \ + Mistrat.med \ + ModuleMed.png \ + Old_ChampsDarcy.med \ + Old_darcy_1.1_res.med \ + Old_darcy_1.3_resCASTEM.med \ + Old_darcy_1.3_resPORFLOW.med \ + Old_darcy_1.3_resTRACES.med \ + Old_darcy2_Castem_EFMH.med \ + Old_darcy2_Castem_qua_EFMH.med \ + Old_darcy2_Castem_qua_VF.med \ + Old_Deff_fdt_5.8_castem_efmh_diff_conc_dom.med \ + Old_Deff_fdt_5.8_castem_vf_diff_conc_dom.med \ + Old_H_CastCast_EFMH_I129_COUPLEX1.med \ + Old_H_CastCast_VF_I129_COUPLEX1.med \ + Old_H_CastCast_VF_Se79_COUPLEX1.med \ + Old_H_CastPorf_I129_COUPLEX1.med \ + Old_H_CastPorf_Se79_COUPLEX1.med \ + Old_H_PorfCast_EFMH_I129_COUPLEX1.med \ + Old_H_PorfCast_EFMH_Se79_COUPLEX1.med \ + Old_H_PorfPorf_I129_COUPLEX1.med \ + Old_H_PorfPorf_Se79_COUPLEX1.med \ + Old_H_Traces_I129_COUPLEX1.med \ + Old_H_Traces_Se79_COUPLEX1.med \ + Old_maillage_chemvalIV_cas1_40elts.med \ + pointe_import22.med \ + pointe.med \ + poly3D.med \ + polyedres.med \ + polygones.med \ + recoll_bord.med \ + SalomeApp.xml \ + Structure.png \ + test19.med \ + test_2D.med \ + test3.cnc \ + test3.inp \ + test3.xyz \ + TimeStamps_import22.med \ + TimeStamps.med \ + titi.cnc \ + titi.inp \ + titi.xyz \ + zzzz121b.med \ + zzzz121b_without_tr6.med + +nodist_salomeres_DATA=MEDCatalog.xml +EXTRA_DIST+= config diff --git a/resources/SalomeApp.xml b/resources/SalomeApp.xml index 8760c1bb3..bfb313ecc 100644 --- a/resources/SalomeApp.xml +++ b/resources/SalomeApp.xml @@ -6,6 +6,6 @@
- +
diff --git a/src/INTERPOLATION/MEDMEM_Interpolation.hxx b/src/INTERPOLATION/MEDMEM_Interpolation.hxx index 18c7a523c..85a62820c 100644 --- a/src/INTERPOLATION/MEDMEM_Interpolation.hxx +++ b/src/INTERPOLATION/MEDMEM_Interpolation.hxx @@ -122,7 +122,7 @@ template INTERPOLATION::INTERPOLATION(const MESH & fr if (! _fromMesh ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"fromMesh is a NULL pointer !")) ; int spaceDimension = _fromMesh->getSpaceDimension(); - if (spaceDimension != DIMENSION ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The spaceDimension of mesh |" << _fromMesh->getName() << "| is |" << spaceDimension << "| and should be |" << DIMENSION << "|" << endl)) ; + if (spaceDimension != DIMENSION ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The spaceDimension of mesh |" << _fromMesh->getName() << "| is |" << spaceDimension << "| and should be |" << DIMENSION << "|")) ; _fromWrapper = new Meta_Wrapper(_fromMesh->getNumberOfNodes(), const_cast (_fromMesh->getCoordinates(MED_EN::MED_FULL_INTERLACE)), @@ -150,8 +150,8 @@ template INTERPOLATION::INTERPOLATION(const MESH & fr int fromSpaceDimension = _fromMesh->getSpaceDimension(); int toSpaceDimension = _toMesh->getSpaceDimension(); - if (fromSpaceDimension != DIMENSION ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The spaceDimension of mesh |" << _fromMesh->getName() << "| is |" << INTERPOLATION::spaceDimension << "| and should be |" << DIMENSION << "|" << endl)) ; - if ( toSpaceDimension != DIMENSION ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The spaceDimension of mesh |" << _toMesh->getName() << "| is |" << INTERPOLATION::spaceDimension << "| and should be |" << DIMENSION << "|" << endl)) ; + if (fromSpaceDimension != DIMENSION ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The spaceDimension of mesh |" << _fromMesh->getName() << "| is |" << fromSpaceDimension << "| and should be |" << DIMENSION << "|")) ; + if ( toSpaceDimension != DIMENSION ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"The spaceDimension of mesh |" << _toMesh->getName() << "| is |" << toSpaceDimension << "| and should be |" << DIMENSION << "|")) ; _fromWrapper = new Meta_Wrapper(_fromMesh->getNumberOfNodes(), const_cast (_fromMesh->getCoordinates(MED_EN::MED_FULL_INTERLACE)), diff --git a/src/INTERPOLATION/MEDMEM_WrapperCells.hxx b/src/INTERPOLATION/MEDMEM_WrapperCells.hxx index 32fb19059..32d7912df 100644 --- a/src/INTERPOLATION/MEDMEM_WrapperCells.hxx +++ b/src/INTERPOLATION/MEDMEM_WrapperCells.hxx @@ -927,7 +927,7 @@ inline Connectivite_Generale::Connectivite_Generale():AllConn(NBR_MODELES_MAILLE } inline Connectivite_Generale::~Connectivite_Generale() { - for (int i=0;igetConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); - const int * med_connectivite=maillesmed->getConnectivityIndex(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_CELL); const int * med_index=maillesmed->getValueIndex(MED_EN::MED_FULL_INTERLACE); nbr_mailles=maillesmed->getNumberOf(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); int size=med_index[nbr_mailles]-med_index[0]; diff --git a/src/INTERPOLATION/MEDMEM_WrapperMesh.hxx b/src/INTERPOLATION/MEDMEM_WrapperMesh.hxx index 918c67965..c3e419d8e 100644 --- a/src/INTERPOLATION/MEDMEM_WrapperMesh.hxx +++ b/src/INTERPOLATION/MEDMEM_WrapperMesh.hxx @@ -219,7 +219,7 @@ template Wrapper_Maillage::Wrapper_Maillage(NUA // pour chaque face, dite primaire, on prend le premier noeud, et on parcourt les mailles qui contiennent ce noeud tant qu'on n'a pas trouvĂ© de voisin // (bornĂ©, par un coefficient qui dĂ©pend de l'anisotropie du maillage, le nombre maximum de maille qui contient un sommet) - for (ind_num_maille_sec=0;(flag_existence==0)&&(ind_num_maille_sec Wrapper_Maillage::Wrapper_Maillage(NUA // on examine les faces de cette maille dans la numĂ©rotation globale faces_contenues - for (ind_num_cont=0;ind_num_cont Wrapper_Maillage::Wrapper_Maillage(NUA for (i=0;isize();i++) + for (i=1;i<(int)noeud_contenu->size();i++) { tmp=DistanceL2(P,(*nuage)[(*noeud_contenu)[i]]); if (tmpsize();num_loc++) + for (num_loc=0;num_loc<(int)noeud_contenu->size();num_loc++) { int indice=(*noeud_contenu)[num_loc]; NOEUD & courant=(*nuage)[indice]; diff --git a/src/INTERPOLATION/Makefile.am b/src/INTERPOLATION/Makefile.am new file mode 100644 index 000000000..bf12b5291 --- /dev/null +++ b/src/INTERPOLATION/Makefile.am @@ -0,0 +1,73 @@ +# MED MEDMEM : MED files in memory +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : Makefile.in +# Module : MED + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +bin_PROGRAMS = \ + test_MEDMEM_InterpolationFlipBack \ + test_MEDMEM_InterpolationFromMesh_toMesh \ + test_MEDMEM_InterpolationRecopieMaillage \ + test_MEDMEM_InterpolationSansRecopieMaillage \ + test_MEDMEM_InterpolationTimeStep \ + UseCasedTree \ + UseCaseInterpolationts \ + UseCaseInterpolationwots \ + UseCaseMapping \ + UseCaseWrapper_Maillage \ + create_mesh_interpolation + +salomeinclude_HEADERS = \ +MEDMEM_dTree.hxx\ +MEDMEM_dTreeSommet.hxx\ +MEDMEM_InterpolationHighLevelObjects.hxx\ +MEDMEM_Interpolation.hxx\ +MEDMEM_InterpolationTools.hxx\ +MEDMEM_Mapping.hxx\ +MEDMEM_MappingTools.hxx\ +MEDMEM_WrapperCells.hxx\ +MEDMEM_WrapperConnectivity.hxx\ +MEDMEM_WrapperField.hxx\ +MEDMEM_WrapperMesh.hxx\ +MEDMEM_WrapperNodes.hxx + +dist_test_MEDMEM_InterpolationFlipBack_SOURCES= test_MEDMEM_InterpolationFlipBack.cxx +dist_test_MEDMEM_InterpolationFromMesh_toMesh_SOURCES= test_MEDMEM_InterpolationFromMesh_toMesh.cxx +dist_test_MEDMEM_InterpolationRecopieMaillage_SOURCES= test_MEDMEM_InterpolationRecopieMaillage.cxx +dist_test_MEDMEM_InterpolationSansRecopieMaillage_SOURCES= test_MEDMEM_InterpolationSansRecopieMaillage.cxx +dist_test_MEDMEM_InterpolationTimeStep_SOURCES= test_MEDMEM_InterpolationTimeStep.cxx +dist_UseCasedTree_SOURCES= UseCasedTree.cxx +dist_UseCaseInterpolationts_SOURCES= UseCaseInterpolationts.cxx +dist_UseCaseInterpolationwots_SOURCES= UseCaseInterpolationwots.cxx +dist_UseCaseMapping_SOURCES= UseCaseMapping.cxx +dist_UseCaseWrapper_Maillage_SOURCES= UseCaseWrapper_Maillage.cxx + +AM_CPPFLAGS=-U_DEBUG_ $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core +LDADD=-lm $(MED2_LIBS) $(HDF5_LIBS) ../MEDMEM/libmedmem.la ../MEDWrapper/V2_1/Core/libmed_V2_1.la + +if MED_ENABLE_KERNEL + AM_CPPFLAGS+= ${KERNEL_CXXFLAGS} + LDADD+= -lSALOMELocalTrace -lSALOMEBasics ${KERNEL_LDFLAGS} +endif diff --git a/src/INTERPOLATION/Makefile.in b/src/INTERPOLATION/Makefile.in deleted file mode 100644 index 158d7fded..000000000 --- a/src/INTERPOLATION/Makefile.in +++ /dev/null @@ -1,112 +0,0 @@ -# MED MEDMEM : MED files in memory -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Module : MED - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir):$(srcdir)/tests - -MACHINE=PCLINUX - -@COMMENCE@ - - -EXPORT_PYSCRIPTS = \ - - -EXPORT_HEADERS = \ -MEDMEM_dTree.hxx\ -MEDMEM_dTreeSommet.hxx\ -MEDMEM_InterpolationHighLevelObjects.hxx\ -MEDMEM_Interpolation.hxx\ -MEDMEM_InterpolationTools.hxx\ -MEDMEM_Mapping.hxx\ -MEDMEM_MappingTools.hxx\ -MEDMEM_WrapperCells.hxx\ -MEDMEM_WrapperConnectivity.hxx\ -MEDMEM_WrapperField.hxx\ -MEDMEM_WrapperMesh.hxx\ -MEDMEM_WrapperNodes.hxx - - -# Libraries targets - -LIB= -LIB_SRC = - - -# Executables targets -BIN = -BIN_SRC = -BIN_SERVER_IDL = -BIN_CLIENT_IDL = - -TEST_PROGS = \ -test_MEDMEM_InterpolationFlipBack\ -test_MEDMEM_InterpolationFromMesh_toMesh\ -test_MEDMEM_InterpolationRecopieMaillage\ -test_MEDMEM_InterpolationSansRecopieMaillage\ -test_MEDMEM_InterpolationTimeStep\ -UseCasedTree\ -UseCaseInterpolationts\ -UseCaseInterpolationwots\ -UseCaseMapping\ -UseCaseWrapper_Maillage - - - - -CPPFLAGS+=-U_DEBUG_ $(MED2_INCLUDES) $(HDF5_INCLUDES) -I../ -CXXFLAGS+=-U_DEBUG_ @CXXTMPDPTHFLAGS@ -#LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -LDFLAGS+=-lm $(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 - -#LDFLAGSFORBIN+=$(MED2_LIBS) $(HDF5_LIBS) -L../.libs -lmedmem -LDFLAGSFORBIN+=-lm $(MED2_LIBS) $(HDF5_LIBS) -L../.libs -lmedmem -lmed_V2_1 - -ifeq ($(MED_WITH_KERNEL),yes) - CPPFLAGS+= ${KERNEL_CXXFLAGS} - CXXFLAGS+= ${KERNEL_CXXFLAGS} - #LDFLAGS+= -lSalomeLoggerServer ${KERNEL_LDFLAGS} - LDFLAGS+= -lSALOMELocalTrace ${KERNEL_LDFLAGS} - - #LDFLAGSFORBIN+= -lSalomeLoggerServer ${KERNEL_LDFLAGS} - LDFLAGSFORBIN+= -lSALOMELocalTrace -lSALOMEBasics ${KERNEL_LDFLAGS} -endif - -LIBSFORBIN= - -LDFLAGS= - -LIBS= - -# build create_mesh : -bin: create_mesh_interpolation - -create_mesh_interpolation: %: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(MED2_LIBS) $(HDF5_LIBS) $< - -@CONCLUDE@ diff --git a/src/MED/MED_test1.py b/src/MED/MED_test1.py index b955ee19b..ee5810b29 100755 --- a/src/MED/MED_test1.py +++ b/src/MED/MED_test1.py @@ -35,7 +35,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" fileName="pointe.med" fileTout=filePath+fileName diff --git a/src/MED/MED_test2.py b/src/MED/MED_test2.py index 152d67135..9f1776cb4 100755 --- a/src/MED/MED_test2.py +++ b/src/MED/MED_test2.py @@ -31,7 +31,7 @@ import SALOME import os filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile=filePath+"mesh.med" med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED") diff --git a/src/MED/Makefile.am b/src/MED/Makefile.am new file mode 100644 index 000000000..319dee829 --- /dev/null +++ b/src/MED/Makefile.am @@ -0,0 +1,49 @@ +# MED MED : implemetation of MED idl descriptions +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDEngine.la + +dist_libMEDEngine_la_SOURCES= Med_Gen_i.cxx Med_Gen_Driver_i.cxx +salomeinclude_HEADERS = Med_Gen_i.hxx Med_Gen_Driver_i.hxx + +libMEDEngine_la_CPPFLAGS= @CAS_CPPFLAGS@ $(MED2_INCLUDES) $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ \ + -I$(srcdir)/../MEDMEM_I -I$(top_builddir)/salome_adm/unix -I$(top_builddir)/idl \ + -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core + +libMEDEngine_la_LDFLAGS=\ + $(top_builddir)/idl/libSalomeIDLMED.la \ + ../MEDMEM_I/libMEDMEMImpl.la \ + ${KERNEL_LDFLAGS} -lTOOLSDS -lSalomeHDFPersist +# ${KERNEL_LDFLAGS} \ +# @CORBA_LIBS@ \ +# @CAS_OCAF@ \ +# $(HDF5_LIBS) +# -lOpUtil -lSalomeContainer -lSalomeDS -lSalomeNS -lRegistry +# +# + + + +dist_salomescript_DATA= MED_test1.py MED_test2.py Med_Gen_test.py testMedAlliances.py testMedAlliances1.py diff --git a/src/MED/Makefile.in b/src/MED/Makefile.in deleted file mode 100644 index 07cbff46e..000000000 --- a/src/MED/Makefile.in +++ /dev/null @@ -1,66 +0,0 @@ -# MED MED : implemetation of MED idl descriptions -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Paul RASCLE, EDF -# Module : MED -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir):$(top_srcdir)/idl:$(top_builddir)/idl - -@COMMENCE@ - -EXPORT_PYSCRIPTS = MED_test1.py MED_test2.py Med_Gen_test.py testMedAlliances.py testMedAlliances1.py - -# Libraries targets - -LIB = libMEDEngine.la - -LIB_SRC = Med_Gen_i.cxx -LIB_SERVER_IDL = MED_Gen.idl SALOME_Component.idl SALOME_ContainerManager.idl \ - SALOME_Exception.idl MED.idl - -LIB_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_ModuleCatalog.idl SALOME_Comm.idl SALOME_GenericObj.idl - -# Executables targets -BIN = -BIN_SRC = - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -# additionnal information to compil and link file - -CPPFLAGS += $(OCC_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} -CXXFLAGS += $(OCC_CXXFLAGS) ${KERNEL_CXXFLAGS} - -LDFLAGS+= $(OCC_LIBS) $(HDF5_LIBS) ${KERNEL_LDFLAGS} \ - -lSalomeContainer -lSalomeHDFPersist -lSalomeDS -lSalomeNS -lRegistry -lOpUtil -lMEDMEMImpl - -MED.hh MEDSK.cc: MED.idl - omniidl -bcxx -Wbtp -I$(top_builddir)/idl -I${KERNEL_ROOT_DIR}/idl/salome $^ - -@CONCLUDE@ diff --git a/src/MED/Med_Gen_Driver_i.cxx b/src/MED/Med_Gen_Driver_i.cxx new file mode 100755 index 000000000..c8a06cbfd --- /dev/null +++ b/src/MED/Med_Gen_Driver_i.cxx @@ -0,0 +1,970 @@ +// MED MED : implemetation of MED idl descriptions +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : Med_Gen_Driver_i.cxx +// Author : Paul RASCLE, EDF +// Module : MED +// $Header$ + +#include "Med_Gen_Driver_i.hxx" + +#include "MEDMEM_Mesh_i.hxx" +#include "MEDMEM_Med_i.hxx" +#include "MEDMEM_FieldTemplate_i.hxx" +#include "MEDMEM_Support_i.hxx" + +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_MedMedDriver.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_MedFieldDriver.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_DriversDef.hxx" + + +#include "Utils_SINGLETON.hxx" +#include "OpUtil.hxx" +#include "Utils_CorbaException.hxx" +#include "utilities.h" + +#include "SALOMEDS_Tool.hxx" + +#include +#include + +#include +#include + +#include + +using namespace std; +using namespace MEDMEM; + +// Initialisation des variables statiques +map Med_Gen_Driver_i::_MedCorbaObj; + +//============================================================================= +/*! + * default constructor: not for use + */ +//============================================================================= +Med_Gen_Driver_i::Med_Gen_Driver_i() +{ + MESSAGE("Med_Gen_Driver_i::Med_Gen_Driver_i"); +} + +//============================================================================= +/*! + * standard constructor + */ +//============================================================================= +Med_Gen_Driver_i::Med_Gen_Driver_i(CORBA::ORB_ptr orb) +{ + MESSAGE("activate object"); + _driver_orb = CORBA::ORB::_duplicate(orb); + + // get a NamingService interface + _NS = SINGLETON_::Instance(); + ASSERT(SINGLETON_::IsAlreadyExisting()); + _NS->init_orb( _driver_orb ); +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= +Med_Gen_Driver_i::~Med_Gen_Driver_i() +{ + MESSAGE("Med_Gen_Driver_i::~Med_Gen_Driver_i"); +} + +//============================================================================= +/*! + * GetMED [ static ] + * + * Get Med of the study (for persistance) + */ +//============================================================================= +MEDMEM::MED_i* Med_Gen_Driver_i::GetMED(SALOMEDS::SComponent_ptr theComponent) +{ + // we have a separate MED_i for each component in a study + SALOMEDS::Study_var study = theComponent->GetStudy(); + ostringstream os; + os << study->StudyId() << "_" << theComponent->Tag(); + string mapKey = os.str(); + + MED_i* med_i; + map ::iterator id_med; + id_med = _MedCorbaObj.find( mapKey ); + if ( id_med == _MedCorbaObj.end() ) + _MedCorbaObj[ mapKey ] = med_i = new MED_i(); + else + med_i = id_med->second; + return med_i; +} + +//============================================================================= +/*! + * CORBA: Save Mesh objects (called when a study is saved) + */ +//============================================================================= +namespace { + + // names to use instead of true and false + enum { SAVE = 1, RESTORE = 0, ASCII = 1, NON_ASCII = 0 }; + + //================================================================================ + /*! + * \brief Return path and base name of a file to store med data in + * \param theStudy - study being stored or restored + * \param theURL - path to file storing the study + * \param isMultiFile - storage mode + * \param isSave - action kind: SAVE or RESTORE + * \retval pair - path and file base name + */ + //================================================================================ + pair getPersistanceDirAndFileName(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + const bool isMultiFile, + const bool isSave) + { + string path, file; + CORBA::String_var compName = theComponent->ComponentDataType(); + if (isMultiFile) { + // file constantly holding data + path = theURL; + SALOMEDS::Study_var study = theComponent->GetStudy(); + file = SALOMEDS_Tool::GetNameFromPath( study->URL() ); + file += string( "_" ) + string( compName ) + ".med"; + } + else { + // temporary file + path = SALOMEDS_Tool::GetTmpDir(); + if ( strcmp( "MED", compName ) != 0 ) + file = string( compName ) + "_"; // not MED + file += "tmp.med"; + } + return make_pair ( path, file ); + } + + //================================================================================ + /*! + * \brief Save med objects published in a study + * \param theStudy - study to store + * \param theURL - path to store + * \param isMultiFile - store mode + * \param isAscii - store mode: ASCII or NON_ASCII + * \retval SALOMEDS::TMPFile* - result file + */ + //================================================================================ + SALOMEDS::TMPFile* saveStudy (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile, + bool isAscii) + { + const char* LOC = "Med_Gen_Driver_i::Save"; + BEGIN_OF(LOC); + + // Write all MEDMEM objects in one med file because of problems with + // reference to external mesh when writting field in a separate file. + // Actually, writting is OK, but when reading a field, its support + // is updated using mesh data missing in the file being read + + // If arises a problem of meshes or other objects having equal names, + // the solution can be in renaming them using study entry before writting + // and renaming back during restoration, real names will be stored in + // LocalPersistentID's for example + + if (CORBA::is_nil(theComponent)) { + SALOMEDS::TMPFile_var aStreamFile; + return aStreamFile._retn(); + } + + SALOMEDS::Study_var study = theComponent->GetStudy(); + + pair aDir_aFileName = + getPersistanceDirAndFileName(theComponent, theURL, isMultiFile, SAVE ); + string& aPath = aDir_aFileName.first; + string& aBaseName = aDir_aFileName.second; + string aFile = aPath + aBaseName; + + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(1); + aSeq[0] = CORBA::string_dup(aBaseName.c_str()); + + if (isMultiFile) { // remove existing file + //cout << "-----------------Remove " << aPath<< ", "< savedMeshIDs; + { + SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(theComponent); + anIter->InitEx(1); + for (; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var aSO = anIter->Value(); + SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow( aSO->GetObject() ); + if (! CORBA::is_nil(myField)) { + long driverId = myField->addDriver(SALOME_MED::MED_DRIVER, + aFile.c_str(), + myField->getName()); + myField->write(driverId,""); + // save mesh + SALOME_MED::SUPPORT_var sup = myField->getSupport(); + if ( !sup->_is_nil() ) { + SALOME_MED::MESH_var mesh = sup->getMesh(); + if ( !mesh->_is_nil() ) { + CORBA::Long corbaID = mesh->getCorbaIndex(); + if ( savedMeshIDs.find( corbaID ) == savedMeshIDs.end() ) { + long driverId = mesh->addDriver(SALOME_MED::MED_DRIVER, + aFile.c_str(), + mesh->getName()); + mesh->write(driverId,""); + savedMeshIDs.insert( corbaID ); + } + } + } + } + } + } + + { + SALOMEDS::ChildIterator_var anIter = study->NewChildIterator(theComponent); + anIter->InitEx(1); + for (; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var aSO = anIter->Value(); + SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow( aSO->GetObject() ); + if (! CORBA::is_nil(myMesh)) { + CORBA::Long corbaID = myMesh->getCorbaIndex(); + if ( savedMeshIDs.find( corbaID ) == savedMeshIDs.end() ) { + long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER, + aFile.c_str(), + myMesh->getName()); + myMesh->write(driverId,""); + savedMeshIDs.insert( corbaID ); + } + } + } + } + + if ( isAscii ) + HDFascii::ConvertFromHDFToASCII( aFile.c_str(), true); + + // Convert a file to the byte stream + SALOMEDS::TMPFile_var aStreamFile; + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aPath.c_str(), aSeq.in(), isMultiFile); + + // Remove a tmp file and directory + if (!isMultiFile) { + //cout << "-----------------Remove " << aPath<< ", "<GetStudy(); + + // Get file name + pair aDir_aFileName = getPersistanceDirAndFileName + (theComponent, theURL, isMultiFile, RESTORE); + string& aPath = aDir_aFileName.first; + string& aBaseName = aDir_aFileName.second; + string aFile = aPath + aBaseName; + + SALOMEDS::ListOfFileNames_var aSeq = + SALOMEDS_Tool::PutStreamToFiles(theStream, aPath.c_str(), isMultiFile); + + string aASCIIPath, aASCIIFile; + if (isASCII) + { + aASCIIPath = HDFascii::ConvertFromASCIIToHDF(aFile.c_str()); + aASCIIFile = "hdf_from_ascii.hdf"; + aFile = aASCIIPath + aASCIIFile; + } + + MED_i* med_i = Med_Gen_Driver_i::GetMED(theComponent); + SALOME_MED::MED_var med = med_i->_this(); + + // Read all meshes with supports and all fields + try + { + //cout << "-----------------Filename " << aFile << endl; + med_i->initWithFieldType(study, MED_DRIVER, aFile, true); + + // publishing must be done by initWithFieldType according to flag + med_i->addInStudy(study, med, theComponent, 0); + } + catch (const std::exception & ex) + { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to read a hdf file",SALOME::BAD_PARAM); + } + + // Remove tmp files + bool keepTmpFiles = getenv( "MEDPERSIST_KEEP_TMP_FILES" ); // DEBUG + if ( keepTmpFiles ) + cout << "TMP FILE: " << aFile << endl; + if ( !isMultiFile && !keepTmpFiles ) { + aSeq->length(1); + aSeq[0]=CORBA::string_dup(aBaseName.c_str()); + SALOMEDS_Tool::RemoveTemporaryFiles(aPath.c_str(), aSeq.in(), true); + } + if (isASCII) + { + aSeq->length(1); + aSeq[0] = CORBA::string_dup(aASCIIFile.c_str()); + //cout << "-----------------Remove " << aASCIIPath<< ", "<getName() + + // "_ORDRE_"+a.str()+ + // "_ITER_"+b.str()+".med" + int aLPIdLen = strlen(aLocalPersistentID); + const int _MEDFIELD_Len = strlen("_MEDFIELD_"); + const int _ORDRE_Len = strlen("_ORDRE_"); + const int _ITER_Len = strlen("_ITER_"); + + // Get field name: look for _ORDRE_ in aLocalPersistentID + int aFieldNameLen = 0, aFieldNameBeg = _MEDFIELD_Len, _ORDRE_Beg; + for ( _ORDRE_Beg = aFieldNameBeg; _ORDRE_Beg < aLPIdLen; ++aFieldNameLen,++_ORDRE_Beg ) + if ( strncmp( &aLocalPersistentID[ _ORDRE_Beg ], "_ORDRE_", _ORDRE_Len ) == 0 ) + break; + aFieldName = string( &(aLocalPersistentID[aFieldNameBeg]), aFieldNameLen); + + // Get orderNumber + int anOrderNumberBeg = _ORDRE_Beg + _ORDRE_Len; + aNumOrdre = atoi( & aLocalPersistentID[ anOrderNumberBeg ]); + + // Get iterationNumber: look for _ITER_ in aLocalPersistentID + int _ITER_Beg = anOrderNumberBeg; + for ( ; _ITER_Beg < aLPIdLen; ++_ITER_Beg ) + if ( strncmp( &aLocalPersistentID[ _ITER_Beg ], "_ITER_", _ITER_Len ) == 0 ) + break; + anIterNumber = atoi( & aLocalPersistentID[ _ITER_Beg + _ITER_Len ]); + } + + //================================================================================ + /*! + * \brief Retrieve from aLocalPersistentID data to get support from med + * \param aLocalPersistentID - persistent ID + * \param type - string "FAMILY", "GROUP" or "SUPPORT + * \param name - support name + * \param mesh - mesh name + * \param entity - support entity + * \retval bool - true if all data found in aLocalPersistentID + */ + //================================================================================ + bool getSupportData (string aLocalPersistentID, + string & type, + string & name, + string & mesh, + string & entity) + { + // aLocalPersistentID contains: + // _MED_[FAMILY|GROUP|SUPPORT]/support_name/ENS_MAA/mesh_name/ENTITY/entity + string::size_type slash1Pos = aLocalPersistentID.find("/"); + if ( slash1Pos == aLocalPersistentID.npos ) return false; + string::size_type ens_maaPos = aLocalPersistentID.find("/ENS_MAA/", slash1Pos); + if ( ens_maaPos == aLocalPersistentID.npos ) return false; + string::size_type entityPos = aLocalPersistentID.find("/ENTITY/", ens_maaPos); + if ( entityPos == aLocalPersistentID.npos ) return false; + + string::size_type medSize = strlen("_MED_"); + string::size_type ens_maaSize = strlen("/ENS_MAA/"); + string::size_type entitySize = strlen("/ENTITY/"); + + type = aLocalPersistentID.substr( medSize, slash1Pos - medSize ); + name = aLocalPersistentID.substr( slash1Pos + 1, ens_maaPos - slash1Pos - 1); + mesh = aLocalPersistentID.substr( ens_maaPos + ens_maaSize, + entityPos - ens_maaPos - ens_maaSize); + entity = aLocalPersistentID.substr( entityPos + entitySize ); +// cout << aLocalPersistentID << endl +// << " type: " << type +// << " name: " << name +// << " mesh: " << mesh +// << " entity: " << entity << endl; + return true; + } +} // no name namespace + +//================================================================================ +/*! + * \brief Save data published under MED component + * \param theComponent - MED component + * \param theURL - path to store + * \param isMultiFile - store mode + * \retval SALOMEDS::TMPFile* - result file + */ +//================================================================================ +SALOMEDS::TMPFile* Med_Gen_Driver_i::Save (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) +{ + return saveStudy ( theComponent, theURL, isMultiFile, NON_ASCII ); +} + +//================================================================================ +/*! + * \brief Save data published under MED component in ASCII file + * \param theComponent - MED component + * \param theURL - path to store + * \param isMultiFile - store mode + * \retval SALOMEDS::TMPFile* - result file + */ +//================================================================================ +SALOMEDS::TMPFile* Med_Gen_Driver_i::SaveASCII (SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile) +{ + return saveStudy ( theComponent, theURL, isMultiFile, ASCII ); +} + +//============================================================================= +/*! + * CORBA: Load Mesh objects (called when an existing study is opened) + */ +//============================================================================= + +CORBA::Boolean Med_Gen_Driver_i::Load (SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) +{ + const char* LOC = "Med_Gen_Driver_i::Load"; + BEGIN_OF(LOC); + + loadStudy ( theComponent, theStream, theURL, isMultiFile, NON_ASCII ); + + return true; +} + +CORBA::Boolean Med_Gen_Driver_i::LoadASCII (SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile) +{ + loadStudy ( theComponent, theStream, theURL, isMultiFile, ASCII ); + return true; +} + +//============================================================================= +/*! + * CORBA: + */ +//============================================================================= +void Med_Gen_Driver_i::Close (SALOMEDS::SComponent_ptr theComponent) +{ + MESSAGE("Med_Gen_Driver_i::Close"); + SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH"); + if (!CORBA::is_nil(aMedMeshFather)) { + SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather); + for(; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var aSO = anIter->Value(); + SALOMEDS::GenericAttribute_var anAttr; + if (aSO->FindAttribute(anAttr,"AttributeIOR")) { + CORBA::Object_var myIOR = + _driver_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); + SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); + // here must call method destroy of myMesh, but it not implemented yet + } + } + } +} + +//============================================================================= +/*! + * CORBA: give a persistent reference of a transient object (for study save) + */ +//============================================================================= +char* Med_Gen_Driver_i::IORToLocalPersistentID (SALOMEDS::SObject_ptr theSObject, + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) +{ + const char * LOC = "Med_Gen_Driver_i::IORToLocalPersistentID"; + BEGIN_OF(LOC); + SCRUTE(IORString); + + if (string(IORString).size()==0) return CORBA::string_dup("_MED"); + // Well, we know where put object (_saveFilename) and we know object (IORString) + // cast object : + CORBA::Object_var myIOR = _driver_orb->string_to_object(IORString); + + // MED + SALOME_MED::MED_var myMed = SALOME_MED::MED::_narrow(myIOR); + if (! CORBA::is_nil(myMed)) + { + string str_MedName="_MED Objet Med + /OBJ_MED/"; + return CORBA::string_dup(str_MedName.c_str()); + } + + // MESH + SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); + if (! CORBA::is_nil(myMesh)) + { + CORBA::String_var aName((string("_MEDMESH_")+ myMesh->getName() + ".med").c_str()); + return aName._retn(); + } + + // SUPPORT + SALOME_MED::SUPPORT_var mySupport = SALOME_MED::SUPPORT::_narrow(myIOR); + if (! CORBA::is_nil(mySupport)) + { + string type, str_SupportName; + SALOME_MED::FAMILY_var family = SALOME_MED::FAMILY::_narrow(myIOR); + if ( !family->_is_nil() ) + type = "_MED_FAMILY"; + else { + SALOME_MED::GROUP_var grp = SALOME_MED::GROUP::_narrow(myIOR); + if ( !grp->_is_nil() ) + type = "_MED_GROUP"; + else + type = "_MED_SUPPORT"; + } + try { + ostringstream os; + os << type << "/" << mySupport->getName(); + os << "/ENS_MAA/" << mySupport->getMesh()->getName(); + os << "/ENTITY/" << mySupport->getEntity(); + str_SupportName = os.str(); + } + catch(...) { + MESSAGE("Unable to save the support"); + THROW_SALOME_CORBA_EXCEPTION("Unable to save Field in Med"\ + ,SALOME::INTERNAL_ERROR); + } + return CORBA::string_dup(str_SupportName.c_str()); + } + + SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR); + if (! CORBA::is_nil(myField)) + { + string str_FieldName; + ostringstream a,b; + a<< myField->getOrderNumber(); + b<< myField->getIterationNumber(); + CORBA::String_var aName((string("_MEDFIELD_")+ myField->getName() + + string("_ORDRE_")+a.str()+ + string("_ITER_")+b.str() + + ".med").c_str()); + return aName._retn(); + } + + //THROW_SALOME_CORBA_EXCEPTION("Unable to save IOR",SALOME::BAD_PARAM); + return CORBA::string_dup("_MED"); +} + +//============================================================================= +/*! + * CORBA: give a transient reference (when loading an object, opening study) + */ +//============================================================================= +char* Med_Gen_Driver_i::LocalPersistentIDToIOR (SALOMEDS::SObject_ptr theSObject, + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) + throw(SALOME::SALOME_Exception) +{ + const char * LOC = "Med_Gen_Driver_i::LocalPersistentIDToIOR"; + BEGIN_OF(LOC); + + // all object are restored in Load() if their name in study coincides + // with a default one generated by object.addInStudy(...) + CORBA::String_var ior = theSObject->GetIOR(); + bool restoredByLoad = ( ior.in() && strlen( ior ) > 0 ); + + if ( !restoredByLoad ) + { + CORBA::Object_var object; + SALOMEDS::SComponent_var component = theSObject->GetFatherComponent(); + MED_i* med_i = Med_Gen_Driver_i::GetMED(component); + SALOME_MED::MED_var med = med_i->_this(); + + // MED + if (strcmp(aLocalPersistentID, "_MED Objet Med + /OBJ_MED/") == 0) + { + //object = med; + object = SALOME_MED::MED::_duplicate(med); + } + // MESH + else if (strncmp(aLocalPersistentID, "_MEDMESH_",9) == 0) + { + int aMeshNameLen = strlen(aLocalPersistentID) - 12; + string aMeshName( &(aLocalPersistentID[9]), aMeshNameLen); + aMeshName[aMeshNameLen-1] = 0; + try { + object = med->getMeshByName( aMeshName.c_str() ); + } + catch (const std::exception & ex) { + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to find a mesh by name in this file", + SALOME::INTERNAL_ERROR); + } + } + // FIELD + else if (strncmp(aLocalPersistentID, "_MEDFIELD_",10) == 0) + { + // Field Name + string aFieldName; + CORBA::Long aNumOrdre, anIterNumber; + getFieldNameAndDtIt( aLocalPersistentID, aFieldName, aNumOrdre, anIterNumber ); + // Get a field that is already read + try { + object = med->getField( aFieldName.c_str(), anIterNumber, aNumOrdre ); + } + catch (const std::exception & ex) { + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to find a field by name in this file", + SALOME::INTERNAL_ERROR); + } + } + // SUPPORT? + else { + string type, name, meshName, entity; + if ( getSupportData( aLocalPersistentID, type, name, meshName, entity )) + { + MED_EN::medEntityMesh medEntity( atoi( entity.c_str() )); + + if ( type == "SUPPORT" ) { + try { + object = med_i->getSupport( meshName, medEntity ); + } + catch (const std::exception & ex) { + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to find support in this file", + SALOME::INTERNAL_ERROR); + } + } + else { + SALOME_MED::MESH_var mesh; + try { + mesh = med->getMeshByName( meshName.c_str() ); + } + catch (const std::exception & ex) { + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to find mesh in this file", + SALOME::INTERNAL_ERROR); + } + if ( !mesh->_is_nil() ) { + try { + if ( type == "FAMILY" ) { + SALOME_MED::Family_array_var families = mesh->getFamilies( medEntity ); + for ( int i = 0; CORBA::is_nil(object) && i <= families->length(); ++i ) + if ( families[ i ]->getName() == name ) + object = SALOME_MED::FAMILY::_duplicate( families[ i ]); + } + else { + SALOME_MED::Group_array_var groups = mesh->getGroups( medEntity ); + for ( int i = 0; CORBA::is_nil(object) && i <= groups->length(); ++i ) + if ( groups[ i ]->getName() == name ) + object = SALOME_MED::GROUP::_duplicate( groups[ i ]); + } + } + catch (const std::exception & ex) { + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to find support in this file", + SALOME::INTERNAL_ERROR); + } + } + } + } + } + if ( !CORBA::is_nil(object) ) + ior = _driver_orb->object_to_string( object ); + else + THROW_SALOME_CORBA_EXCEPTION("Unable to find the object in this file", + SALOME::INTERNAL_ERROR); + + } // !restoredByLoad + + return ior._retn(); +} + +//============================================================================= +/*! + * returns true, if can publish object + */ +//============================================================================= +bool Med_Gen_Driver_i::CanPublishInStudy (CORBA::Object_ptr theIOR) +{ + SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theIOR); + if ( !aMesh->_is_nil()) + return true; + SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(theIOR); + if ( !aField->_is_nil()) + return true; + //SALOME_MED::SUPPORT_var aSupport = SALOME_MED::SUPPORT::_narrow(theIOR); + //if ( !aSupport->_is_nil()) + // return true; + return false; +} + +//============================================================================= +/*! + * publish the given object + */ +//============================================================================= +SALOMEDS::SObject_ptr Med_Gen_Driver_i::PublishInStudy (SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) + throw (SALOME::SALOME_Exception) +{ + SALOMEDS::SObject_var aResultSO; + + if (CORBA::is_nil(theObject)) return aResultSO; + if (theStudy->_is_nil()) return aResultSO; + + SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder(); + SALOMEDS::SComponent_var aFather = theStudy->FindComponent(ComponentDataType()); + + if (aFather->_is_nil()) { + aFather = aBuilder->NewComponent(ComponentDataType()); + if (aFather->_is_nil()) return aResultSO; + + SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + //NRI aName->SetValue("MED"); + + CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog"); + SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = + SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); + SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType()); + if (!Comp->_is_nil()) { + aName->SetValue(Comp->componentusername()); + } + + aBuilder->DefineComponentInstance(aFather, GetComponentInstance()); + } + + if (CORBA::is_nil(theSObject)) { + SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theObject); + if (!aMesh->_is_nil()) { + aMesh->addInStudy(theStudy, aMesh); + } + else { + SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(theObject); + if (!aField->_is_nil()) { + aField->addInStudyToComponent(aFather, aField); + } + //else { + // SALOME_MED::SUPPORT_var aSupport = SALOME_MED::SUPPORT::_narrow(theObject); + // if (!aSupport->_is_nil()) + // aSupport->addInStudy(theStudy, aSupport); + //} + } + aResultSO = theStudy->FindObjectIOR(_driver_orb->object_to_string(theObject)); + } else { + //if (!theSObject->ReferencedObject(aResultSO)) + // THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM); + } + //aBuilder->Addreference(theObject, aResultSO); + return aResultSO._retn(); +} + +//============================================================================= +/*! + * returns true, if can copy the object + */ +//============================================================================= +CORBA::Boolean Med_Gen_Driver_i::CanCopy (SALOMEDS::SObject_ptr theObject) +{ + // Try to retrieve known by MED component mesh by given IOR + SALOMEDS::GenericAttribute_var anAttr; + if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false; + try { + CORBA::Object_var anObj = + _driver_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); + SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj); + // If the object is null one it can't be copied: return false + if (aMesh->_is_nil()) return false; + } catch(...) { + return false; + } + return true; +} + +//============================================================================= +/*! + * create copy of the object and put it to the stream + */ +//============================================================================= +SALOMEDS::TMPFile* Med_Gen_Driver_i::CopyFrom (SALOMEDS::SObject_ptr theObject, + CORBA::Long& theObjectID) +{ + // Declare a sequence of the byte to store the copied object + SALOMEDS::TMPFile_var aStreamFile; + + // Try to get GEOM_Shape object by given SObject + SALOMEDS::GenericAttribute_var anAttr; + if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return new SALOMEDS::TMPFile(0); + CORBA::String_var anIOR = CORBA::string_dup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); + CORBA::Object_var anObj = _driver_orb->string_to_object(anIOR); + SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj); + if (aMesh->_is_nil()) return new SALOMEDS::TMPFile(0); + + // Get a temporary directory to store a temporary file + CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str(); + // Create a list to store names of created files + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(1); + aSeq[0] = CORBA::string_dup(aMesh->getName()); + char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1]; + strcpy(aFullName, aTmpDir); + strcpy(aFullName+strlen(aTmpDir), aSeq[0]); + + long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,aFullName , aMesh->getName()); + aMesh->write(driverId,""); + + // aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false); + char* aFullName1 = new char[strlen(aTmpDir)+1]; + strcpy(aFullName1, aTmpDir); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aFullName1, aSeq.in(), false); + // SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); + SALOMEDS_Tool::RemoveTemporaryFiles(aFullName1, aSeq.in(), true); + + // Assign an ID = 1 the the type SALOME_MED::MESH + theObjectID = 1; + + return aStreamFile._retn(); +} + +//============================================================================= +/*! + * returns true, if can copy the object + */ +//============================================================================= +CORBA::Boolean Med_Gen_Driver_i::CanPaste (const char* theComponentName, CORBA::Long theObjectID) +{ + // The MED component can paste only objects copied by MED component + // and with the object type = 1 (mesh) + if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false; + return true; +} + +//============================================================================= +/*! + * returns true, if can copy the object + */ +//============================================================================= +SALOMEDS::SObject_ptr Med_Gen_Driver_i::PasteInto (const SALOMEDS::TMPFile& theStream, + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject) +{ + SALOMEDS::SObject_var aResultSO = SALOMEDS::SObject::_duplicate(theObject); + if (theStream.length() == 0) return aResultSO._retn(); + + SALOMEDS::Study_var aStudy = theObject->GetStudy(); + + CORBA::String_var aTmpDir = CORBA::string_dup(SALOMEDS_Tool::GetTmpDir().c_str()); + char* aFullName2 = new char[strlen(aTmpDir)+1]; + strcpy(aFullName2,aTmpDir); + // SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false); + SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aFullName2, false); + CORBA::String_var aMeshName = CORBA::string_dup(aSeq[0]); + char* aFullName = new char[strlen(aTmpDir)+strlen(aMeshName)+1]; + strcpy(aFullName, aTmpDir); + strcpy(aFullName+strlen(aTmpDir), aMeshName); + + MESH * myMesh= new MESH(); + // myMesh->setName(aMeshName.c_str()); + char* aFullMeshName = new char[strlen(aMeshName)+1]; + strcpy(aFullMeshName,aMeshName); + myMesh->setName(aFullMeshName); + MED_MESH_RDONLY_DRIVER myMeshDriver(aFullName, myMesh); + try { + myMeshDriver.setMeshName(aFullMeshName); + myMeshDriver.open(); + } catch (const std::exception & ex) { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + return aResultSO._retn(); + }; + try { + myMeshDriver.read(); + MESSAGE("apres read"); + myMeshDriver.close(); + } catch (const std::exception & ex) { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + return aResultSO._retn(); + }; + // set new mesh name, becouse now there are no possibility to operate meshes with the same names +// srand((unsigned int)time(NULL)); + int aRND = rand(); //Get a random number to present a name of a copied mesh + char aCopiedMeshName[127]; + sprintf(aCopiedMeshName,"MESH_COPY_%d",aRND); + myMesh->setName(aCopiedMeshName); + MESH_i * meshi = new MESH_i(myMesh); + SALOME_MED::MESH_ptr mesh = meshi->_this(); + // add the mesh object in study + meshi->addInStudy(aStudy,mesh); + // get the IOR attribute of just added mesh + CORBA::String_var anIORString = _driver_orb->object_to_string(mesh); + aResultSO = aStudy->FindObjectIOR(anIORString); + + char * aFullName1 = new char[strlen(aTmpDir)+1]; + strcpy(aFullName1,aTmpDir); + // SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); + SALOMEDS_Tool::RemoveTemporaryFiles(aFullName1, aSeq.in(), true); + + return aResultSO._retn(); +} diff --git a/src/MED/Med_Gen_Driver_i.hxx b/src/MED/Med_Gen_Driver_i.hxx new file mode 100644 index 000000000..a0110fcf8 --- /dev/null +++ b/src/MED/Med_Gen_Driver_i.hxx @@ -0,0 +1,119 @@ +// MED MED : implemetation of MED idl descriptions +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : Med_Gen_Driver_i.hxx +// Author : Paul RASCLE, EDF +// Module : MED + +#ifndef _MED_GEN_DRIVER_I_HXX_ +#define _MED_GEN_DRIVER_I_HXX_ + +#include +#include CORBA_SERVER_HEADER(MED_Gen) +#include CORBA_SERVER_HEADER(MED) +#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) + +#include CORBA_SERVER_HEADER(SALOMEDS_Attributes) + +#include "SALOME_Component_i.hxx" +#include "SALOME_NamingService.hxx" + +#include + +namespace MEDMEM { + class MED_i; +} + +class Med_Gen_Driver_i : public virtual POA_SALOME_MED::MED_Gen_Driver +{ +private: + Med_Gen_Driver_i(); + +public: + // Constructor and Destructor + Med_Gen_Driver_i(CORBA::ORB_ptr orb); + virtual ~Med_Gen_Driver_i(); + + // Get Med object of the study (for persistance) + static MEDMEM::MED_i* GetMED(SALOMEDS::SComponent_ptr theStudy); + + // inherited methods from SALOMEDS::Driver + + SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, + const char* theURL, + bool isMultiFile); + + CORBA::Boolean Load(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile); + CORBA::Boolean LoadASCII(SALOMEDS::SComponent_ptr theComponent, + const SALOMEDS::TMPFile& theStream, + const char* theURL, + bool isMultiFile); + + void Close(SALOMEDS::SComponent_ptr theComponent); + + char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, + const char* IORString, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII); + char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, + const char* aLocalPersistentID, + CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII) + throw(SALOME::SALOME_Exception); + + bool CanPublishInStudy(CORBA::Object_ptr theIOR); + + SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject, + CORBA::Object_ptr theObject, + const char* theName) throw (SALOME::SALOME_Exception); + + CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject); + SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID); + + CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID); + SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, + CORBA::Long theObjectID, + SALOMEDS::SObject_ptr theObject); + + // this method of SALOMEDS::Driver must be implemented in Component + //char* ComponentDataType(); + + // to be defined in Component + virtual Engines::Component_ptr GetComponentInstance() = 0; + +private: + static std::map _MedCorbaObj; + + CORBA::ORB_ptr _driver_orb; + +protected: + SALOME_NamingService *_NS; +}; + +#endif diff --git a/src/MED/Med_Gen_i.cxx b/src/MED/Med_Gen_i.cxx index 430cfd932..8af700ac5 100755 --- a/src/MED/Med_Gen_i.cxx +++ b/src/MED/Med_Gen_i.cxx @@ -17,8 +17,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // File : Med_Gen_i.cxx @@ -28,19 +27,21 @@ #include "Med_Gen_i.hxx" -#include "MEDMEM_Mesh_i.hxx" +#include "MEDMEM_Mesh.hxx" #include "MEDMEM_Med_i.hxx" #include "MEDMEM_FieldTemplate_i.hxx" #include "MEDMEM_Support_i.hxx" -#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Mesh_i.hxx" #include "MEDMEM_Field.hxx" + #include "MEDMEM_Med.hxx" #include "MEDMEM_MedMedDriver.hxx" #include "MEDMEM_MedMeshDriver.hxx" #include "MEDMEM_MedFieldDriver.hxx" #include "MEDMEM_define.hxx" #include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Grid.hxx" #include "Utils_SINGLETON.hxx" @@ -48,46 +49,47 @@ #include "Utils_CorbaException.hxx" #include "utilities.h" +#include "SALOMEDS_Tool.hxx" + #include #include #include #include #include + #include -#include "SALOMEDS_Tool.hxx" using namespace std; using namespace MEDMEM; // Initialisation des variables statiques - map Med_Gen_i::_MedCorbaObj; - string Med_Gen_i::_myFileName=""; - string Med_Gen_i::_saveFileName=""; +//string Med_Gen_i::_myFileName=""; +//string Med_Gen_i::_saveFileName=""; + Med_Gen_i* Med_Gen_i::_MEDGen = NULL; //============================================================================= /*! * default constructor: not for use */ //============================================================================= - -Med_Gen_i::Med_Gen_i() -{ - MESSAGE("Med_Gen_i::Med_Gen_i"); -} +//Med_Gen_i::Med_Gen_i() +//{ +// MESSAGE("Med_Gen_i::Med_Gen_i"); +//} //============================================================================= /*! * standard constructor */ //============================================================================= - -Med_Gen_i:: Med_Gen_i(CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, - const char *interfaceName) : - Engines_Component_i(orb, poa, contId, instanceName, interfaceName) +Med_Gen_i::Med_Gen_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName) + : Engines_Component_i(orb, poa, contId, instanceName, interfaceName), + Med_Gen_Driver_i(orb) { MESSAGE("activate object"); _thisObj = this ; @@ -95,18 +97,50 @@ Med_Gen_i:: Med_Gen_i(CORBA::ORB_ptr orb, _duringLoad=false; // get an NamingService interface - _NS = SINGLETON_::Instance() ; - ASSERT(SINGLETON_::IsAlreadyExisting()) ; - _NS->init_orb( _orb ) ; + //_NS = SINGLETON_::Instance() ; + //ASSERT(SINGLETON_::IsAlreadyExisting()) ; + //_NS->init_orb( _orb ) ; - _myMedI = 0; + //_myMedI = 0; + _MEDGen = this; } + //============================================================================= /*! - * private method : change a study name in SALOMEDS::Study_var + * Destructor */ //============================================================================= +Med_Gen_i::~Med_Gen_i() +{ + MESSAGE("Med_Gen_i::~Med_Gen_i"); +} + +//============================================================================= +/*! + * GetServant [ static ] + * + * Get servant of the CORBA object + */ +//============================================================================= +PortableServer::ServantBase_var Med_Gen_i::GetServant( CORBA::Object_ptr theObject ) +{ + if( CORBA::is_nil( theObject ) || !_MEDGen || CORBA::is_nil( _MEDGen->_poa ) ) + return NULL; + try { + PortableServer::Servant aServant = _MEDGen->_poa->reference_to_servant( theObject ); + return aServant; + } + catch (...) { + INFOS( "GetServant - Unknown exception was caught!!!" ); + return NULL; + } +} +//============================================================================= +/*! + * private method : change a study name in SALOMEDS::Study_var + */ +//============================================================================= SALOMEDS::Study_var Med_Gen_i::studyName2Study(const char* studyName) throw(SALOME::SALOME_Exception) { @@ -139,7 +173,6 @@ SALOMEDS::Study_var Med_Gen_i::studyName2Study(const char* studyName) * private method : add Med component in Study (Not MedGen ???) */ //============================================================================= - void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy) throw(SALOME::SALOME_Exception) { @@ -174,8 +207,6 @@ void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy) if (aLocked) myStudy->GetProperties()->SetLocked(true); myBuilder->CommitCommand(); } - - } //============================================================================= @@ -184,27 +215,33 @@ void Med_Gen_i::addInStudy(SALOMEDS::Study_var myStudy) */ //============================================================================= SALOME_MED::MED_ptr Med_Gen_i::readStructFile (const char* fileName, - const char* studyName) + const char* studyName) throw(SALOME::SALOME_Exception) { beginService("Med_Gen_i::readStructFile"); SCRUTE(fileName); SALOMEDS::Study_var myStudy = studyName2Study(studyName) ; -// if (!_duringLoad) addInStudy(myStudy) ; + //if (!_duringLoad) addInStudy(myStudy) ; SALOME_MED::MED_ptr myMedIOR ; try { // we create a new MED_i and add in study - MED_i * myMedI = new MED_i(); + //SALOMEDS::SComponent_var theComponent = myStudy->FindComponent("MED"); + //MED_i * myMedI = 0; + //if (CORBA::is_nil(theComponent)) + // myMedI = new MED_i(); + //else + // myMedI = Med_Gen_Driver_i::GetMED(theComponent); + MED_i * myMedI = new MED_i(); myMedIOR = myMedI->_this() ; // if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR) ; // if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR,fileName) ; // create ::MED object, read all and add in study ! myMedI->init(myStudy,MED_DRIVER,fileName) ; } - catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {} + catch (const SALOMEDS::StudyBuilder::LockProtection & ) {} catch(...) { MESSAGE("Erreur a la lecture du fichier"); @@ -224,7 +261,7 @@ SALOME_MED::MED_ptr Med_Gen_i::readStructFile (const char* fileName, //============================================================================= void Med_Gen_i::readStructFileWithFieldType (const char* fileName, const char* studyName) -throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { beginService("Med_Gen_i::readStructFileWithFieldType"); @@ -237,13 +274,19 @@ throw (SALOME::SALOME_Exception) try { // we create a new MED_i and add in study - MED_i * myMedI = new MED_i(); - SALOME_MED::MED_ptr myMedIOR = myMedI->_this() ; - if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR,fileName) ; + SALOMEDS::SComponent_var theComponent = myStudy->FindComponent("MED"); + //MED_i * myMedI = 0; + //if (CORBA::is_nil(theComponent)) + // myMedI = new MED_i(); + //else + // myMedI = Med_Gen_Driver_i::GetMED(theComponent); + MED_i * myMedI = new MED_i(); + SALOME_MED::MED_ptr myMedIOR = myMedI->_this(); + if (!_duringLoad) myMedI->addInStudy(myStudy,myMedIOR,theComponent,fileName); // create ::MED object, read all and add in study ! - myMedI->initWithFieldType(myStudy,MED_DRIVER,fileName) ; + myMedI->initWithFieldType(myStudy,MED_DRIVER,fileName); } - catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {} + catch (const SALOMEDS::StudyBuilder::LockProtection & ) {} catch(...) { MESSAGE("Erreur a la lecture du fichier"); @@ -253,8 +296,6 @@ throw (SALOME::SALOME_Exception) endService("Med_Gen_i::readStructFileWithFieldType"); END_OF("Med_Gen_i::readStructFileWithFieldType (const char* fileName,const char* studyName)"); - - } //============================================================================= @@ -275,7 +316,26 @@ throw (SALOME::SALOME_Exception) // Creation du maillage - MESH * myMesh= new MESH() ; + MESH * myMesh; + + // skl for IPAL14240 + // check mesh or grid: + try { + MED med(MED_DRIVER,fileName); + MESH* tmpMesh = med.getMesh(meshName); + if(tmpMesh) { + if(tmpMesh->getIsAGrid()) + myMesh = new GRID(); + else + myMesh = new MESH() ; + } + } + catch (const std::exception & ex) { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + myMesh = new MESH() ; + }; + myMesh->setName(meshName); MED_MESH_RDONLY_DRIVER myMeshDriver(fileName,myMesh); try @@ -283,7 +343,11 @@ throw (SALOME::SALOME_Exception) myMeshDriver.setMeshName(meshName); myMeshDriver.open(); } +#if defined(_DEBUG_) || defined(_DEBUG) catch (const std::exception & ex) +#else + catch (const std::exception &) +#endif { MESSAGE("Exception Interceptee : "); SCRUTE(ex.what()); @@ -295,7 +359,11 @@ throw (SALOME::SALOME_Exception) MESSAGE("apres read"); myMeshDriver.close(); } +#if defined(_DEBUG_) || defined(_DEBUG) catch (const std::exception & ex) +#else + catch (const std::exception &) +#endif { MESSAGE("Exception Interceptee : "); SCRUTE(ex.what()); @@ -310,21 +378,22 @@ throw (SALOME::SALOME_Exception) // add the mesh object in study // if (!_duringLoad) meshi->addInStudy(myStudy,mesh); } - catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {} + catch (const SALOMEDS::StudyBuilder::LockProtection & ) {} endService("Med_Gen_i::readMeshInFile"); return mesh; } + //============================================================================= /*! * Sert un Champ */ //============================================================================= SALOME_MED::FIELD_ptr Med_Gen_i::readFieldInFile(const char* fileName, - const char* studyName, - const char* fieldName, - CORBA::Long ordre, - CORBA::Long iter) + const char* studyName, + const char* fieldName, + CORBA::Long ordre, + CORBA::Long iter) throw (SALOME::SALOME_Exception) { beginService("Med_Gen_i::readFieldInFile"); @@ -384,7 +453,18 @@ throw (SALOME::SALOME_Exception) // Creation du champ FIELD_ * myField; - MED * mymed = new MED(MED_DRIVER,fileName) ; + MED * mymed; + try + { + mymed = new MED(MED_DRIVER,fileName) ; + } + catch (const std::exception & ex) + { + MESSAGE("Exception Interceptee : "); + SCRUTE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION("Unable to find this file ",SALOME::BAD_PARAM); + } + try { deque fieldsNames = mymed->getFieldNames() ; @@ -409,7 +489,11 @@ throw (SALOME::SALOME_Exception) */ myField = mymed->getField(fieldName,ordre,iter); } +#if defined(_DEBUG_) || defined(_DEBUG) catch (const std::exception & ex) +#else + catch (const std::exception &) +#endif { MESSAGE("Exception Interceptee : "); SCRUTE(ex.what()); @@ -427,7 +511,11 @@ throw (SALOME::SALOME_Exception) SCRUTE(myMesh->getName()); fieldSupport->update(); } +#if defined(_DEBUG_) || defined(_DEBUG) catch (const std::exception & ex) +#else + catch (const std::exception &) +#endif { MESSAGE("Exception Interceptee : "); SCRUTE(ex.what()); @@ -448,8 +536,12 @@ throw (SALOME::SALOME_Exception) endService("Med_Gen_i::readFieldInFile"); return myFieldIOR; } - catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {} + catch (const SALOMEDS::StudyBuilder::LockProtection &) {} +#if defined(_DEBUG_) || defined(_DEBUG) catch (const std::exception & ex) +#else + catch (const std::exception &) +#endif { MESSAGE("Exception Interceptee : "); SCRUTE(ex.what()); @@ -468,8 +560,13 @@ throw (SALOME::SALOME_Exception) endService("Med_Gen_i::readFieldInFile"); return myFieldIOR; } - catch (const SALOMEDS::StudyBuilder::LockProtection & lp) {} + catch (const SALOMEDS::StudyBuilder::LockProtection &) {} + +#if defined(_DEBUG_) || defined(_DEBUG) catch (const std::exception & ex) +#else + catch (const std::exception &) +#endif { MESSAGE("Exception Interceptee : "); SCRUTE(ex.what()); @@ -485,763 +582,20 @@ throw (SALOME::SALOME_Exception) //============================================================================= /*! - * Destructor - */ -//============================================================================= - -Med_Gen_i::~Med_Gen_i() -{ - MESSAGE("Med_Gen_i::~Med_Gen_i"); -} - -//============================================================================= -/*! - * CORBA: Save Mesh objects (called when a study is saved) - */ -//============================================================================= -SALOMEDS::TMPFile* Med_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile) { - const char* LOC = "Med_Gen_i::Save"; - BEGIN_OF(LOC); - - SALOMEDS::TMPFile_var aStreamFile; - // Get a temporary directory to store a file - TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); - // Create a list to store names of created files - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - TColStd_SequenceOfAsciiString aFileNames; - - CORBA::String_var aSaveStudyName(""); - if (isMultiFile) aSaveStudyName = CORBA::string_dup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str()); - - SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH"); - if (!CORBA::is_nil(aMedMeshFather)) { - SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather); - anIter->InitEx(1); - for(; anIter->More(); anIter->Next()) { - SALOMEDS::SObject_var aSO = anIter->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (aSO->FindAttribute(anAttr,"AttributeIOR")) { - CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); - if (! CORBA::is_nil(myMesh)) { - TCollection_AsciiString aName(aSaveStudyName); - aName += "_MEDMESH_"; - aName += myMesh->getName(); - aName += ".med"; - MESSAGE("Save mesh with name "<length(1); - aSeq[0]=CORBA::string_dup( aName.ToCString() ); - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - aSeq->length(0); - } - long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName()); - myMesh->write(driverId,""); - aFileNames.Append(aName); - } - } - } - } - - // temporary: until info that mesh is distant is written - MED_EN::medFileVersion curVersion = DRIVERFACTORY::getMedFileVersionForWriting(); - DRIVERFACTORY::setMedFileVersionForWriting( MED_EN::V21 ); - - SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD"); - if (!CORBA::is_nil(aMedFieldFather)) { - SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather); - anIter->InitEx(1); - for(; anIter->More(); anIter->Next()) { - SALOMEDS::SObject_var aSO = anIter->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (aSO->FindAttribute(anAttr,"AttributeIOR")) { - CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR); - if (! CORBA::is_nil(myField)) { - ostringstream a,b; - a<< myField->getOrderNumber(); - b<< myField->getIterationNumber(); - - TCollection_AsciiString aName(aSaveStudyName); - aName += "_MEDFIELD_"; - aName += myField->getName(); - aName += "_ORDRE_"; - aName += (char*)(a.str().c_str()); - aName += "_ITER_"; - aName += (char*)(b.str().c_str()); - aName += ".med"; - // Remove existing file - if (isMultiFile) { - aSeq->length(1); - aSeq[0]=CORBA::string_dup( aName.ToCString() ); - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - aSeq->length(0); - } - MESSAGE("Save field with name "<addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName()); - myField->write(driverId,""); - aFileNames.Append(aName); - } - } - } - } - DRIVERFACTORY::setMedFileVersionForWriting( curVersion ); - - int i; - aSeq->length(aFileNames.Length()); - for(i = aFileNames.Length(); i > 0; i--) - aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); - // Conver a file to the byte stream - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); - // Remove the created file and tmp directory - if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - // Return the created byte stream - return aStreamFile._retn(); - - END_OF(LOC); -} -SALOMEDS::TMPFile* Med_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile) { - const char* LOC = "Med_Gen_i::SaveASCII"; - BEGIN_OF(LOC); - - SALOMEDS::TMPFile_var aStreamFile; - // Get a temporary directory to store a file - TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); - // Create a list to store names of created files - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - TColStd_SequenceOfAsciiString aFileNames; - - CORBA::String_var aSaveStudyName(""); - if (isMultiFile) aSaveStudyName = CORBA::string_dup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str()); - - SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH"); - if (!CORBA::is_nil(aMedMeshFather)) { - SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather); - anIter->InitEx(1); - for(; anIter->More(); anIter->Next()) { - SALOMEDS::SObject_var aSO = anIter->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (aSO->FindAttribute(anAttr,"AttributeIOR")) { - CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); - if (! CORBA::is_nil(myMesh)) { - TCollection_AsciiString aName(aSaveStudyName); - aName += "_MEDMESH_"; - aName += myMesh->getName(); - aName += ".med"; - MESSAGE("Save mesh with name "<length(1); - aSeq[0]=CORBA::string_dup( aName.ToCString() ); - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - aSeq->length(0); - } - long driverId = myMesh->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myMesh->getName()); - myMesh->write(driverId,""); - HDFascii::ConvertFromHDFToASCII((aTmpDir+aName).ToCString(), true); - aFileNames.Append(aName); - } - } - } - } - - // temporary: until info that mesh is distant is written - MED_EN::medFileVersion curVersion = DRIVERFACTORY::getMedFileVersionForWriting(); - DRIVERFACTORY::setMedFileVersionForWriting( MED_EN::V21 ); - - SALOMEDS::SObject_var aMedFieldFather = theComponent->GetStudy()->FindObject("MEDFIELD"); - if (!CORBA::is_nil(aMedFieldFather)) { - SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedFieldFather); - anIter->InitEx(1); - for(; anIter->More(); anIter->Next()) { - SALOMEDS::SObject_var aSO = anIter->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (aSO->FindAttribute(anAttr,"AttributeIOR")) { - CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR); - if (! CORBA::is_nil(myField)) { - ostringstream a,b; - a<< myField->getOrderNumber(); - b<< myField->getIterationNumber(); - - TCollection_AsciiString aName(aSaveStudyName); - aName += "_MEDFIELD_"; - aName += myField->getName(); - aName += "_ORDRE_"; - aName += (char*)(a.str().c_str()); - aName += "_ITER_"; - aName += (char*)(b.str().c_str()); - aName += ".med"; - MESSAGE("Save field with name "<length(1); - aSeq[0]=CORBA::string_dup( aName.ToCString() ); - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - aSeq->length(0); - } - long driverId = myField->addDriver(SALOME_MED::MED_DRIVER,(aTmpDir+aName).ToCString(),myField->getName()); - myField->write(driverId,""); - HDFascii::ConvertFromHDFToASCII((aTmpDir+aName).ToCString(), true); - aFileNames.Append(aName); - } - } - } - } - DRIVERFACTORY::setMedFileVersionForWriting( curVersion ); - - int i; - aSeq->length(aFileNames.Length()); - for(i = aFileNames.Length(); i > 0; i--) - aSeq[i-1] = CORBA::string_dup(aFileNames.Value(i).ToCString()); - // Convert a file to the byte stream - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile); - // Remove the created file and tmp directory - if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - // Return the created byte stream - return aStreamFile._retn(); -} - -//============================================================================= -/*! - * CORBA: Load Mesh objects (called when an existing study is opened) + * from Driver */ //============================================================================= - -CORBA::Boolean Med_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile& theStream, - const char* theURL, - bool isMultiFile) { - const char* LOC = "Med_Gen_i::Load"; - BEGIN_OF(LOC); - - // Get a temporary directory for a file - TCollection_AsciiString aTmpDir = - (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); - _saveFileName = CORBA::string_dup(aTmpDir.ToCString()); - SALOMEDS::ListOfFileNames_var aSeq = - SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), isMultiFile); - return true; -} - -CORBA::Boolean Med_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile& theStream, - const char* theURL, - bool isMultiFile) { - return Load(theComponent, theStream, theURL, isMultiFile); -} - -//============================================================================= -/*! - * CORBA: - */ -//============================================================================= - -void Med_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent) +Engines::Component_ptr Med_Gen_i::GetComponentInstance() { - MESSAGE("Med_Gen_i::Close"); - SALOMEDS::SObject_var aMedMeshFather = theComponent->GetStudy()->FindObject("MEDMESH"); - if (!CORBA::is_nil(aMedMeshFather)) { - SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(aMedMeshFather); - for(; anIter->More(); anIter->Next()) { - SALOMEDS::SObject_var aSO = anIter->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (aSO->FindAttribute(anAttr,"AttributeIOR")) { - CORBA::Object_var myIOR = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); - // here must call method destroy of myMesh, but it not implented yet - } - } - } + return MED_Gen::_this(); } -//============================================================================= -/*! - * CORBA: - */ -//============================================================================= - char* Med_Gen_i::ComponentDataType() { MESSAGE("Med_Gen_i::ComponentDataType"); return CORBA::string_dup("MED") ; /* What is this type ? */ } -//============================================================================= -/*! - * CORBA: give a persistent reference of a transient object (for study save) - */ -//============================================================================= - -char* Med_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, - const char* IORString, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) { - const char * LOC = "Med_Gen_i::IORToLocalPersistentID" ; - BEGIN_OF(LOC) ; - SCRUTE(IORString); - - - if (string(IORString).size()==0) return CORBA::string_dup("_MED"); - // Well, we know where put object (_saveFilename) and we know object (IORString) - // cast object : - CORBA::Object_var myIOR = _orb->string_to_object(IORString); - - // MED - SALOME_MED::MED_var myMed = SALOME_MED::MED::_narrow(myIOR); - if (! CORBA::is_nil(myMed)) - { - // nothing to save : Support will be saved inside the mesh - string str_MedName="_MED Objet Med + /OBJ_MED/"; - return CORBA::string_dup(str_MedName.c_str()) ; - } - - // MESH - SALOME_MED::MESH_var myMesh = SALOME_MED::MESH::_narrow(myIOR); - if (! CORBA::is_nil(myMesh)) - { - CORBA::String_var aName((string("_MEDMESH_")+ myMesh->getName() + ".med").c_str()); - return aName._retn() ; - } - - // SUPPORT - SALOME_MED::SUPPORT_var mySupport = SALOME_MED::SUPPORT::_narrow(myIOR); - if (! CORBA::is_nil(mySupport)) - { - // nothing to save : Support will be saved inside the mesh - string str_SupportName; - try - { - str_SupportName=string("/FAS/")+string(mySupport->getName()); - str_SupportName+=string("/ENS_MAA/")+string(mySupport->getMesh()->getName()); - SCRUTE(str_SupportName); - } - catch(...) - { - MESSAGE("Unable to save the support"); - THROW_SALOME_CORBA_EXCEPTION("Unable to save Field in Med"\ - ,SALOME::INTERNAL_ERROR); - } - return CORBA::string_dup(("_MED"+str_SupportName).c_str()); - } - - SALOME_MED::FIELD_var myField = SALOME_MED::FIELD::_narrow(myIOR); - if (! CORBA::is_nil(myField)) - { - string str_FieldName; - ostringstream a,b; - a<< myField->getOrderNumber(); - b<< myField->getIterationNumber(); - CORBA::String_var aName((string("_MEDFIELD_")+ myField->getName() + - string("_ORDRE_")+a.str()+ - string("_ITER_")+b.str() + - ".med").c_str()); - return aName._retn(); - } - - //THROW_SALOME_CORBA_EXCEPTION("Unable to save IOR",SALOME::BAD_PARAM); - return CORBA::string_dup("_MED"); -} - -//======================================================================= -//function : getFieldNameAndDtIt -//purpose : -//======================================================================= - -static void getFieldNameAndDtIt( const char* aLocalPersistentID, - string & aFieldName, - CORBA::Long & aNumOrdre, - CORBA::Long & anIterNumber) -{ - // aLocalPersistentID(("_MEDFIELD_"+ myField->getName() + - // "_ORDRE_"+a.str()+ - // "_ITER_"+b.str()+".med" - int aLPIdLen = strlen(aLocalPersistentID); - const int _MEDFIELD_Len = strlen("_MEDFIELD_"); - const int _ORDRE_Len = strlen("_ORDRE_"); - const int _ITER_Len = strlen("_ITER_"); - - // Get field name: look for _ORDRE_ in aLocalPersistentID - int aFieldNameLen = 0, aFieldNameBeg = _MEDFIELD_Len, _ORDRE_Beg; - for ( _ORDRE_Beg = aFieldNameBeg; _ORDRE_Beg < aLPIdLen; ++aFieldNameLen,++_ORDRE_Beg ) - if ( strncmp( &aLocalPersistentID[ _ORDRE_Beg ], "_ORDRE_", _ORDRE_Len ) == 0 ) - break; - aFieldName = string( &(aLocalPersistentID[aFieldNameBeg]), aFieldNameLen); - - // Get orderNumber - int anOrderNumberBeg = _ORDRE_Beg + _ORDRE_Len; - aNumOrdre = atoi( & aLocalPersistentID[ anOrderNumberBeg ]); - - // Get iterationNumber: look for _ITER_ in aLocalPersistentID - int _ITER_Beg = anOrderNumberBeg; - for ( ; _ITER_Beg < aLPIdLen; ++_ITER_Beg ) - if ( strncmp( &aLocalPersistentID[ _ITER_Beg ], "_ITER_", _ITER_Len ) == 0 ) - break; - anIterNumber = atoi( & aLocalPersistentID[ _ITER_Beg + _ITER_Len ]); -} - -//============================================================================= -/*! - * CORBA: give a transient reference (when loading an object, opening study) - */ -//============================================================================= - -char* Med_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, - const char* aLocalPersistentID, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) - throw(SALOME::SALOME_Exception) -{ - const char * LOC = "Med_Gen_i::LocalPersistentIDToIOR" ; - BEGIN_OF(LOC) ; - - bool isMesh, isField; - isMesh = isField = false; - - if (strcmp(aLocalPersistentID, "_MED Objet Med + /OBJ_MED/") == 0) { // MED - _myMedI = new MED_i(); - SALOME_MED::MED_ptr myMedIOR = _myMedI->_this(); - return(CORBA::string_dup(_orb->object_to_string(myMedIOR))); - } - else if (strncmp(aLocalPersistentID, "_MEDMESH_",9) == 0) // MESH - isMesh = true; - else if (strncmp(aLocalPersistentID, "_MED/FAS/",9) == 0) // SUPPORT - return (CORBA::string_dup( theSObject->GetIOR() )); // is loaded along with MESH - else if (strncmp(aLocalPersistentID, "_MEDFIELD_",10) == 0) // FIELD - isField = true; - else - return CORBA::string_dup(""); - - // Get file name - char* aFileName; - TCollection_AsciiString aTmpDir((char*)(_saveFileName.c_str())); - TCollection_AsciiString aSaveStudyName(""); - if (isMultiFile) - aSaveStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()).c_str(); - if (isASCII) - { - char* aResultPath = HDFascii::ConvertFromASCIIToHDF((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString()); - aFileName = new char[strlen(aResultPath) + 19]; - sprintf(aFileName, "%shdf_from_ascii.hdf", aResultPath); - delete(aResultPath); - } - else - aFileName = CORBA::string_dup((aTmpDir + aSaveStudyName + (char*)aLocalPersistentID).ToCString()); - - // Read file structure - try - { - ASSERT( _myMedI ); - CORBA::Long drvId = _myMedI->addDriver( SALOME_MED::MED_DRIVER, aFileName ); - _myMedI->readFileStruct( drvId ); - } - catch (const std::exception & ex) - { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - THROW_SALOME_CORBA_EXCEPTION("Unable to read a hdf file",SALOME::BAD_PARAM); - }; - - CORBA::Object_ptr anIOR; - - if ( isMesh ) {// MESH - // Get mesh name - int aMeshNameLen = strlen(aLocalPersistentID) - 12; - string aMeshName( &(aLocalPersistentID[9]), aMeshNameLen); - aMeshName[aMeshNameLen-1] = 0; - - // Read mesh - SALOME_MED::MESH_ptr mesh; - try - { - mesh = _myMedI->getMeshByName( aMeshName.c_str() ); - mesh->read( 0 ); - _myMedI->updateSupportIORs( theSObject->GetStudy(), aMeshName.c_str() ); - } - catch (const std::exception & ex) - { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - THROW_SALOME_CORBA_EXCEPTION("Unable to read this mesh in this file", - SALOME::INTERNAL_ERROR); - } - - anIOR = mesh; - } - - if ( isField ) { // FIELD - - // Field Name - string aFieldName; - CORBA::Long aNumOrdre, anIterNumber; - getFieldNameAndDtIt( aLocalPersistentID, aFieldName, aNumOrdre, anIterNumber ); - - // Read field - SALOME_MED::FIELD_ptr field; - try - { - field = _myMedI->getField( aFieldName.c_str(), anIterNumber, aNumOrdre ); - field->read( 0 ); - } - catch (const std::exception & ex) - { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - THROW_SALOME_CORBA_EXCEPTION("Unable to read this field in this file", - SALOME::INTERNAL_ERROR); - } - - anIOR = field; - - } - - // Remove tmp files - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(1); - aSeq[0]=CORBA::string_dup(aLocalPersistentID); - if (!isMultiFile) - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true); - if (isASCII) - { - SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames; - aFilesToRemove->length(1); - aFilesToRemove[0] = CORBA::string_dup(&(aFileName[strlen(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str())])); - SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aFileName).c_str(), aFilesToRemove, true); - } - - delete(aFileName); - - if ( CORBA::is_nil( anIOR )) - return CORBA::string_dup(""); - - return(CORBA::string_dup(_orb->object_to_string( anIOR ))); -} - -//============================================================================= -/*! - * returns true, if can publish object - */ -//============================================================================= -bool Med_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) { - SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theIOR); - if ( !aMesh->_is_nil()) - return true; - SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(theIOR); - if ( !aField->_is_nil()) - return true; -// SALOME_MED::SUPPORT_var aSupport = SALOME_MED::SUPPORT::_narrow(theIOR); -// if ( !aSupport->_is_nil()) -// return true; - return false; -} - -//============================================================================= -/*! - * publish the given object - */ -//============================================================================= -SALOMEDS::SObject_ptr Med_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theObject, - const char* theName) throw (SALOME::SALOME_Exception) -{ - SALOMEDS::SObject_var aResultSO; - - if(CORBA::is_nil(theObject)) return aResultSO; - if(theStudy->_is_nil()) return aResultSO; - - SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::SComponent_var aFather = theStudy->FindComponent("MED"); - - if (aFather->_is_nil()) { - aFather = aBuilder->NewComponent("MED"); - if (aFather->_is_nil()) return aResultSO; - anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - //NRI aName->SetValue("MED"); - - CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog"); - SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN); - SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( "MED" ); - if ( !Comp->_is_nil() ) { - aName->SetValue( Comp->componentusername() ); - } - aBuilder->DefineComponentInstance(aFather, MED_Gen::_this()); - } - - if (CORBA::is_nil(theSObject)) { - SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(theObject); - if ( !aMesh->_is_nil() ) - aMesh->addInStudy(theStudy, aMesh); - SALOME_MED::FIELD_var aField = SALOME_MED::FIELD::_narrow(theObject); - if ( !aField->_is_nil()) - aField->addInStudy(theStudy, aField); -// SALOME_MED::SUPPORT_var aSupport = SALOME_MED::SUPPORT::_narrow(theObject); -// if ( !aSupport->_is_nil()) -// aSupport->addInStudy(theStudy, aSupport); - aResultSO = theStudy->FindObjectIOR(_orb->object_to_string(theObject)); - } else { -// if (!theSObject->ReferencedObject(aResultSO)) -// THROW_SALOME_CORBA_EXCEPTION("Publish in study MED object error",SALOME::BAD_PARAM); - } -// aBuilder->Addreference(theObject, aResultSO); - return aResultSO._retn(); -} - -//============================================================================= -/*! - * returns true, if can copy the object - */ -//============================================================================= -CORBA::Boolean Med_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) { - // Try to retrieve known by MED component mesh by given IOR - SALOMEDS::GenericAttribute_var anAttr; - if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false; - try { - CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj); - // If the object is null one it can't be copied: return false - if (aMesh->_is_nil()) return false; - } catch(...) { - return false; - } - return true; -} - -//============================================================================= -/*! - * create copy of the object and put it to the stream - */ -//============================================================================= -SALOMEDS::TMPFile* Med_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) { - // Declare a sequence of the byte to store the copied object - SALOMEDS::TMPFile_var aStreamFile; - - // Try to get GEOM_Shape object by given SObject - SALOMEDS::GenericAttribute_var anAttr; - if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return new SALOMEDS::TMPFile(0); - CORBA::String_var anIOR = CORBA::string_dup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()); - CORBA::Object_var anObj = _orb->string_to_object(anIOR); - SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj); - if (aMesh->_is_nil()) return new SALOMEDS::TMPFile(0); - - // Get a temporary directory to store a temporary file - CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str(); - // Create a list to store names of created files - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(1); - aSeq[0] = CORBA::string_dup(aMesh->getName()); - char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1]; - strcpy(aFullName, aTmpDir); - strcpy(aFullName+strlen(aTmpDir), aSeq[0]); - - long driverId = aMesh->addDriver(SALOME_MED::MED_DRIVER,aFullName , aMesh->getName()); - aMesh->write(driverId,""); - - // aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), false); - char* aFullName1 = new char[strlen(aTmpDir)+1]; - strcpy(aFullName1, aTmpDir); - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aFullName1, aSeq.in(), false); - // SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); - SALOMEDS_Tool::RemoveTemporaryFiles(aFullName1, aSeq.in(), true); - - // Assign an ID = 1 the the type SALOME_MED::MESH - theObjectID = 1; - - return aStreamFile._retn(); -} - -//============================================================================= -/*! - * returns true, if can copy the object - */ -//============================================================================= -CORBA::Boolean Med_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) { - // The MED component can paste only objects copied by MED component - // and with the object type = 1 (mesh) - if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false; - return true; -} - -//============================================================================= -/*! - * returns true, if can copy the object - */ -//============================================================================= -SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, - CORBA::Long theObjectID, - SALOMEDS::SObject_ptr theObject) { - SALOMEDS::SObject_var aResultSO = SALOMEDS::SObject::_duplicate(theObject); - if (theStream.length() == 0) return aResultSO._retn(); - - SALOMEDS::Study_var aStudy = theObject->GetStudy(); - - CORBA::String_var aTmpDir = CORBA::string_dup(SALOMEDS_Tool::GetTmpDir().c_str()); - char* aFullName2 = new char[strlen(aTmpDir)+1]; - strcpy(aFullName2,aTmpDir); - // SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false); - SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aFullName2, false); - CORBA::String_var aMeshName = CORBA::string_dup(aSeq[0]); - char* aFullName = new char[strlen(aTmpDir)+strlen(aMeshName)+1]; - strcpy(aFullName, aTmpDir); - strcpy(aFullName+strlen(aTmpDir), aMeshName); - - MESH * myMesh= new MESH() ; - // myMesh->setName(aMeshName.c_str()); - char* aFullMeshName = new char[strlen(aMeshName)+1]; - strcpy(aFullMeshName,aMeshName); - myMesh->setName(aFullMeshName); - MED_MESH_RDONLY_DRIVER myMeshDriver(aFullName, myMesh); - try { - myMeshDriver.setMeshName(aFullMeshName); - myMeshDriver.open(); - } catch (const std::exception & ex) { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - return aResultSO._retn(); - }; - try { - myMeshDriver.read(); - MESSAGE("apres read"); - myMeshDriver.close(); - } catch (const std::exception & ex) { - MESSAGE("Exception Interceptee : "); - SCRUTE(ex.what()); - return aResultSO._retn(); - }; - // set new mesh name, becouse now there are no possibility to operate meshes with the same names -// srand((unsigned int)time(NULL)); - int aRND = rand(); //Get a random number to present a name of a copied mesh - char aCopiedMeshName[20]; - sprintf(aCopiedMeshName,"MESH_COPY_%d",aRND); - myMesh->setName(aCopiedMeshName); - MESH_i * meshi = new MESH_i(myMesh); - SALOME_MED::MESH_ptr mesh = meshi->_this(); - // add the mesh object in study - meshi->addInStudy(aStudy,mesh); - // get the IOR attribute of just added mesh - CORBA::String_var anIORString = _orb->object_to_string(mesh); - aResultSO = aStudy->FindObjectIOR(anIORString); - - char * aFullName1 = new char[strlen(aTmpDir)+1]; - strcpy(aFullName1,aTmpDir); - // SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); - SALOMEDS_Tool::RemoveTemporaryFiles(aFullName1, aSeq.in(), true); - return aResultSO._retn(); -} - - - - //============================================================================= @@ -1250,19 +604,17 @@ SALOMEDS::SObject_ptr Med_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream, */ //============================================================================= -extern "C" -{ +extern "C" MED_EXPORT PortableServer::ObjectId * MEDEngine_factory( CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, PortableServer::ObjectId * contId, const char *instanceName, const char *interfaceName) - { - MESSAGE("PortableServer::ObjectId * MedEngine_factory()"); - SCRUTE(interfaceName); - Med_Gen_i * myMed_Gen - = new Med_Gen_i(orb, poa, contId, instanceName, interfaceName); - return myMed_Gen->getId() ; - } +{ + MESSAGE("PortableServer::ObjectId * MedEngine_factory()"); + SCRUTE(interfaceName); + Med_Gen_i * myMed_Gen + = new Med_Gen_i(orb, poa, contId, instanceName, interfaceName); + return myMed_Gen->getId() ; } diff --git a/src/MED/Med_Gen_i.hxx b/src/MED/Med_Gen_i.hxx index e5a61657f..59158af75 100644 --- a/src/MED/Med_Gen_i.hxx +++ b/src/MED/Med_Gen_i.hxx @@ -1,30 +1,28 @@ // MED MED : implemetation of MED idl descriptions // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // File : Med_Gen_i.hxx // Author : Paul RASCLE, EDF // Module : MED -// $Header$ #ifndef _MED_GEN_I_HXX_ #define _MED_GEN_I_HXX_ @@ -40,13 +38,34 @@ #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) +#include "Med_Gen_Driver_i.hxx" + namespace MEDMEM { class MED_i; } -class Med_Gen_i: +#ifdef WNT + #if defined MED_EXPORTS + #if defined WIN32 + #define MED_EXPORT __declspec( dllexport ) + #else + #define MED_EXPORT + #endif + #else + #if defined WIN32 + #define MED_EXPORT __declspec( dllimport ) + #else + #define MED_EXPORT + #endif + #endif +#else + #define MED_EXPORT +#endif + +class MED_EXPORT Med_Gen_i: public POA_SALOME_MED::MED_Gen, - public Engines_Component_i + public Engines_Component_i, + public Med_Gen_Driver_i { private: SALOMEDS::Study_var studyName2Study(const char* studyName) @@ -55,11 +74,11 @@ private: throw(SALOME::SALOME_Exception); public: - Med_Gen_i(); + //Med_Gen_i(); Med_Gen_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char *instanceName, + PortableServer::ObjectId * contId, + const char *instanceName, const char *interfaceName); virtual ~Med_Gen_i(); @@ -67,84 +86,53 @@ public: SALOME_MED::MESH_ptr readMeshInFile(const char* fileName, const char* studyName, const char* meshName) - throw(SALOME::SALOME_Exception); + throw(SALOME::SALOME_Exception); SALOME_MED::FIELD_ptr readFieldInFile(const char* fileName, - const char* studyName, - const char* fieldName, - CORBA::Long ordre, - CORBA::Long iter) - throw(SALOME::SALOME_Exception); + const char* studyName, + const char* fieldName, + CORBA::Long ordre, + CORBA::Long iter) + throw(SALOME::SALOME_Exception); SALOME_MED::MED_ptr readStructFile(const char* fileName, - const char* studyName) - throw(SALOME::SALOME_Exception); + const char* studyName) + throw(SALOME::SALOME_Exception); void readStructFileWithFieldType(const char* fileName, const char* studyName) - throw(SALOME::SALOME_Exception); - - // inherited methods from SALOMEDS::Driver - -// void Save(const char *IORSComponent, const char *aUrlOfFile); -// void Load(const char *IORSComponent, const char *aUrlOfFile); - SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile); - SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile); - - CORBA::Boolean Load(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile& theStream, - const char* theURL, - bool isMultiFile); - CORBA::Boolean LoadASCII(SALOMEDS::SComponent_ptr theComponent, - const SALOMEDS::TMPFile& theStream, - const char* theURL, - bool isMultiFile); - - void Close(SALOMEDS::SComponent_ptr theComponent); - char* ComponentDataType(); - - char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, - const char* IORString, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII); - char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, - const char* aLocalPersistentID, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII) throw(SALOME::SALOME_Exception); - bool CanPublishInStudy(CORBA::Object_ptr theIOR); - - SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theObject, - const char* theName) throw (SALOME::SALOME_Exception) ; - - CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject); - SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID); - CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID); - SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, - CORBA::Long theObjectID, - SALOMEDS::SObject_ptr theObject); - - private : - static std::map _MedCorbaObj; - static std::string _myFileName; - static std::string _saveFileName; - - private: + // Get last created instance of the class + static Med_Gen_i* GetMEDGen() { return _MEDGen; } + + // Get Med of the study (for persistance) + static SALOME_MED::MED_ptr GetMED(SALOMEDS::SComponent_ptr theStudy); + + // Get object of the CORBA reference + static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject ); + + template + static T DownCast(CORBA::Object_ptr theArg) + { + return dynamic_cast(GetServant(theArg).in()); + } + + // (re)defined methods of Driver + char* ComponentDataType(); + virtual Engines::Component_ptr GetComponentInstance(); + +private: + //static std::string _myFileName; + //static std::string _saveFileName; + static Med_Gen_i* _MEDGen; // Point to last created instance of the class + +private: bool _duringLoad; - int _myStudyID; - std::string _myStudyName; - - int myCounter; - SALOME_NamingService *_NS; + //int _myStudyID; + //std::string _myStudyName; - MEDMEM::MED_i* _myMedI; // used while loading a study + //int myCounter; }; #endif diff --git a/src/MED/Med_Gen_test.py b/src/MED/Med_Gen_test.py index 98616fad0..1750d498c 100644 --- a/src/MED/Med_Gen_test.py +++ b/src/MED/Med_Gen_test.py @@ -130,7 +130,7 @@ medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED") import os filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" filePathName = filePath + fileName diff --git a/src/MED/testMedAlliances.py b/src/MED/testMedAlliances.py index f18dad3a1..a30672609 100755 --- a/src/MED/testMedAlliances.py +++ b/src/MED/testMedAlliances.py @@ -3,7 +3,7 @@ import SALOME import os filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" import string @@ -126,13 +126,37 @@ medFiles.append("H_Traces_I129_COUPLEX1.med") medFiles.append("H_Traces_Se79_COUPLEX1.med") medFiles.append("maillage_5_5_5.med") medFiles.append("maillage_chemvalIV_cas1_40elts.med") +medFiles.append("Old_ChampsDarcy.med") +medFiles.append("Old_darcy_1.1_res.med") +medFiles.append("Old_darcy_1.3_resCASTEM.med") +medFiles.append("Old_darcy_1.3_resPORFLOW.med") +medFiles.append("Old_darcy_1.3_resTRACES.med") +medFiles.append("Old_darcy2_Castem_EFMH.med") +medFiles.append("Old_darcy2_Castem_qua_EFMH.med") +medFiles.append("Old_darcy2_Castem_qua_VF.med") +medFiles.append("Old_Deff_fdt_5.8_castem_efmh_diff_conc_dom.med") +medFiles.append("Old_Deff_fdt_5.8_castem_vf_diff_conc_dom.med") +medFiles.append("Old_H_CastCast_EFMH_I129_COUPLEX1.med") +medFiles.append("Old_H_CastCast_VF_I129_COUPLEX1.med") +medFiles.append("Old_H_CastCast_VF_Se79_COUPLEX1.med") +medFiles.append("Old_H_CastPorf_I129_COUPLEX1.med") +medFiles.append("Old_H_CastPorf_Se79_COUPLEX1.med") +medFiles.append("Old_H_PorfCast_EFMH_I129_COUPLEX1.med") +medFiles.append("Old_H_PorfCast_EFMH_Se79_COUPLEX1.med") +medFiles.append("Old_H_PorfPorf_I129_COUPLEX1.med") +medFiles.append("Old_H_PorfPorf_Se79_COUPLEX1.med") +medFiles.append("Old_H_Traces_I129_COUPLEX1.med") +medFiles.append("Old_H_Traces_Se79_COUPLEX1.med") +medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med") nbOfFiles = len(medFiles) -med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED") +med = salome.lcc.FindOrLoadComponent("FactoryServer", "MED") for i in range(nbOfFiles): - medFile = filePath + medFiles[i] + medFile = medFiles[i] + print "Testing with the file ",medFile + medFile = filePath + medFile med.readStructFile(medFile,salome.myStudyName) print "END of the Pyhton script ..... Ctrl D to exit" diff --git a/src/MED/testMedAlliances1.py b/src/MED/testMedAlliances1.py index e4e0c4e2c..bbd2a004b 100755 --- a/src/MED/testMedAlliances1.py +++ b/src/MED/testMedAlliances1.py @@ -3,7 +3,7 @@ import SALOME import os filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" import string @@ -126,13 +126,37 @@ medFiles.append("H_Traces_I129_COUPLEX1.med") medFiles.append("H_Traces_Se79_COUPLEX1.med") medFiles.append("maillage_5_5_5.med") medFiles.append("maillage_chemvalIV_cas1_40elts.med") +medFiles.append("Old_ChampsDarcy.med") +medFiles.append("Old_darcy_1.1_res.med") +medFiles.append("Old_darcy_1.3_resCASTEM.med") +medFiles.append("Old_darcy_1.3_resPORFLOW.med") +medFiles.append("Old_darcy_1.3_resTRACES.med") +medFiles.append("Old_darcy2_Castem_EFMH.med") +medFiles.append("Old_darcy2_Castem_qua_EFMH.med") +medFiles.append("Old_darcy2_Castem_qua_VF.med") +medFiles.append("Old_Deff_fdt_5.8_castem_efmh_diff_conc_dom.med") +medFiles.append("Old_Deff_fdt_5.8_castem_vf_diff_conc_dom.med") +medFiles.append("Old_H_CastCast_EFMH_I129_COUPLEX1.med") +medFiles.append("Old_H_CastCast_VF_I129_COUPLEX1.med") +medFiles.append("Old_H_CastCast_VF_Se79_COUPLEX1.med") +medFiles.append("Old_H_CastPorf_I129_COUPLEX1.med") +medFiles.append("Old_H_CastPorf_Se79_COUPLEX1.med") +medFiles.append("Old_H_PorfCast_EFMH_I129_COUPLEX1.med") +medFiles.append("Old_H_PorfCast_EFMH_Se79_COUPLEX1.med") +medFiles.append("Old_H_PorfPorf_I129_COUPLEX1.med") +medFiles.append("Old_H_PorfPorf_Se79_COUPLEX1.med") +medFiles.append("Old_H_Traces_I129_COUPLEX1.med") +medFiles.append("Old_H_Traces_Se79_COUPLEX1.med") +medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med") nbOfFiles = len(medFiles) med=salome.lcc.FindOrLoadComponent("FactoryServer", "MED") for i in range(nbOfFiles): - medFile = filePath + medFiles[i] - med.readStructFileWithFieldType(medFile,salome.myStudyName) + medFile = medFiles[i] + print "Testing with the file ",medFile + medFile = filePath + medFile + med.readStructFileWithFieldType(medFile,salome.myStudyName) print "END of the Pyhton script ..... Ctrl D to exit" diff --git a/src/MEDGUI/MED_msg_en.po b/src/MEDGUI/MED_msg_en.po index c74756afc..e6348cf98 100644 --- a/src/MEDGUI/MED_msg_en.po +++ b/src/MEDGUI/MED_msg_en.po @@ -127,23 +127,23 @@ msgstr "Popup test" msgid "STB_POPUPTEST" msgstr "Popup test" -msgid "TOP_ERASE" -msgstr "Erase" +msgid "TOP_HIDE" +msgstr "Hide" -msgid "MEN_ERASE" -msgstr "Erase" +msgid "MEN_HIDE" +msgstr "Hide" -msgid "STB_ERASE" -msgstr "Erase" +msgid "STB_HIDE" +msgstr "Hide" -msgid "TOP_DISPLAY" -msgstr "Display" +msgid "TOP_SHOW" +msgstr "Show" -msgid "MEN_DISPLAY" -msgstr "Display" +msgid "MEN_SHOW" +msgstr "Show" -msgid "STB_DISPLAY" -msgstr "Display" +msgid "STB_SHOW" +msgstr "Show" diff --git a/src/MEDGUI/Makefile.am b/src/MEDGUI/Makefile.am new file mode 100644 index 000000000..5c04834c4 --- /dev/null +++ b/src/MEDGUI/Makefile.am @@ -0,0 +1,47 @@ +# MED MEDGUI : MED component GUI implemetation +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# Libraries targets +lib_LTLIBRARIES= libMED.la +dist_libMED_la_SOURCES= MedGUI.cxx MedGUI_Selection.cxx +MOC_FILES= MedGUI_moc.cxx +nodist_libMED_la_SOURCES= $(MOC_FILES) +EXTRA_DIST+= MedGUI_Selection.h MedGUI.h + +libMED_la_CPPFLAGS= $(QT_INCLUDES) $(VTK_INCLUDES) @CAS_CPPFLAGS@ $(PYTHON_INCLUDES) \ + ${KERNEL_CXXFLAGS} ${GUI_CXXFLAGS} ${BOOST_CPPFLAGS} \ + @CORBA_INCLUDES@ @CORBA_CXXFLAGS@ \ + -I$(top_builddir)/idl -I$(top_builddir)/salome_adm/unix + +libMED_la_LDFLAGS= \ + ../../idl/libSalomeIDLMED.la \ + $(KERNEL_LDFLAGS) -lSalomeLifeCycleCORBA \ + $(GUI_LDFLAGS) -lSalomeApp + +# .po files to transform in .qm +nodist_salomeres_DATA= \ + MED_images.qm \ + MED_msg_fr.qm \ + MED_msg_en.qm diff --git a/src/MEDGUI/Makefile.in b/src/MEDGUI/Makefile.in deleted file mode 100644 index 600ee4fb4..000000000 --- a/src/MEDGUI/Makefile.in +++ /dev/null @@ -1,68 +0,0 @@ -# MED MEDGUI : MED component GUI implemetation -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Paul RASCLE, EDF -# Module : MED -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir):$(top_srcdir)/idl:$(top_builddir)/idl - -@COMMENCE@ - -# header files -EXPORT_HEADERS= - -# .po files to transform in .qm -PO_FILES = \ - MED_images.po \ - MED_msg_fr.po \ - MED_msg_en.po \ - - -# Libraries targets -LIB = libMED.la -LIB_SRC = MedGUI.cxx MedGUI_Selection.cxx -LIB_MOC = MedGUI.h - -LIB_CLIENT_IDL = SALOMEDS.idl SALOME_Exception.idl SALOME_Component.idl \ - MED_Gen.idl MED.idl \ - SALOMEDS_Attributes.idl SALOME_Comm.idl SALOME_GenericObj.idl -# SMESH_Mesh.idl SMESH_Hypothesis.idl SMESH_BasicHypothesis.idl \ -# GEOM_Shape.idl SALOMEDS_Attributes.idl - -LIB_SERVER_IDL = - -# additionnal information to compil and link file - -CPPFLAGS += $(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) ${KERNEL_CXXFLAGS} ${GUI_CXXFLAGS} ${BOOST_CPPFLAGS} - -LDFLAGS += -lSalomeApp -lMEDMEMImpl -lmedmem -lMEDEngine ${KERNEL_LDFLAGS} ${GUI_LDFLAGS} - -MED.hh MEDSK.cc: MED.idl - omniidl -bcxx -Wbtp -I$(top_builddir)/idl -I${KERNEL_ROOT_DIR}/idl/salome $^ - -@CONCLUDE@ diff --git a/src/MEDGUI/MedGUI.cxx b/src/MEDGUI/MedGUI.cxx index 916a12a3d..56f980685 100644 --- a/src/MEDGUI/MedGUI.cxx +++ b/src/MEDGUI/MedGUI.cxx @@ -186,10 +186,14 @@ void MedGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& QString MedGUI::engineIOR() const { + QString anIOR( "" ); SALOME_MED::MED_Gen_ptr aMedGen = InitMedGen(); if ( !CORBA::is_nil( aMedGen) ) - return QString( getApp()->orb()->object_to_string( aMedGen )); - return QString( "" ); + { + CORBA::String_var objStr = getApp()->orb()->object_to_string( aMedGen ); + anIOR = QString( objStr.in() ); + } + return anIOR; } void MedGUI::windows( QMap& mappa ) const @@ -732,7 +736,7 @@ bool MedGUI::DumpMesh( SALOME_MED::MESH_var MEDMesh) int nbelemnts=Families[k]->getNumberOfElements(SALOME_MED::MED_NONE); SCRUTE(nbelemnts); SALOME_MED::long_array_var tabnoeuds=Families[k]->getNumber(SALOME_MED::MED_NONE); - for (int l=0;llength();l++) + for (int l=0;l<(int)tabnoeuds->length();l++) SCRUTE(tabnoeuds[l]); } @@ -782,7 +786,7 @@ bool MedGUI::DumpSubMesh( SALOME_MED::FAMILY_var Fam ) return false; SALOME_MED::long_array_var tabnoeuds=Fam->getNumber(SALOME_MED::MED_NONE); - for (int l=0;llength();l++) + for (int l=0;l<(int)tabnoeuds->length();l++) SCRUTE(tabnoeuds[l]); return true; diff --git a/src/MEDMEM/DataTest/Data/maill.0.med b/src/MEDMEM/DataTest/Data/maill.0.med index e5a7b130d..4994e63a1 100644 Binary files a/src/MEDMEM/DataTest/Data/maill.0.med and b/src/MEDMEM/DataTest/Data/maill.0.med differ diff --git a/src/MEDMEM/DataTest/Data/mesh.med b/src/MEDMEM/DataTest/Data/mesh.med index 5f7a25c55..54bdd1b16 100755 Binary files a/src/MEDMEM/DataTest/Data/mesh.med and b/src/MEDMEM/DataTest/Data/mesh.med differ diff --git a/src/MEDMEM/DataTest/Data/pointe.med b/src/MEDMEM/DataTest/Data/pointe.med index 430a74bd6..0dbc1e8fb 100644 Binary files a/src/MEDMEM/DataTest/Data/pointe.med and b/src/MEDMEM/DataTest/Data/pointe.med differ diff --git a/src/MEDMEM/DataTest/Data/zzzz121b.med b/src/MEDMEM/DataTest/Data/zzzz121b.med index b28cebd2d..9b664636b 100644 Binary files a/src/MEDMEM/DataTest/Data/zzzz121b.med and b/src/MEDMEM/DataTest/Data/zzzz121b.med differ diff --git a/src/MEDMEM/MEDMEM.hxx b/src/MEDMEM/MEDMEM.hxx new file mode 100755 index 000000000..5017496e5 --- /dev/null +++ b/src/MEDMEM/MEDMEM.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM.hxx +// Author : Alexander A. BORODIN +// Module : MED + +#ifndef _MEDMEM_HXX_ +#define _MEDMEM_HXX_ + +#ifdef WNT + #if defined MEDMEM_EXPORTS + #if defined WIN32 + #define MEDMEM_EXPORT __declspec( dllexport ) + #else + #define MEDMEM_EXPORT + #endif + #else + #if defined WIN32 + #define MEDMEM_EXPORT __declspec( dllimport ) + #else + #define MEDMEM_EXPORT + #endif + #endif +#else + #define MEDMEM_EXPORT +#endif + +#endif diff --git a/src/MEDMEM/MEDMEM_Array.hxx b/src/MEDMEM/MEDMEM_Array.hxx index 65dd5a21f..0315653b1 100644 --- a/src/MEDMEM/MEDMEM_Array.hxx +++ b/src/MEDMEM/MEDMEM_Array.hxx @@ -337,9 +337,7 @@ template MEDARRAY::MEDARRAY(MEDARRAY const & p,bool copyOther ): // ------------------ -// /*! This operator does a copy of pointers\n -// It DOES NOT copy of the memory. -// The two objects will share data.\n */ +/*! This operator makes a deep copy of the arrays.\n */ template MEDARRAY & MEDARRAY::operator = (const MEDARRAY & m) { diff --git a/src/MEDMEM/MEDMEM_ArrayConvert.hxx b/src/MEDMEM/MEDMEM_ArrayConvert.hxx index 85749787e..891fe50b7 100644 --- a/src/MEDMEM/MEDMEM_ArrayConvert.hxx +++ b/src/MEDMEM/MEDMEM_ArrayConvert.hxx @@ -89,6 +89,74 @@ ArrayConvert( }; +template +MEDMEM_Array * +ArrayConvert( + const MEDMEM_Array< T, NoInterlaceByTypeGaussPolicy, CHECKING_POLICY > &array, T* values=0 + ) +{ + MEDMEM_Array * myArray; + if(values) + myArray = new MEDMEM_Array ( + values, + array.getDim(), + array.getNbElem(), + array.getNbGeoType(), + array.getNbElemGeoC(), + array.getNbGaussGeo(), + true,false + ); + else + myArray = new MEDMEM_Array ( + array.getDim(), + array.getNbElem(), + array.getNbGeoType(), + array.getNbElemGeoC(), + array.getNbGaussGeo() + ); + for (int i=1; i <= array.getNbElem() ; i++ ) + for (int k=1; k<= array.getNbGauss(i); k++ ) + for (int j=1; j<= array.getDim(); j++ ) + myArray->setIJK(i,j,k,array.getIJK(i,j,k)); + + return myArray; + +} + +template +MEDMEM_Array * +ArrayConvert2No( + const MEDMEM_Array< T, NoInterlaceByTypeGaussPolicy, CHECKING_POLICY > &array, T* values=0 + ) +{ + MEDMEM_Array * myArray; + if(values) + myArray = new MEDMEM_Array ( + values, + array.getDim(), + array.getNbElem(), + array.getNbGeoType(), + array.getNbElemGeoC(), + array.getNbGaussGeo(), + true,false + ); + else + myArray = new MEDMEM_Array ( + array.getDim(), + array.getNbElem(), + array.getNbGeoType(), + array.getNbElemGeoC(), + array.getNbGaussGeo() + ); + for (int i=1; i <= array.getNbElem() ; i++ ) + for (int k=1; k<= array.getNbGauss(i); k++ ) + for (int j=1; j<= array.getDim(); j++ ) + myArray->setIJK(i,j,k,array.getIJK(i,j,k)); + + return myArray; + +}; + template MEDMEM_Array * ArrayConvert( @@ -115,6 +183,58 @@ ArrayConvert( }; +template +MEDMEM_Array * +ArrayConvert( + const MEDMEM_Array< T, NoInterlaceByTypeNoGaussPolicy, CHECKING_POLICY > &array, T* values=0 + ) +{ + MEDMEM_Array * myArray; + if(values) + myArray=new MEDMEM_Array ( values, + array.getDim(), + array.getNbElem(), + true,false + ); + else + myArray = new MEDMEM_Array ( + array.getDim(), + array.getNbElem() + ); + for (int i=1; i <= array.getNbElem() ; i++ ) + for (int j=1; j<= array.getDim(); j++ ) + myArray->setIJ(i,j,array.getIJ(i,j)); + + return myArray; + +} + +template +MEDMEM_Array * +ArrayConvert2No( + const MEDMEM_Array< T, NoInterlaceByTypeNoGaussPolicy, CHECKING_POLICY > &array, T* values=0 + ) +{ + MEDMEM_Array * myArray; + if(values) + myArray=new MEDMEM_Array ( values, + array.getDim(), + array.getNbElem(), + true,false + ); + else + myArray = new MEDMEM_Array ( + array.getDim(), + array.getNbElem() + ); + for (int i=1; i <= array.getNbElem() ; i++ ) + for (int j=1; j<= array.getDim(); j++ ) + myArray->setIJ(i,j,array.getIJ(i,j)); + + return myArray; + +}; + template MEDMEM_Array * ArrayConvert( diff --git a/src/MEDMEM/MEDMEM_ArrayInterface.hxx b/src/MEDMEM/MEDMEM_ArrayInterface.hxx index 7d64f7a49..62c170aa0 100644 --- a/src/MEDMEM/MEDMEM_ArrayInterface.hxx +++ b/src/MEDMEM/MEDMEM_ArrayInterface.hxx @@ -38,7 +38,7 @@ template < class ARRAY_ELEMENT_TYPE, class GAUSS_TAG, class CHECKING_POLICY=IndexCheckPolicy> //NoIndexCheckPolicy> -class MEDMEM_ArrayInterface { +class MEDMEM_EXPORT MEDMEM_ArrayInterface { public: diff --git a/src/MEDMEM/MEDMEM_AsciiFieldDriver.hxx b/src/MEDMEM/MEDMEM_AsciiFieldDriver.hxx index 4a871b8c5..1d64a4af8 100644 --- a/src/MEDMEM/MEDMEM_AsciiFieldDriver.hxx +++ b/src/MEDMEM/MEDMEM_AsciiFieldDriver.hxx @@ -20,6 +20,7 @@ #ifndef ASCII_FIELD_DRIVER_HXX #define ASCII_FIELD_DRIVER_HXX +#include "MEDMEM.hxx" #include "MEDMEM_GenDriver.hxx" #include "MEDMEM_Exception.hxx" #include "MEDMEM_Unit.hxx" @@ -34,7 +35,7 @@ #include #include #include -#include +#include #define PRECISION_IN_ASCII_FILE 10 #define PRECISION_IN_COMPARE 1e-10 @@ -61,10 +62,10 @@ namespace MEDMEM { return compare(a,b); } - template<> + template<> MEDMEM_EXPORT void fill<-1,0x3>(double *a, const double *b); - template<> + template<> MEDMEM_EXPORT bool compare<-1>(const double *a, const double *b); template @@ -217,6 +218,8 @@ namespace MEDMEM { template void ASCII_FIELD_DRIVER::open() throw (MEDEXCEPTION) { + if (_file.is_open()) + throw MEDEXCEPTION("ASCII_FIELD_DRIVER::open() : file is already open !"); _file.open(_fileName.c_str(),ofstream::out | ofstream::app); } @@ -241,6 +244,9 @@ namespace MEDMEM { template void ASCII_FIELD_DRIVER::write( void ) const throw (MEDEXCEPTION) { + if (!_file.is_open()) + throw MEDEXCEPTION("ASCII_FIELD_DRIVER::write : can't write a file that was not opened !"); + buildIntroduction(); switch(_spaceDimension) { @@ -360,10 +366,11 @@ namespace MEDMEM template void ASCII_FIELD_DRIVER::sortAndWrite() const { - typedef typename MEDMEM_ArrayInterface::Array ArrayDoubleNo; - typedef typename MEDMEM_ArrayInterface::Array ArrayDoubleFull; - typedef typename MEDMEM_ArrayInterface::Array ArrayNo; - typedef typename MEDMEM_ArrayInterface::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface::Array ArrayDoubleNo; + typedef typename MEDMEM_ArrayInterface::Array ArrayDoubleFull; + typedef typename MEDMEM_ArrayInterface::Array ArrayNo; + typedef typename MEDMEM_ArrayInterface::Array ArrayNoByType; + typedef typename MEDMEM_ArrayInterface::Array ArrayFull; int i,j; int numberOfValues=_ptrField->getNumberOfValues(); @@ -407,6 +414,11 @@ namespace MEDMEM ArrayFull * tmpArray = NULL; if ( _ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) valsToSet= _ptrField->getValue(); + else if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + tmpArray = ArrayConvert + ( *( static_cast(_ptrField->getArray()) ) ); + valsToSet= tmpArray->getPtr(); + } else { tmpArray = ArrayConvert ( *( static_cast(_ptrField->getArray()) ) ); diff --git a/src/MEDMEM/MEDMEM_CellModel.hxx b/src/MEDMEM/MEDMEM_CellModel.hxx index ede10661d..47181c4f0 100644 --- a/src/MEDMEM/MEDMEM_CellModel.hxx +++ b/src/MEDMEM/MEDMEM_CellModel.hxx @@ -25,6 +25,8 @@ #ifndef CELLMODEL_HXX #define CELLMODEL_HXX +#include + #include #include #include @@ -42,8 +44,12 @@ using namespace std ; the cell model it describes as cell dimensions, number of nodes... */ + namespace MEDMEM { -class CELLMODEL + class CELLMODEL; + MEDMEM_EXPORT ostream & operator<<(ostream &os,const CELLMODEL &my); + +class MEDMEM_EXPORT CELLMODEL { private: @@ -99,7 +105,7 @@ public : inline CELLMODEL & operator=(const CELLMODEL &m); /*! Operator << : print CELLMODEL to the given stream. */ - friend ostream & operator<<(ostream &os,const CELLMODEL &my); + friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const CELLMODEL &my); /*! returns _name attribute (ie: MED_PENTA15).\n see med.h (in med/include) */ diff --git a/src/MEDMEM/MEDMEM_Compatibility21_22.hxx b/src/MEDMEM/MEDMEM_Compatibility21_22.hxx index 66b1b854e..e2c028d6e 100644 --- a/src/MEDMEM/MEDMEM_Compatibility21_22.hxx +++ b/src/MEDMEM/MEDMEM_Compatibility21_22.hxx @@ -45,12 +45,20 @@ #undef MED_H #undef MED_PROTO_H -namespace med_2_2 { +/*#ifdef med_2_3_NAMESPACE + +{ +#endif //med_2_3_NAMESPACE*/ +namespace med_2_3 { extern "C" { -#include -#include + #include + #include } } +// } +//#ifdef med_2_3_NAMESPACE + +//#endif //med_2_3_NAMESPACE /* Core of the management V2.1 V2.2 of the Med File diff --git a/src/MEDMEM/MEDMEM_ConnectZone.cxx b/src/MEDMEM/MEDMEM_ConnectZone.cxx new file mode 100644 index 000000000..51013a37a --- /dev/null +++ b/src/MEDMEM/MEDMEM_ConnectZone.cxx @@ -0,0 +1,258 @@ + +// few STL include files +#include + +// few Med Memory include files +#include "MEDMEM_define.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_ConnectZone.hxx" + +using namespace MEDMEM; + + CONNECTZONE::CONNECTZONE(): + _name("") + ,_description("") + ,_distantDomainNumber(0) + ,_localDomainNumber(0) + ,_nodeCorresp(0) + ,_faceCorresp(0) + { + _entityCorresp.clear(); + } + + CONNECTZONE::~CONNECTZONE(){ + if (_nodeCorresp !=0) delete _nodeCorresp; + if (_faceCorresp !=0) delete _faceCorresp; + for (map < pair ,MEDMEM::MEDSKYLINEARRAY * >::iterator + iter = _entityCorresp.begin(); iter != _entityCorresp.end(); iter++) + { + delete iter->second; + } + } + + CONNECTZONE::CONNECTZONE(const CONNECTZONE & myConnectZone): + _name(myConnectZone._name) + ,_description(myConnectZone._description) + ,_distantDomainNumber(myConnectZone._distantDomainNumber) + ,_localDomainNumber(myConnectZone._localDomainNumber) + ,_nodeCorresp(myConnectZone._nodeCorresp) + ,_faceCorresp(myConnectZone._faceCorresp) + ,_entityCorresp(myConnectZone._entityCorresp) + { + } + string CONNECTZONE::getName() const + { + return _name; + } + string CONNECTZONE::getDescription() const + { + return _description; + } + int CONNECTZONE::getDistantDomainNumber() const + { + return _distantDomainNumber; + } + int CONNECTZONE::getLocalDomainNumber() const + { + return _localDomainNumber; + } + + MEDMEM::MESH * CONNECTZONE::getLocalMesh() const + { + return _localMesh; + } + + MEDMEM::MESH * CONNECTZONE::getDistantMesh() const + { + return _distantMesh; + } + + bool CONNECTZONE::isEntityCorrespPresent(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const +{ + typedef map, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter; + + for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++) + { + if ((iter->first).first==localEntity && (iter->first).second==distantEntity) + return true; + } + return false; +} + + const int * CONNECTZONE::getNodeCorrespIndex() const + { + return _nodeCorresp->getIndex(); + } + + const int * CONNECTZONE::getNodeCorrespValue() const + { + return _nodeCorresp->getValue(); + } + int CONNECTZONE::getNodeNumber() const + { + return _nodeCorresp->getNumberOf(); + } + const int * CONNECTZONE::getFaceCorrespIndex() const + { + return _faceCorresp->getIndex(); + } + + const int * CONNECTZONE::getFaceCorrespValue() const + { + return _faceCorresp->getValue(); + } + int CONNECTZONE::getFaceNumber() const + { + return _faceCorresp->getNumberOf(); + } +const int * CONNECTZONE::getEntityCorrespIndex(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const +{ + typedef map, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter; + + for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++) + { + if ((iter->first).first==localEntity && (iter->first).second==distantEntity) + return iter->second->getIndex(); + } + return 0; +} + +const int * CONNECTZONE::getEntityCorrespValue(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const +{ + typedef map, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter; + + for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++) + { + if ((iter->first).first==localEntity && (iter->first).second==distantEntity) + return iter->second->getValue(); + } + return 0; +} + +int CONNECTZONE::getEntityCorrespNumber(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const +{ + typedef map, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter; + + for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++) + { + if ((iter->first).first==localEntity && (iter->first).second==distantEntity) + return iter->second->getNumberOf(); + } + return 0; +} + + +int CONNECTZONE::getEntityCorrespLength(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const +{ + typedef map, MEDMEM::MEDSKYLINEARRAY*>::const_iterator map_iter; + + for (map_iter iter=_entityCorresp.begin(); iter != _entityCorresp.end(); iter++) + { + if ((iter->first).first==localEntity && (iter->first).second==distantEntity) + return iter->second->getLength(); + } + return 0; +} + + void CONNECTZONE::setName(string name) + { + _name=name; + } + void CONNECTZONE::setDescription(string description) + { + _description=description; + } + void CONNECTZONE::setDistantDomainNumber(int distantDomainNumber) + { + _distantDomainNumber=distantDomainNumber; + } + void CONNECTZONE::setLocalDomainNumber(int localDomainNumber) + { + _localDomainNumber=localDomainNumber; + } + void CONNECTZONE::setLocalMesh(MEDMEM::MESH * localMesh) + { + _localMesh=localMesh; + } + + void CONNECTZONE::setDistantMesh(MEDMEM::MESH * distantMesh) + { + _distantMesh=distantMesh; + } + +/*! transforms an int array containing + * the node-node connections + * to a MEDSKYLINEARRAY + */ + void CONNECTZONE::setNodeCorresp(int * nodeCorresp, int nbnode) + { + int* index= new int[nbnode]; + for (int i=0; i + +// few Med Memory include files +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_SkyLineArray.hxx" + +namespace MEDMEM { +class MEDMEM_EXPORT CONNECTZONE +{ +private : + string _name; + string _description; + int _localDomainNumber; + int _distantDomainNumber; + + MEDMEM::MESH * _localMesh; + MEDMEM::MESH * _distantMesh; + + MEDMEM::MEDSKYLINEARRAY * _nodeCorresp; + MEDMEM::MEDSKYLINEARRAY * _faceCorresp; + + map < pair , + MEDMEM::MEDSKYLINEARRAY * > + _entityCorresp; + +public : + CONNECTZONE(); + ~CONNECTZONE(); + CONNECTZONE(const CONNECTZONE & myConnectZone); + + string getName() const ; + string getDescription() const ; + int getDistantDomainNumber() const ; + int getLocalDomainNumber() const ; + MEDMEM::MESH * getLocalMesh() const ; + MEDMEM::MESH * getDistantMesh() const ; + + bool isEntityCorrespPresent(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const; + const int * getNodeCorrespIndex() const; + const int * getNodeCorrespValue() const; + int getNodeNumber() const; + const int * getFaceCorrespIndex() const; + const int * getFaceCorrespValue() const; + int getFaceNumber() const; + const int * getEntityCorrespIndex(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const; + const int * getEntityCorrespValue(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const; + int getEntityCorrespNumber(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const; + int getEntityCorrespLength(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity) const; + void setName(string name) ; + void setDescription(string description) ; + void setDistantDomainNumber(int distantDomainNumber) ; + void setLocalDomainNumber(int distantDomainNumber) ; + void setLocalMesh(MEDMEM::MESH * localMesh) ; + void setDistantMesh(MEDMEM::MESH * distantMesh) ; + + void setNodeCorresp(int * nodeCorresp, int nbnode); + void setNodeCorresp(MEDMEM::MEDSKYLINEARRAY* array); + void setFaceCorresp(int * faceCorresp, int nbface); + void setFaceCorresp(MEDMEM::MEDSKYLINEARRAY* array); + void setEntityCorresp(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity, + int * entityCorresp, int nbentity); + void setEntityCorresp(MED_EN::medEntityMesh localEntity, + MED_EN::medEntityMesh distantEntity, + MEDMEM::MEDSKYLINEARRAY* array); +}; +} +# endif diff --git a/src/MEDMEM/MEDMEM_Connectivity.cxx b/src/MEDMEM/MEDMEM_Connectivity.cxx index 9f686ec45..bc5ab298a 100644 --- a/src/MEDMEM/MEDMEM_Connectivity.cxx +++ b/src/MEDMEM/MEDMEM_Connectivity.cxx @@ -35,15 +35,36 @@ using namespace MED_EN; // Enlarge the vector if necessary to insert the element static inline void insert_vector(vector &Vect, int Indice, int Element) { - if (Indice >= Vect.capacity()) + if (Indice >=(int) Vect.capacity()) Vect.reserve(Indice + 1000); - if (Indice >= Vect.size()) + if (Indice >=(int) Vect.size()) Vect.resize(Indice+1); Vect[Indice] = Element; } +void mergeOrderedTabs(const int *tab1, int lgth1, const int *tab2, int lgth2, int *result, int& lgth) +{ + int cpt[2]={0,0}; + lgth=0; + unsigned char switcher=0; + const int *tabS[2]={tab1,tab2}; + while(cpt[0]tabS[switcher][cpt[switcher]]) + switcher=1-switcher; + else + { + int tmp=tabS[switcher][cpt[switcher]]; + cpt[switcher]++; cpt[1-switcher]++; + result[lgth++]=tmp; + } + } +} + /*! Default Constructor. /n Default for Entity is MED_CELL and type of Connectivity is MED_NODAL */ @@ -70,6 +91,8 @@ CONNECTIVITY::CONNECTIVITY(medEntityMesh Entity /* =MED_CELL */) : _constituent((CONNECTIVITY*)NULL) { MESSAGE("CONNECTIVITY(medEntityMesh Entity=MED_CELL)"); + _count = new int[1]; + _count[0]=1; } /*! @@ -98,6 +121,7 @@ CONNECTIVITY::CONNECTIVITY(int numberOfTypes,medEntityMesh Entity /* =MED_CELL * _geometricTypes = new medGeometryElement[numberOfTypes]; _type = new CELLMODEL[numberOfTypes]; _count = new int[numberOfTypes+1]; + _count[0]=1; } /*! @@ -277,6 +301,8 @@ void CONNECTIVITY::setCount(const int * Count, const medEntityMesh Entity) { if (Entity == _entity) { + if (_numberOfTypes==0) + throw MEDEXCEPTION("Number of Types was not set before setting counts"); int * index = new int[Count[_numberOfTypes]]; index[0]=1; _count[0]=1; @@ -288,8 +314,13 @@ void CONNECTIVITY::setCount(const int * Count, const medEntityMesh Entity) } // allocate _nodal if (_nodal != NULL) delete _nodal; - _nodal = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1,index[_count[_numberOfTypes]-1]-1); - _nodal->setIndex(index); + if (_numberOfTypes != 0) + { + _nodal = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1,index[_count[_numberOfTypes]-1]-1); + _nodal->setIndex(index); + } + else + _nodal=0; delete [] index; } else @@ -358,9 +389,18 @@ void CONNECTIVITY::setPolygonsConnectivity(medConnectivity ConnectivityType, med } else { - if (_constituent == (CONNECTIVITY*) NULL) + if (_entityDimension==3) + { + if (_constituent == (CONNECTIVITY*) NULL) + _constituent=new CONNECTIVITY(MED_EN::MED_FACE); + } + else if (_constituent == (CONNECTIVITY*) NULL) + { throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" : Entity not found !")); - _constituent->setPolygonsConnectivity(ConnectivityType, Entity, PolygonsConnectivity, PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons); + } + _constituent->setPolygonsConnectivity(ConnectivityType, Entity, + PolygonsConnectivity, PolygonsConnectivityIndex, + ConnectivitySize, NumberOfPolygons); } } @@ -379,7 +419,7 @@ void CONNECTIVITY::setPolyhedronConnectivity(medConnectivity ConnectivityType, c if (_polyhedronNodal != (POLYHEDRONARRAY*) NULL) delete _polyhedronNodal; _polyhedronNodal = new POLYHEDRONARRAY(NumberOfPolyhedron,NumberOfFaces,ConnectivitySize); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int i ; MED_EN::med_int * tmp_PolyhedronIndex = new med_int[NumberOfPolyhedron+1] ; for ( i = 0 ; i < NumberOfPolyhedron+1 ; i++ ) @@ -415,6 +455,19 @@ void CONNECTIVITY::setPolyhedronConnectivity(medConnectivity ConnectivityType, c throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" : _entity must be MED_CELL to set polyhedron !")); } +bool CONNECTIVITY::existConnectivityWithPoly (MED_EN::medConnectivity connectivityType, + MED_EN::medEntityMesh Entity) const +{ + if (_entity == Entity) { + if ((connectivityType == MED_EN::MED_NODAL) && + (_nodal != (MEDSKYLINEARRAY*)NULL || _polygonsNodal || _polyhedronNodal)) + return true; + if ((connectivityType == MED_EN::MED_DESCENDING) && (_descending != (MEDSKYLINEARRAY*)NULL)) + return true; + } else if (_constituent != NULL) + return _constituent->existConnectivityWithPoly(connectivityType, Entity); + return false; +} /*! A DOCUMENTER */ //------------------------------------------------------------------------------------------// @@ -463,7 +516,7 @@ void CONNECTIVITY::updateFamily(const vector& myFamilies) return; CONNECTIVITY * oldConstituent = _constituent; _constituent = (CONNECTIVITY *)NULL; - if (oldConstituent->_nodal==NULL) + if (oldConstituent->_nodal==NULL && oldConstituent->_polygonsNodal==NULL) throw MED_EXCEPTION(LOCALIZED(STRING(LOC)<<"We have no nodal connectivity of sub cell")); //Loc vars defined to treat polygons exactly the same as classic types. Not nice but necessary. @@ -471,11 +524,25 @@ void CONNECTIVITY::updateFamily(const vector& myFamilies) const int * oldConstituentValueTab[2]; const int * oldConstituentIndexTab[2]; int * renumberingFromOldToNewTab[2];//Final mapping array between old numbers and new numbers.; + int startNbOfTurnInGlobalLoop=0; - int oldNumberOfFace = oldConstituent->_nodal->getNumberOf(); oldNumberOfFaceTab[0]=oldNumberOfFace; - const int * oldConstituentValue = oldConstituent->_nodal->getValue(); oldConstituentValueTab[0]=oldConstituentValue; - const int * oldConstituentIndex = oldConstituent->_nodal->getIndex(); oldConstituentIndexTab[0]=oldConstituentIndex; - int * renumberingFromOldToNew= new int [oldNumberOfFace]; renumberingFromOldToNewTab[0]=renumberingFromOldToNew; + if (oldConstituent->_nodal != NULL) + { + int oldNumberOfFace = oldConstituent->_nodal->getNumberOf(); + oldNumberOfFaceTab[0] = oldNumberOfFace; + const int * oldConstituentValue = oldConstituent->_nodal->getValue(); + oldConstituentValueTab[0] = oldConstituentValue; + const int * oldConstituentIndex = oldConstituent->_nodal->getIndex(); + oldConstituentIndexTab[0] = oldConstituentIndex; + int * renumberingFromOldToNew = new int [oldNumberOfFace+1]; + renumberingFromOldToNewTab[0] = renumberingFromOldToNew; + } + else //Polyg/PolyH only + { + renumberingFromOldToNewTab[0]=0; + oldNumberOfFaceTab[0]=0; + startNbOfTurnInGlobalLoop++; + } int oldNumberOfFacePoly = oldConstituent->getNumberOfPolygons(); const int * oldConstituentValuePoly=0; @@ -485,10 +552,13 @@ void CONNECTIVITY::updateFamily(const vector& myFamilies) int nbOfTurnInGlobalLoop=1;//Defined to know if a second search on polygons is needed. if(oldNumberOfFacePoly>0) { - oldNumberOfFaceTab[1]=oldNumberOfFacePoly; - oldConstituentValuePoly = oldConstituent->_polygonsNodal->getValue(); oldConstituentValueTab[1]=oldConstituentValuePoly; - oldConstituentIndexPoly = oldConstituent->_polygonsNodal->getIndex(); oldConstituentIndexTab[1]=oldConstituentIndexPoly; - renumberingFromOldToNewPoly=new int[oldNumberOfFacePoly]; renumberingFromOldToNewTab[1]=renumberingFromOldToNewPoly; + oldNumberOfFaceTab[1] = oldNumberOfFacePoly; + oldConstituentValuePoly = oldConstituent->_polygonsNodal->getValue(); + oldConstituentValueTab[1] = oldConstituentValuePoly; + oldConstituentIndexPoly = oldConstituent->_polygonsNodal->getIndex(); + oldConstituentIndexTab[1] = oldConstituentIndexPoly; + renumberingFromOldToNewPoly = new int[oldNumberOfFacePoly+1]; + renumberingFromOldToNewTab[1] = renumberingFromOldToNewPoly; nbOfTurnInGlobalLoop++; } @@ -498,12 +568,14 @@ void CONNECTIVITY::updateFamily(const vector& myFamilies) const int * reverseFaceNodal = _constituent->getReverseNodalConnectivity(); //Common to polygons and classic geometric types const int * reverseFaceNodalIndex = _constituent->getReverseNodalConnectivityIndex(); //Common to polygons and classic geometric types - for(int loop=0;loop_type[0]; for(int iOldFace=0;iOldFace& myFamilies) int nbOfNodesOfCurrentFaceNew; const int *nodesOfCurrentFaceNew=_constituent->getConnectivityOfAnElementWithPoly(MED_NODAL,_constituent->getEntity(), renumberingFromOldToNewLoop[iOldFace],nbOfNodesOfCurrentFaceNew); - MEDMODULUSARRAY modulusArrayOld(nbOfNodesOfCurrentFaceOld,nodesOfCurrentFaceOld); - MEDMODULUSARRAY modulusArrayNew(nbOfNodesOfCurrentFaceNew,nodesOfCurrentFaceNew); + // compare nodes of a new face and those of an old one; + // for the second order elements, only vertex nodes are compared + int nbOfVertices = nbOfNodesOfCurrentFaceOld; + if ( aCELLMODEL ) { + if ( aCELLMODEL->getNumberOfNodes() != nbOfNodesOfCurrentFaceOld ) { + // type changed, find a corresponding CELLMODEL + int iType = 2; // 1-st type is already used at loop beginning + //while ( iOldFace + 1 >= oldConstituent->_count[ 1 + iType ]) // check next type + while ( iOldFace + 1 >= oldConstituent->_count[ iType ]) // check next type + ++iType; + aCELLMODEL = & oldConstituent->_type[ iType - 1 ]; + } + nbOfVertices = aCELLMODEL->getNumberOfVertexes(); + } + MEDMODULUSARRAY modulusArrayOld(nbOfVertices,nbOfNodesOfCurrentFaceOld,nodesOfCurrentFaceOld); + int nbOfVerticesNew = nbOfVertices; + if (nbOfVerticesNew > nbOfNodesOfCurrentFaceNew) nbOfVerticesNew = nbOfNodesOfCurrentFaceNew; + MEDMODULUSARRAY modulusArrayNew(nbOfVerticesNew,nbOfNodesOfCurrentFaceNew,nodesOfCurrentFaceNew); int retCompareNewOld=modulusArrayNew.compare(modulusArrayOld); if(retCompareNewOld==0) throw MED_EXCEPTION(LOCALIZED(STRING(LOC)<<"Uncompatible given user face with calculated existing faces")); @@ -550,10 +638,19 @@ void CONNECTIVITY::updateFamily(const vector& myFamilies) } // Updating the Family for(vector::const_iterator iter=myFamilies.begin();iter!=myFamilies.end();iter++) - (*iter)->changeElementsNbs(_constituent->getEntity(),renumberingFromOldToNew,oldNumberOfFace,renumberingFromOldToNewPoly); - delete oldConstituent ; - delete [] renumberingFromOldToNew; - if(oldNumberOfFacePoly>0) + (*iter)->changeElementsNbs(_constituent->getEntity(), renumberingFromOldToNewTab[0], + oldNumberOfFaceTab[0], renumberingFromOldToNewTab[1]); + + // FIX PAL13414: + if ( _constituent && !_constituent->_constituent ) { + _constituent->_constituent = oldConstituent->_constituent; + oldConstituent->_constituent = NULL; + } + // END FIX PAL13414: + + delete oldConstituent; + delete [] renumberingFromOldToNewTab[0]; + if (oldNumberOfFacePoly > 0) delete [] renumberingFromOldToNewPoly; return; } @@ -625,7 +722,7 @@ int CONNECTIVITY::getConnectivityLength(medConnectivity ConnectivityType, medEnt else { for (int i=0; i<_numberOfTypes; i++) if (_geometricTypes[i]==Type) - return Connectivity->getNumberOfI(_count[i]); + return (_count[i+1]-_count[i])*getType(Type).getNumberOfNodes(); throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" : Type not found !")); } else @@ -775,7 +872,7 @@ const int* CONNECTIVITY::getPolyhedronConnectivity(medConnectivity ConnectivityT ((CONNECTIVITY *)(this))->calculateNodalConnectivity(); if (_polyhedronNodal != (POLYHEDRONARRAY*) NULL) { //CCRT -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int i ; const MED_EN::med_int * tmp_PolyhedronConnectivity = _polyhedronNodal->getNodes(); int * PolyhedronConnectivity = new int[_polyhedronNodal->getNumberOfNodes()] ; @@ -816,7 +913,7 @@ const int* CONNECTIVITY::getPolyhedronFacesIndex() const // calculateNodalConnectivity(); if (_polyhedronNodal != (POLYHEDRONARRAY*) NULL) { //CCRT -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int i ; const MED_EN::med_int * tmp_PolyhedronFacesIndex = _polyhedronNodal->getFacesIndex(); int * PolyhedronFacesIndex = new int[_polyhedronNodal->getNumberOfFaces()+1] ; @@ -849,7 +946,7 @@ const int* CONNECTIVITY::getPolyhedronIndex(medConnectivity ConnectivityType) co // calculateNodalConnectivity(); if (_polyhedronNodal != (POLYHEDRONARRAY*) NULL) { //CCRT -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int i ; const MED_EN::med_int * tmp_PolyhedronIndex = _polyhedronNodal->getPolyhedronIndex(); int * PolyhedronIndex = new int[_polyhedronNodal->getNumberOfPolyhedron()+1] ; @@ -912,15 +1009,13 @@ int CONNECTIVITY::getNumberOfPolyhedron() const const CELLMODEL & CONNECTIVITY::getType(medGeometryElement Type) const //--------------------------------------------------------------// { - const char * LOC = "CONNECTIVITY::getType"; - BEGIN_OF(LOC); - + if ((Type==MED_ALL_ELEMENTS) || (Type==MED_NONE)) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" : medGeometryElement must be different of MED_ALL_ELEMENTS and MED_NONE !")); + throw MEDEXCEPTION("CONNECTIVITY::getType : medGeometryElement must be different of MED_ALL_ELEMENTS and MED_NONE !"); for (int i=0; i<_numberOfTypes; i++) if (_geometricTypes[i]==Type) return _type[i]; - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" : medGeometryElement not found !")); + throw MEDEXCEPTION("CONNECTIVITY::getType : medGeometryElement not found !"); } /*! Returns the number of elements of type %medGeometryElement. @@ -966,11 +1061,11 @@ int CONNECTIVITY::getNumberOf(medEntityMesh Entity, medGeometryElement Type) con { //const char * LOC = "CONNECTIVITY::getNumberOf"; if (Entity==_entity) { - if (Type==MED_NONE) + if (Type==MED_EN::MED_NONE) return 0; // not defined ! //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" : medGeometryElement must be different of MED_NONE")); if (!existConnectivity(MED_NODAL,Entity) && !existConnectivity(MED_DESCENDING,Entity)) return 0; //case with only polygons for example - if (Type==MED_ALL_ELEMENTS) + if (Type==MED_EN::MED_ALL_ELEMENTS) return _count[_numberOfTypes]-1; for (int i=0; i<_numberOfTypes; i++) if (_geometricTypes[i]==Type) @@ -1006,7 +1101,7 @@ const int* CONNECTIVITY::getValue(medConnectivity TypeConnectivity, return _descending->getValue(); for (int i=0; i<_numberOfTypes; i++) if (_geometricTypes[i]==Type) - return _descending->getI(Type); + return _descending->getI(_count[i]); } throw MEDEXCEPTION("Not found"); } @@ -1161,7 +1256,7 @@ void CONNECTIVITY::calculateReverseNodalConnectivity() int global_polyh_number=offset+local_polyh_number+1; int *nodes=getNodesOfPolyhedron(global_polyh_number,nbOfNodes); for(int i=0;igetIndex(); int * descend_connectivity_index = new int[_count[_numberOfTypes]]; - descend_connectivity_index[0]=1; + if(_numberOfTypes>0) + descend_connectivity_index[0]=1; + + + map eltsCounter; medGeometryElement* ConstituentsTypes = new medGeometryElement[2]; ConstituentsTypes[0]=MED_NONE; ConstituentsTypes[1]=MED_NONE; int * NumberOfConstituentsForeachType = new int[2]; NumberOfConstituentsForeachType[0]=0; NumberOfConstituentsForeachType[1]=0; + map::iterator status; for(int i=0; i<_numberOfTypes; i++) { // initialize descend_connectivity_index array : @@ -1255,24 +1356,24 @@ void CONNECTIVITY::calculateDescendingConnectivity() for(int k=1;k2) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Descending connectivity does not support more than 2 types.")); + status=eltsCounter.begin(); + if(!eltsCounter.empty()) + { + ConstituentsTypes[0]=(*status).first; NumberOfConstituentsForeachType[0]=(*status).second; + status++; + if(status!=eltsCounter.end()) + { ConstituentsTypes[1]=(*status).first; NumberOfConstituentsForeachType[1]=(*status).second; } + } // we could built _constituent ! int TotalNumberOfConstituents = NumberOfConstituentsForeachType[0]+NumberOfConstituentsForeachType[1]; int TotalNumberOfNodes = NumberOfConstituentsForeachType[0]*(ConstituentsTypes[0]%100)+NumberOfConstituentsForeachType[1]*(ConstituentsTypes[1]%100); @@ -1287,7 +1388,9 @@ void CONNECTIVITY::calculateDescendingConnectivity() ConstituentNodalConnectivityIndex[0]=1; _constituent->_entityDimension = _entityDimension-1; - if (ConstituentsTypes[1]==MED_NONE) + if(ConstituentsTypes[0]==MED_NONE && ConstituentsTypes[1]==MED_NONE && _numberOfTypes==0) + _constituent->_numberOfTypes = 0; + else if (ConstituentsTypes[1]==MED_NONE) _constituent->_numberOfTypes = 1; else _constituent->_numberOfTypes = 2; @@ -1503,7 +1606,8 @@ void CONNECTIVITY::calculateDescendingConnectivity() delete [] ConstituentNodalConnectivityIndex; delete [] ConstituentNodalConnectivity; delete [] ReverseDescendingConnectivityValue; - _constituent->_count[1]=tmp_NumberOfConstituentsForeachType[0]+1; + if (_constituent->_numberOfTypes > 0) + _constituent->_count[1]=tmp_NumberOfConstituentsForeachType[0]+1; delete [] tmp_NumberOfConstituentsForeachType; _descending = new MEDSKYLINEARRAY(_count[_numberOfTypes]-1, @@ -1536,14 +1640,14 @@ void CONNECTIVITY::calculateDescendingConnectivity() vector myPolygon(vector_begin, vector_begin+vector_size); myPolygon[myPolygon.size()-1] = myPolygon[0]; // because first and last point make a segment - for (int j=0; j Constituentpolygonsnodalvalue; vector Constituentpolygonsnodalindex(1,1); int NumberOfNewFaces = 0; // by convention new faces are polygons + //offset to switch between all types and classical types. + int offsetCell = getNumberOf(MED_CELL, MED_ALL_ELEMENTS); + int *tabRes = new int[1000]; //temporay array for intersection calculation for (int i=0; i(Constituentpolygonsnodalindex.size())-1; k++) // we must cast the unsigned int into int before doing -1 - { - if (Constituentpolygonsnodalindex[k+1]-Constituentpolygonsnodalindex[k] == myFaceNumberOfNodes) - { - MEDMODULUSARRAY face(myFaceNumberOfNodes,&Constituentpolygonsnodalvalue[0] + Constituentpolygonsnodalindex[k]-1); - ret_compare = face_poly.compare(face); - if (ret_compare) - { - PolyDescending.push_back(ret_compare*(NumberOfConstituent+k+1)); // we had it to the connectivity - insert_vector(Reversedescendingconnectivityvalue, 2*(NumberOfConstituent+k)+1, i+1 + getNumberOf(MED_CELL,MED_ALL_ELEMENTS)); // add polyhedra i to reverse descending connectivity for face_poly (in 2sd place) - break; - } - } - } - } + { + int lgth; + const int *facePolyTab=face_poly.getArray(lgth); + int nbOfCandidatesCell = ReverseNodalConnectivityIndex[facePolyTab[0]] - + ReverseNodalConnectivityIndex[facePolyTab[0]-1]; + const int *candidatesCell = ReverseNodalConnectivityValue + + ReverseNodalConnectivityIndex[facePolyTab[0]-1] - 1; + memcpy(tabRes,candidatesCell,nbOfCandidatesCell*sizeof(int)); + int lgth2=nbOfCandidatesCell; + for (int k=1;k 2 should never happend : A face is shared by more than 2 polyhedrons... + { + if (tabRes[0] == offsetCell+i+1) //as tabRes is ordered by construction tabRes[1] > tabRes[0] so the current + // face is shared with an another cell whose id > current id. So let's create + ret_compare=0; + else + {//tabRes[0]getPolyhedronIndex()[tabRes[0]-offsetCell-1] - 1; + int nbOfFacesConstitutingAlreadyBuiltPolyh = _polyhedronNodal->getPolyhedronIndex()[tabRes[0]-offsetCell] - _polyhedronNodal->getPolyhedronIndex()[tabRes[0]-offsetCell-1]; + for (int k1=0; k1NumberOfConstituent)//In other case it is not a polyhedron : no chance to fit if you see comment 30 lines behind. + { + int nbOfNodesForCurrentFace = + Constituentpolygonsnodalindex[curFaceId-NumberOfConstituent] + - Constituentpolygonsnodalindex[curFaceId-NumberOfConstituent-1]; + MEDMODULUSARRAY face (nbOfNodesForCurrentFace,&Constituentpolygonsnodalvalue[0]+ + Constituentpolygonsnodalindex[curFaceId-NumberOfConstituent-1]-1); + ret_compare = face_poly.compare(face); + if (ret_compare) + { + PolyDescending.push_back(ret_compare*curFaceId); // we had it to the connectivity + insert_vector(Reversedescendingconnectivityvalue, 2*(curFaceId-1)+1, + i + 1 + getNumberOf(MED_CELL,MED_ALL_ELEMENTS)); + } + } + } + } + } + } // if not found, face_poly must be created @@ -1683,10 +1824,11 @@ void CONNECTIVITY::calculateDescendingConnectivity() } } } + delete [] tabRes; if (getNumberOfPolyhedron() > 0) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int * tmp_PolyhedronIndex = new int[getNumberOfPolyhedron()+1] ; const MED_EN::med_int * PolyhedronIndex = _polyhedronNodal->getPolyhedronIndex() ; int ii ; @@ -1785,7 +1927,10 @@ medGeometryElement CONNECTIVITY::getElementTypeWithPoly(medEntityMesh Entity,int int globalNumberMaxOfClassicType; if(_entity==Entity) { - globalNumberMaxOfClassicType=_count[_numberOfTypes]; + if (_count==0) + globalNumberMaxOfClassicType = 1; + else + globalNumberMaxOfClassicType=_count[_numberOfTypes]; if(globalNumber>=1) { if(globalNumber retInSet; + if (polyhedronId getNumberOfElementsWithPoly (MED_CELL, MED_ALL_ELEMENTS)) + throw MEDEXCEPTION("Polyhedron ID does not match a polyhedron in the element range"); int startFace=glob[polyhedronId-offsetWithClassicType-1]-1; int endFace=glob[polyhedronId-offsetWithClassicType]-1; int i; @@ -2009,7 +2156,9 @@ int **CONNECTIVITY::getNodesPerFaceOfPolyhedron(int polyhedronId, int& nbOfFaces const int *faces=getPolyhedronFacesIndex(); const int *glob=getPolyhedronIndex(MED_EN::MED_NODAL); int offsetWithClassicType=getNumberOf(_entity,MED_ALL_ELEMENTS); - + if (polyhedronId getNumberOfElementsWithPoly (MED_CELL, MED_ALL_ELEMENTS)) + throw MEDEXCEPTION("Polyhedron ID does not match a polyhedron in the element range"); + int startFace=glob[polyhedronId-offsetWithClassicType-1]-1; nbOfFaces=glob[polyhedronId-offsetWithClassicType]-startFace-1; nbOfNodesPerFaces=new int[nbOfFaces]; @@ -2046,7 +2195,7 @@ int CONNECTIVITY::getNumberOfPolyType() const if(getNumberOfPolyhedron()>0) return 1; } - else if ((_entity==MED_CELL && _entityDimension==2) || (_entity==MED_FACE && _entityDimension==2)) + else if ((_entity==MED_CELL && _entityDimension==2) || (_entity==MED_FACE)) if(getNumberOfPolygons()>0) return 1; return 0; @@ -2058,7 +2207,7 @@ int CONNECTIVITY::getNumberOfElementOfPolyType(MED_EN::medEntityMesh Entity) co { if (_entity==MED_CELL && _entityDimension==3) return getNumberOfPolyhedron(); - else if ((_entity==MED_CELL && _entityDimension==2) || (_entity==MED_FACE && _entityDimension==2)) + else if ((_entity==MED_CELL && _entityDimension==2) || (_entity==MED_FACE)) return getNumberOfPolygons(); return 0; } @@ -2067,7 +2216,8 @@ int CONNECTIVITY::getNumberOfElementOfPolyType(MED_EN::medEntityMesh Entity) co if(_constituent!=NULL) return _constituent->getNumberOfElementOfPolyType(Entity); else - throw MEDEXCEPTION("_constituent required to evaluate getNumberOfElementOfPolyType"); + //throw MEDEXCEPTION("_constituent required to evaluate getNumberOfElementOfPolyType"); + return 0; } } @@ -2087,7 +2237,7 @@ MED_EN::medGeometryElement * CONNECTIVITY::getGeometricTypesWithPoly(MED_EN::med { if (Entity==MED_CELL && _entityDimension==3) ret[nbOfTypesWithoutPoly]=MED_EN::MED_POLYHEDRA; - else if((Entity==MED_CELL && _entityDimension==2) || (Entity==MED_FACE && _entityDimension==2)) + else if((Entity==MED_CELL && _entityDimension==2) || (Entity==MED_FACE)) ret[nbOfTypesWithoutPoly]=MED_EN::MED_POLYGON; } return ret; @@ -2161,8 +2311,7 @@ void CONNECTIVITY::invertConnectivityForAFace(int faceId, const int *nodalConnFo } /* - Method with 2 output : the connectivity required and its length 'lgth'. This method gives the connectivity independently it is a polygons/polyhedrons or normal - element. + Method with 2 output : the connectivity required and its length 'lgth'. This method gives the connectivity independently it is a polygons/polyhedrons or normal element. */ const int * CONNECTIVITY::getConnectivityOfAnElementWithPoly(MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity, int Number, int &lgth) { @@ -2180,11 +2329,11 @@ const int * CONNECTIVITY::getConnectivityOfAnElementWithPoly(MED_EN::medConnecti return newConstituentValue+newConstituentIndex[Number-1]-1; } int nbOfClassicalElements=getNumberOf(_entity,MED_ALL_ELEMENTS); - if((_entity==MED_FACE && _entityDimension==2) || (_entity==MED_CELL && _entityDimension==2)) + if((_entity==MED_FACE) || (_entity==MED_CELL && _entityDimension==2)) { const int * newConstituentValue = 0; const int * newConstituentIndex = 0; - if(Number<=nbOfClassicalElements) + if(Number<=nbOfClassicalElements && nbOfClassicalElements!=0) { newConstituentValue = getConnectivity(ConnectivityType,Entity,MED_ALL_ELEMENTS); newConstituentIndex = getConnectivityIndex(ConnectivityType,Entity); @@ -2222,7 +2371,7 @@ const int * CONNECTIVITY::getConnectivityOfAnElementWithPoly(MED_EN::medConnecti if(localNumbergetValue(); // newConstituentIndex = _polyhedronDescending->getIndex(); newConstituentValue = getPolyhedronConnectivity( ConnectivityType ); @@ -2251,8 +2400,15 @@ int CONNECTIVITY::getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, MED_ return _numberOfNodes; if(Entity==_entity) { + if (Type == MED_ALL_ELEMENTS) + return getNumberOfElementOfPolyType(_entity)+ getNumberOf(_entity,Type) ; + if(Type==MED_POLYGON || Type==MED_POLYHEDRA) - return getNumberOfElementOfPolyType(_entity); + { + if(Type==MED_POLYGON && Entity==MED_CELL && _entityDimension==3 || Type==MED_POLYHEDRA && Entity==MED_FACE) + return 0; + return getNumberOfElementOfPolyType(_entity); + } else return getNumberOf(_entity,Type); } @@ -2261,7 +2417,8 @@ int CONNECTIVITY::getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, MED_ if(_constituent) return _constituent->getNumberOfElementsWithPoly(Entity,Type); else - throw MEDEXCEPTION("CONNECTIVITY::getNumberOfElementsWithPoly : _constituent needed"); + //throw MEDEXCEPTION("CONNECTIVITY::getNumberOfElementsWithPoly : _constituent needed"); + return 0; } } diff --git a/src/MEDMEM/MEDMEM_Connectivity.hxx b/src/MEDMEM/MEDMEM_Connectivity.hxx index 25722efc5..f976e1cde 100644 --- a/src/MEDMEM/MEDMEM_Connectivity.hxx +++ b/src/MEDMEM/MEDMEM_Connectivity.hxx @@ -20,6 +20,8 @@ #ifndef CONNECTIVITY_HXX #define CONNECTIVITY_HXX +#include + #include #include "MEDMEM_Utilities.hxx" @@ -39,7 +41,7 @@ class GROUP; */ /* ------------------------------------------- */ -class CONNECTIVITY +class MEDMEM_EXPORT CONNECTIVITY /* ------------------------------------------- */ { /* ---------------------- */ @@ -196,30 +198,37 @@ public: const int* PolyhedronFacesIndex= (int*) NULL, int NumberOfFaces=0); - inline bool existConnectivity (MED_EN::medConnectivity connectivityType, MED_EN::medEntityMesh Entity) const; - - virtual bool existPolygonsConnectivity(MED_EN::medConnectivity connectivityType, - MED_EN::medEntityMesh Entity) const; + inline bool existConnectivity (MED_EN::medConnectivity connectivityType, + MED_EN::medEntityMesh Entity) const; + bool existConnectivityWithPoly (MED_EN::medConnectivity connectivityType, + MED_EN::medEntityMesh Entity) const; + + virtual bool existPolygonsConnectivity (MED_EN::medConnectivity connectivityType, + MED_EN::medEntityMesh Entity) const; - virtual bool existPolyhedronConnectivity(MED_EN::medConnectivity connectivityType, - MED_EN::medEntityMesh Entity) const; + virtual bool existPolyhedronConnectivity (MED_EN::medConnectivity connectivityType, + MED_EN::medEntityMesh Entity) const; - virtual void calculateConnectivity (MED_EN::medConnectivity connectivityType, MED_EN::medEntityMesh Entity); + virtual void calculateConnectivity (MED_EN::medConnectivity connectivityType, + MED_EN::medEntityMesh Entity); virtual void updateFamily (const vector& myFamilies); - inline MED_EN::medEntityMesh getEntity () const; - inline int getNumberOfTypes (MED_EN::medEntityMesh Entity) const; - int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const; - const int * getConnectivityOfAnElementWithPoly(MED_EN::medConnectivity ConnectivityType, - MED_EN::medEntityMesh Entity, - int Number, int &lgth); + inline MED_EN::medEntityMesh getEntity () const; + + inline int getNumberOfTypes (MED_EN::medEntityMesh Entity) const; + int getNumberOfTypesWithPoly (MED_EN::medEntityMesh Entity) const; + const int * getConnectivityOfAnElementWithPoly (MED_EN::medConnectivity ConnectivityType, + MED_EN::medEntityMesh Entity, + int Number, int &lgth); + int getNumberOfPolyType() const; int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; int getNumberOfElementOfPolyType(MED_EN::medEntityMesh Entity) const; - inline const MED_EN::medGeometryElement * getGeometricTypes (MED_EN::medEntityMesh Entity) const + + inline const MED_EN::medGeometryElement * getGeometricTypes (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); - MED_EN::medGeometryElement * getGeometricTypesWithPoly (MED_EN::medEntityMesh Entity) const + MED_EN::medGeometryElement * getGeometricTypesWithPoly (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); MED_EN::medGeometryElement getElementType (MED_EN::medEntityMesh Entity, int Number) const; @@ -307,7 +316,7 @@ inline int CONNECTIVITY::getNumberOfTypes(MED_EN::medEntityMesh Entity) const { (const_cast (this))->calculateDescendingConnectivity(); } - catch (MEDEXCEPTION & ex) + catch (MEDEXCEPTION &) { return 0 ; } @@ -320,7 +329,7 @@ inline int CONNECTIVITY::getNumberOfTypes(MED_EN::medEntityMesh Entity) const { _constituent->calculateConnectivity(MED_EN::MED_NODAL,Entity); } - catch (MEDEXCEPTION & ex) + catch (MEDEXCEPTION &) { return 0 ; } @@ -382,7 +391,7 @@ inline bool CONNECTIVITY::existConnectivity( MED_EN::medConnectivity Connectivit //-----------------------------------------------------------------------------// { if (_entity==Entity) { - if ((ConnectivityType==MED_EN::MED_NODAL)&(_nodal!=(MEDSKYLINEARRAY*)NULL)) + if ((ConnectivityType == MED_EN::MED_NODAL) && (_nodal != (MEDSKYLINEARRAY*)NULL)) return true; if ((ConnectivityType==MED_EN::MED_DESCENDING)&(_descending!=(MEDSKYLINEARRAY*)NULL)) return true; diff --git a/src/MEDMEM/MEDMEM_Coordinate.hxx b/src/MEDMEM/MEDMEM_Coordinate.hxx index 68b30e9a7..f0f66b1b1 100644 --- a/src/MEDMEM/MEDMEM_Coordinate.hxx +++ b/src/MEDMEM/MEDMEM_Coordinate.hxx @@ -25,6 +25,8 @@ #ifndef COORDINATE_HXX #define COORDINATE_HXX +#include + #include #include "MEDMEM_PointerOf.hxx" @@ -42,7 +44,7 @@ */ namespace MEDMEM { -class COORDINATE +class MEDMEM_EXPORT COORDINATE { protected: diff --git a/src/MEDMEM/MEDMEM_DriverFactory.cxx b/src/MEDMEM/MEDMEM_DriverFactory.cxx index 9aa2c8454..32c2f0ace 100644 --- a/src/MEDMEM/MEDMEM_DriverFactory.cxx +++ b/src/MEDMEM/MEDMEM_DriverFactory.cxx @@ -25,6 +25,9 @@ #include "MEDMEM_PorflowMeshDriver.hxx" #include "MEDMEM_VtkMeshDriver.hxx" #include "MEDMEM_VtkMedDriver.hxx" +#include "MEDMEM_EnsightFieldDriver.hxx" +#include "MEDMEM_EnsightMeshDriver.hxx" +#include "MEDMEM_EnsightMedDriver.hxx" #include "MEDMEM_Exception.hxx" @@ -64,7 +67,7 @@ void DRIVERFACTORY::setMedFileVersionForWriting(medFileVersion version) driverTypes DRIVERFACTORY::deduceDriverTypeFromFileName(const std::string & fileName) { string extension(fileName); - unsigned int pos=extension.rfind('.'); + string::size_type pos=extension.rfind('.'); if(pos==string::npos) return NO_DRIVER; extension.erase(0,pos+1); @@ -76,6 +79,8 @@ driverTypes DRIVERFACTORY::deduceDriverTypeFromFileName(const std::string & file return PORFLOW_DRIVER; if(extension=="vtk") return VTK_DRIVER; + if(extension=="case") + return ENSIGHT_DRIVER; return NO_DRIVER; } @@ -96,8 +101,9 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, ret->setMeshName(driverName); return ret; } + case MED_CREA : case MED_ECRI : { - ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh); + ret = new MED_MESH_WRONLY_DRIVER(fileName, mesh, access); ret->setMeshName(driverName); return ret; } @@ -119,13 +125,12 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, ret=new GIBI_MESH_RDONLY_DRIVER(fileName,mesh); return ret; } + case MED_REMP : + case MED_CREA : case MED_ECRI : { throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the GIBI_DRIVER type which is not allowed because GIBI_DRIVER is only a read access driver"); } - case MED_REMP : { - throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the GIBI_DRIVER type which is not allowed because GIBI_DRIVER is only a read access driver"); - } - default: + default: throw MED_EXCEPTION ("access type has not been properly specified to the method"); } break; @@ -138,11 +143,32 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,mesh); return ret; } + case MED_CREA : + case MED_REMP : case MED_ECRI : { throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the PORFLOW_DRIVER type which is not allowed because PORFLOW_DRIVER is only a read access driver"); } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; + } + + case ENSIGHT_DRIVER : { + switch(access) + { + case MED_LECT : { + ret=new ENSIGHT_MESH_RDONLY_DRIVER(fileName,mesh); + return ret; + } + case MED_ECRI : { + ret=new ENSIGHT_MESH_WRONLY_DRIVER(fileName,mesh); + return ret; + } + case MED_CREA : case MED_REMP : { - throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the PORFLOW_DRIVER type which is not allowed because PORFLOW_DRIVER is only a read access driver"); + throw MED_EXCEPTION ("not yet implemented"); + return ret; } default: throw MED_EXCEPTION ("access type has not been properly specified to the method"); @@ -156,14 +182,13 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, case MED_LECT : { throw MED_EXCEPTION ("access mode other than MED_ECRI or MED_REMPT has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver"); } + case MED_CREA : + case MED_REMP : case MED_ECRI : { ret=new VTK_MESH_DRIVER(fileName,mesh); return ret; } - case MED_REMP : { - ret=new VTK_MESH_DRIVER(fileName,mesh); - return ret; - } + default: throw MED_EXCEPTION ("access type has not been properly specified to the method"); } @@ -171,7 +196,7 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, } case NO_DRIVER : { - throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed"); + throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 1 which is not allowed"); } default: throw MED_EXCEPTION ("other driver than MED_DRIVER GIBI_DRIVER PORFLOW_DRIVER and VT_DRIVER has been specified to the method which is not allowed"); @@ -193,6 +218,7 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType, ret=new MED_MED_RDONLY_DRIVER(fileName,med); break ; } + case MED_CREA : case MED_ECRI : { ret=new MED_MED_WRONLY_DRIVER(fileName,med); break ; @@ -213,6 +239,7 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType, case MED_LECT : { throw MED_EXCEPTION ("access mode other than MED_ECRI or MED_REMPT has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver"); } + case MED_CREA : case MED_ECRI : { ret=new VTK_MED_DRIVER(fileName,med); break ; @@ -227,6 +254,28 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType, break; } + case ENSIGHT_DRIVER : { + switch(access) + { + case MED_LECT : { + ret=new ENSIGHT_MED_RDONLY_DRIVER(fileName,med); + break ; + } + case MED_CREA : + case MED_ECRI : { + ret=new ENSIGHT_MED_WRONLY_DRIVER(fileName,med); + break ; + } + case MED_REMP : { + throw MED_EXCEPTION ("not yet implemented"); + break ; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; + } + case GIBI_DRIVER : { throw MED_EXCEPTION ("GIBI_DRIVER has been specified to the method which is not allowed because there is no GIBI driver for the MED object"); break; @@ -238,11 +287,11 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType, } case NO_DRIVER : { - throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed"); + throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 2 which is not allowed"); break; } default: - throw MED_EXCEPTION ("NO_DRIVER has been specified to the method which is not allowed"); + throw MED_EXCEPTION ("NO_DRIVER has been specified to the method 3 which is not allowed"); } return ret; } @@ -257,7 +306,7 @@ GENDRIVER * DRIVERFACTORY::buildMedDriverFromFile(const string & fileName, { version = getMedFileVersion(fileName); } - catch (MEDEXCEPTION & ex) + catch (MEDEXCEPTION & ex) { version = DRIVERFACTORY::globalMedFileVersionForWriting; } @@ -275,6 +324,7 @@ GENDRIVER * DRIVERFACTORY::buildMedDriverFromFile(const string & fileName, driver = new MED_MED_RDONLY_DRIVER22(fileName,ptrMed); return driver; } + case MED_CREA : case MED_ECRI : { if (version == V21) driver = new MED_MED_WRONLY_DRIVER21(fileName,ptrMed); @@ -322,11 +372,12 @@ GENDRIVER * DRIVERFACTORY::buildMeshDriverFromFile(const string & fileName, driver = new MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh); return driver; } + case MED_CREA : case MED_ECRI : { if (version == V21) driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh); else if (version == V22) - driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh); + driver = new MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh,access); return driver; } case MED_REMP : { @@ -360,6 +411,7 @@ GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForMesh(const std::string & fil driver->setMeshName(driverName); return driver; } + case MED_CREA : case MED_ECRI : { if (version == V21) driver = new MED_MESH_WRONLY_DRIVER21(fileName,ptrMesh); diff --git a/src/MEDMEM/MEDMEM_DriverFactory.hxx b/src/MEDMEM/MEDMEM_DriverFactory.hxx index b3871f6b8..945b88e61 100644 --- a/src/MEDMEM/MEDMEM_DriverFactory.hxx +++ b/src/MEDMEM/MEDMEM_DriverFactory.hxx @@ -20,6 +20,8 @@ #ifndef DRIVERFACTORY_HXX #define DRIVERFACTORY_HXX +#include + #include "MEDMEM_MedVersion.hxx" #include "MEDMEM_GenDriver.hxx" #include "MEDMEM_define.hxx" @@ -41,11 +43,13 @@ namespace MEDMEM { for the writing of Med File set to V22 */ - extern MED_EN::medFileVersion globalMedFileVersionForWriting; + MEDMEM_EXPORT extern MED_EN::medFileVersion globalMedFileVersionForWriting; + + MEDMEM_EXPORT MED_EN::medFileVersion getMedFileVersionForWriting(); - MED_EN::medFileVersion getMedFileVersionForWriting(); + MEDMEM_EXPORT void setMedFileVersionForWriting(MED_EN::medFileVersion version); - void setMedFileVersionForWriting(MED_EN::medFileVersion version); + MEDMEM_EXPORT driverTypes deduceDriverTypeFromFileName(const std::string & fileName); driverTypes deduceDriverTypeFromFileName(const std::string & fileName); @@ -86,6 +90,7 @@ namespace MEDMEM { } } +#include "MEDMEM_EnsightFieldDriver.hxx" #include "MEDMEM_VtkFieldDriver.hxx" #include "MEDMEM_MedFieldDriver.hxx" #include "MEDMEM_MedFieldDriver21.hxx" @@ -123,6 +128,27 @@ namespace MEDMEM { break; } + case ENSIGHT_DRIVER : { + switch(access) + { + case MED_EN::MED_LECT : { + ret = new ENSIGHT_FIELD_RDONLY_DRIVER(fileName,field); + break; + } + case MED_EN::MED_ECRI : { + ret=new ENSIGHT_FIELD_WRONLY_DRIVER(fileName,field); + break; + } + case MED_EN::MED_REMP : { + throw MED_EXCEPTION ("not yet implemented"); + break ; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; + } + case VTK_DRIVER : { switch(access) { @@ -188,7 +214,7 @@ namespace MEDMEM { { version = getMedFileVersion(fileName); } - catch (MEDEXCEPTION & ex) + catch (MEDEXCEPTION & ) { version = DRIVERFACTORY::globalMedFileVersionForWriting; } diff --git a/src/MEDMEM/MEDMEM_DriverTools.cxx b/src/MEDMEM/MEDMEM_DriverTools.cxx index c28a37d19..c5d512ea7 100644 --- a/src/MEDMEM/MEDMEM_DriverTools.cxx +++ b/src/MEDMEM/MEDMEM_DriverTools.cxx @@ -27,38 +27,40 @@ #include using namespace std; -using namespace MEDMEM; using namespace MED_EN; #define DUMP_LINES_LIMIT 20 +namespace MEDMEM { + // Cet opĂ©rateur permet d'ordonner les mailles dans un set suivant l'ordre requis par MED bool _maille::operator < (const _maille& ma) const { - // si le type gĂ©omĂ©trique differe, la comparaison est basĂ©e dessus - // sinon on se base sur une comparaison des numĂ©ros de sommets - if(geometricType==ma.geometricType) + // si le type gĂ©omĂ©trique differe, la comparaison est basĂ©e dessus + // sinon on se base sur une comparaison des numĂ©ros de sommets + if(geometricType==ma.geometricType) + { + // construction de deux vecteur temporaire contenant les numeros de sommets + // pour faire le tri et les comparaisons + size_t l=sommets.size(); + std::vector v1(l); + std::vector v2(l); + for (unsigned int i=0; i!=l; ++i) { - // construction de deux vecteur temporaire contenant les numeros de sommets - // pour faire le tri et les comparaisons - size_t l=sommets.size(); - std::vector v1(l); - std::vector v2(l); - for (unsigned int i=0; i!=l; ++i) - { - v1[i]=sommets[i]->second.number; - v2[i]=ma.sommets[i]->second.number; - } - std::sort(v1.begin(), v1.end()); - std::sort(v2.begin(), v2.end()); - for(std::vector::const_iterator i1=v1.begin(), i2=v2.begin(); i1!=v1.end(); ++i1, ++i2) - if(*i1 != *i2) - return *i1 < *i2; - return false; // cas d'Ă©galitĂ© + v1[i]=sommets[i]->second.number; + v2[i]=ma.sommets[i]->second.number; } - else - return geometricType::const_iterator i1=v1.begin(), i2=v2.begin(); i1!=v1.end(); ++i1, ++i2) + if(*i1 != *i2) + return *i1 < *i2; + return false; // cas d'Ă©galitĂ© + } + else + return geometricType= 0 && i < sommets.size() ); @@ -99,7 +101,7 @@ return entity; //END_OF(LOC); }; -std::ostream& MEDMEM::operator << (std::ostream& os, const _maille& ma) +std::ostream& operator << (std::ostream& os, const _maille& ma) { os << "maille " << ma.ordre << " (" << ma.geometricType << ") : < "; std::vector< std::map::iterator >::const_iterator i=ma.sommets.begin(); @@ -110,19 +112,23 @@ std::ostream& MEDMEM::operator << (std::ostream& os, const _maille& ma) return os; } -std::ostream& MEDMEM::operator << (std::ostream& os, const _groupe& gr) +std::ostream& operator << (std::ostream& os, const _groupe& gr) { os << "--- Groupe " << gr.nom << " --- " << std::endl ; os << " -> liste des sous-groupes : "; for( std::vector::const_iterator i=gr.groupes.begin(); i!=gr.groupes.end(); ++i) - os << *i << " "; + os << *i << " "; + os << std::endl << " -> liste des "<< gr.mailles.size() << " mailles : " << std::endl; - _groupe::mailleIter i=gr.mailles.begin(); + + _groupe::mailleIter i1=gr.mailles.begin(); int l; - for(l = 0; l < DUMP_LINES_LIMIT && i!=gr.mailles.end(); i++, l++) - os << setw(3) << l+1 << " " << *(*i) << std::endl; + for(l = 0; l < DUMP_LINES_LIMIT && i1!=gr.mailles.end(); i1++, l++) + os << setw(3) << l+1 << " " << *(*i1) << std::endl; + if ( l == DUMP_LINES_LIMIT ) os << " ... skip " << gr.mailles.size() - l << " mailles" << endl; + os << " relocMap, size=" << gr.relocMap.size() << endl; map::const_iterator it = gr.relocMap.begin(); for ( l = 0; l < DUMP_LINES_LIMIT && it != gr.relocMap.end(); ++it, ++l ) @@ -132,7 +138,7 @@ std::ostream& MEDMEM::operator << (std::ostream& os, const _groupe& gr) return os; } -std::ostream& MEDMEM::operator << (std::ostream& os, const _noeud& no) +std::ostream& operator << (std::ostream& os, const _noeud& no) { os << "noeud " << no.number << " : < "; std::vector::const_iterator i=no.coord.begin(); @@ -151,7 +157,7 @@ void MEDMEM::_fieldBase::dump(std::ostream& os) const " type: " << _type << endl; os << " subcomponents:" << endl; vector< _sub_data >::const_iterator sub_data = _sub.begin(); - for ( int i_sub = 1; sub_data != _sub.end(); ++sub_data, i_sub ) { + for ( ; sub_data != _sub.end(); ++sub_data ) { os << " group index: " << sub_data->_supp_id << ", " << sub_data->nbComponents() << " comp names: "; for ( int i_comp = 0; i_comp < sub_data->nbComponents(); ++i_comp ) @@ -160,13 +166,13 @@ void MEDMEM::_fieldBase::dump(std::ostream& os) const } } -std::ostream& MEDMEM::operator << (std::ostream& os, const _fieldBase * f) +std::ostream& operator << (std::ostream& os, const _fieldBase * f) { f->dump( os ); return os; } -std::ostream& MEDMEM::operator << (std::ostream& os, const _intermediateMED& mi) +std::ostream& operator << (std::ostream& os, const _intermediateMED& mi) { os << "Set des " << mi.maillage.size() << " mailles : " << std::endl; std::set<_maille>::const_iterator i=mi.maillage.begin(); @@ -206,6 +212,10 @@ void _intermediateMED::treatGroupes() { const char * LOC = "_intermediateMED::treatGroupes() : "; BEGIN_OF(LOC); + + if ( myGroupsTreated ) + return; + myGroupsTreated = true; // -------------------- // erase useless group @@ -220,7 +230,7 @@ void _intermediateMED::treatGroupes() j = grp.groupes.begin(); while( j!=grp.groupes.end() ) { int grpInd = *j-1; - if ( grpInd < 0 || grpInd >= groupes.size() ) { + if ( grpInd < 0 || grpInd >= (int)groupes.size() ) { throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad subgroup index: " << grpInd << ", in " << i << " groupe.nom=" << grp.nom)); } @@ -229,7 +239,7 @@ void _intermediateMED::treatGroupes() MESSAGE("High hierarchical depth of subgroups in group " << i ); *j = sub_grp.groupes[0]; // replace j with its 1st subgroup // push back the rest subs - for ( int k = 1; k < sub_grp.groupes.size(); ++k ) + for ( int k = 1; k < (int)sub_grp.groupes.size(); ++k ) grp.groupes.push_back( sub_grp.groupes[ k ]); // vector maybe is reallocated: restart iterator j = grp.groupes.begin(); @@ -330,24 +340,91 @@ void _intermediateMED::numerotationMaillage() i++; } } + + // check if numeration is needed + if ( i->ordre > 0 && maillage.rbegin()->ordre > 0 ) + { + // already numerated, check numeration + bool ok = true; + const int maxNbTypes = 20; + pair< unsigned, unsigned > minMaxOrder[ maxNbTypes ]; + int nbElems[ maxNbTypes ]; + std::set<_maille>::iterator j=i; + + do { // loop on elements of one entity + int iType = 0; + minMaxOrder[ iType ] = make_pair( maillage.size(), 0 ); + int i_maille = 0, dimension = j->dimension(), type = j->geometricType; + + std::set<_maille>::iterator k=j; + for ( ; j!=maillage.end() && (hasMixedCells || dimension==j->dimension()); ++j) + { + if (type != j->geometricType) // si changement de type geometrique + { + nbElems[ iType ] = i_maille; + i_maille=0; + type = j->geometricType; + iType++; + minMaxOrder[ iType ] = make_pair( maillage.size(), 0 ); + } + ++i_maille; + if ( j->ordre < minMaxOrder[ iType ].first ) + minMaxOrder[ iType ].first = j->ordre; + if ( j->ordre > minMaxOrder[ iType ].second ) + minMaxOrder[ iType ].second = j->ordre; + } + nbElems[ iType ] = i_maille; + + bool renumEntity = false; + for ( int t = 0; t <= iType; ++t ) { + int orderRange = minMaxOrder[ t ].second - minMaxOrder[ t ].first; + if ( nbElems[ t ] != orderRange + 1 ) + ok = false; + if ( t > 0 ) { + if ( minMaxOrder[ t ].first == 1 ) + renumEntity = true; + else if ( minMaxOrder[ t-1 ].second+1 != minMaxOrder[ t ].first ) + ok = false; + } + } + if ( ok && renumEntity ) { // each type of entity is numerated separately + int iType = 0, i_shift = 0; + type = k->geometricType; + for ( ; k != j; ++k ) { + if (type != k->geometricType) { // si changement de type geometrique + i_shift = minMaxOrder[ iType++ ].second; + type = k->geometricType; + } + k->ordre += i_shift; + } + } + + } while ( ok && j != maillage.end() ); + + if ( ok ) return; // renumeration not needed + } + // numerotation des mailles par entitĂ© - int i_maille=0; - int dimension=i->dimension(); - for( ; i!=maillage.end(); ++i) + int i_maille=0; + int dimension=i->dimension(); + for( ; i!=maillage.end(); ++i) + { + if ( !hasMixedCells && dimension != i->dimension() ) // on change d'entite { - if ( !hasMixedCells && dimension!=i->dimension() ) // on change d'entite - { - MESSAGE( "NB dim " << dimension << " entities: " << i_maille); - dimension=i->dimension(); - i_maille=0; - } - (*i).ordre=++i_maille; + MESSAGE( "NB dim " << dimension << " entities: " << i_maille); + dimension=i->dimension(); + i_maille=0; } + i->ordre=++i_maille; + } END_OF(LOC); } void _intermediateMED::numerotationPoints() { +// if ( myPointsNumerated ) +// return; +// myPointsNumerated = true; // Fonction de renumerotation des noeuds (necessaire quand il y a des trous dans la numerotation. int i_noeud=0; for( std::map::const_iterator i=points.begin(); i!=points.end(); ++i) @@ -412,6 +489,10 @@ CONNECTIVITY * _intermediateMED::getConnectivity() std::set<_maille>::const_iterator i, j; // iterateurs sur les mailles + // min and max element nb for each geom type + const int maxNbTypes = 20; + vector< pair< unsigned, unsigned > > minMaxOrder( maxNbTypes ); + // skip nodes and elements of or less dimension // Unfortunately, it is impossible because of MESH::createFamilies() that requires // presence of connectivity even for nodes! @@ -431,13 +512,19 @@ CONNECTIVITY * _intermediateMED::getConnectivity() // - on alloue la connectivite // - on parcourt une deuxieme fois avec j pour lire les noeuds. - type=i->geometricType; // init boucle for dimension=i->dimension(); nbtype=0; vtype.push_back(type); // Boucle sur i de parcours des mailles d'une entite // Une entite se termine lorsqu'on atteint la fin de maillage ou lorsque la dimension des mailles change + + int iType=0; + minMaxOrder[ iType ] = make_pair( maillage.size(), 0 ); + + // if hasMixedCells, store POINT1 elems as MED_NODE and + // elems of all the rest types as MED_CELL, i.e. do not break the loop + // when dimension changes bool ignoreDimChange = hasMixedCells && dimension > 0; for( ; i!=maillage.end() && ( ignoreDimChange || dimension==i->dimension()) ; ++i) { @@ -448,8 +535,13 @@ CONNECTIVITY * _intermediateMED::getConnectivity() type=i->geometricType; vtype.push_back(type); // stocke le nouveau type geometrique rencontre dimension=i->dimension(); + iType++; + minMaxOrder[ iType ] = make_pair( maillage.size(), 0 ); } - + if ( i->ordre < minMaxOrder[ iType ].first ) + minMaxOrder[ iType ].first = i->ordre; + if ( i->ordre > minMaxOrder[ iType ].second ) + minMaxOrder[ iType ].second = i->ordre; ++nbtype; } vcount.push_back(dimension ? nbtype : numberOfNodes); // n'a pas Ă©tĂ© stockĂ© dans la boucle @@ -492,18 +584,23 @@ CONNECTIVITY * _intermediateMED::getConnectivity() for (int k=0; k!=numberOfTypes; ++k ) { + int orderShift = 1; + if ( minMaxOrder[ k ].first > 1 ) // min elem number != 1 + orderShift += minMaxOrder[ k-1 ].second; // max elem number in previous type // pour chaque type gĂ©ometrique k, copie des sommets dans connectivity et set dans Connectivity int nbSommetsParMaille = j->sommets.size(); - int n, nbSommets = vcount[k] * j->sommets.size(); + int n, nbSommets = vcount[k] * nbSommetsParMaille; connectivity = new int[ nbSommets ]; - for (int l=0; l!=vcount[k]; ++l) + for (int l=0; l!=vcount[k]; ++l) // loop on elements of geom type { if ( entity==MED_NODE ) connectivity[l] = l+1; else { + int index0 = nbSommetsParMaille * ( j->ordre - orderShift ); for ( n=0; n != nbSommetsParMaille; ++n) { - connectivity[nbSommetsParMaille*l+n] = + //connectivity[nbSommetsParMaille*l+n] = + connectivity[ index0 + n ] = j->sommets[ j->reverse ? nbSommetsParMaille-n-1 : n ]->second.number; } // DO NOT ERASE, maillage will be used while fields construction @@ -625,7 +722,7 @@ _intermediateMED::getGroups(vector & _groupCell, field->getGroupIds( sub_grps, false ); } } - if ( i > *sub_grps.begin() ) { // roll back + if ( (int)i > *sub_grps.begin() ) { // roll back support_groups.erase( i ); support_groups.insert( sub_grps.begin(), sub_grps.end() ); i = *sub_grps.begin() - 1; @@ -887,7 +984,7 @@ void _intermediateMED::getFamilies(std::vector & _famCell, GROUP * _intermediateMED::getGroup( int i ) { - if ( i < medGroupes.size() ) + if ( i <(int) medGroupes.size() ) return medGroupes[ i ]; throw MEDEXCEPTION (LOCALIZED(STRING("_intermediateMED::getGroup(): WRONG GROUP INDEX: ") @@ -903,16 +1000,17 @@ void _intermediateMED::getFields(std::list< FIELD_* >& theFields) { const char * LOC = "_intermediateMED::getFields() : "; BEGIN_OF(LOC); + std::list< _fieldBase* >::const_iterator fIt = fields.begin(); for ( ; fIt != fields.end(); fIt++ ) { const _fieldBase* fb = *fIt; - list > ff = fb->getField(groupes); + list > ff = fb->getField(groupes, medGroupes); list >::iterator f_sup = ff.begin(); for (int j = 1 ; f_sup != ff.end(); f_sup++, ++j ) { - FIELD_* f = f_sup->first; - SUPPORT* sup = getGroup( f_sup->second ); + FIELD_ * f = f_sup->first; + SUPPORT * sup = getGroup( f_sup->second ); if ( !sup ) throw MEDEXCEPTION (LOCALIZED(STRING(LOC) <<"_intermediateMED::getFields(), NULL field support: " @@ -923,8 +1021,11 @@ void _intermediateMED::getFields(std::list< FIELD_* >& theFields) (LOCALIZED(STRING("_intermediateMED::getFields(), field support size (") << nb_elems << ") != NumberOfValues (" << f->getNumberOfValues())); theFields.push_back( f ); - if ( sup->getName().empty() ) - sup->setName( "GRP_" + f->getName() ); + if ( sup->getName().empty() ) { + ostringstream name; + name << "GRP_" << f->getName() << "_" << j; + sup->setName( name.str() ); + } f->setSupport( sup ); //f->setIterationNumber( j ); f->setOrderNumber( j ); @@ -968,13 +1069,15 @@ bool _fieldBase::hasSameComponentsBySupport() const const _sub_data& first_sub_data = *sub_data; for ( ++sub_data ; sub_data != _sub.end(); ++sub_data ) { - if ( first_sub_data.nbComponents() != sub_data->nbComponents() ) - return false; - for ( int iComp = 0; iComp < first_sub_data.nbComponents(); ++iComp ) - if ( first_sub_data._comp_names[ iComp ] != sub_data->_comp_names[ iComp ]) - return false; + if ( first_sub_data._comp_names != sub_data->_comp_names ) + return false; // diff names of components + + if ( first_sub_data._nb_gauss != sub_data->_nb_gauss ) + return false; // diff nb of gauss points } return true; } +} + ///// diff --git a/src/MEDMEM/MEDMEM_DriverTools.hxx b/src/MEDMEM/MEDMEM_DriverTools.hxx index 605f4e89e..267e02639 100644 --- a/src/MEDMEM/MEDMEM_DriverTools.hxx +++ b/src/MEDMEM/MEDMEM_DriverTools.hxx @@ -20,10 +20,15 @@ #ifndef DRIVERTOOLS_HXX #define DRIVERTOOLS_HXX +#include + #include "MEDMEM_define.hxx" #include "MEDMEM_Exception.hxx" #include "MEDMEM_FieldForward.hxx" #include "MEDMEM_ArrayInterface.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_GaussLocalization.hxx" + #include #include #include @@ -32,6 +37,12 @@ #include #include +// Way of storing values with gauss points by CASTEM: full/no interlace. +// Remove code switched by this symbol as soon as the way is found out, +// from here and from gibi driver +#define CASTEM_FULL_INTERLACE + + namespace MEDMEM { class MESH; class CONNECTIVITY; @@ -39,7 +50,8 @@ class COORDINATE; class GROUP; class FAMILY; class FIELD_; -struct _noeud + +struct MEDMEM_EXPORT _noeud { mutable int number; std::vector coord; @@ -47,7 +59,7 @@ struct _noeud typedef pair _link; // a pair of node numbers -struct _maille +struct MEDMEM_EXPORT _maille { typedef std::map::iterator iter; MED_EN::medGeometryElement geometricType; @@ -72,7 +84,7 @@ struct _maille _link link(int i) const; }; -struct _mailleIteratorCompare // pour ordonner le set d'iterateurs sur mailles +struct MEDMEM_EXPORT _mailleIteratorCompare // pour ordonner le set d'iterateurs sur mailles { bool operator () (std::set<_maille>::iterator i1, std::set<_maille>::iterator i2) { @@ -80,7 +92,7 @@ struct _mailleIteratorCompare // pour ordonner le set d'iterateurs sur mailles } }; -struct _groupe +struct MEDMEM_EXPORT _groupe { typedef std::vector< std::set<_maille>::iterator>::const_iterator mailleIter; std::string nom; @@ -90,16 +102,23 @@ struct _groupe bool empty() const { return mailles.empty() && groupes.empty(); } }; -struct _fieldBase { +struct MEDMEM_EXPORT _fieldBase { // a field contains several subcomponents each referring to its own support and // having several named components - struct _sub_data { + struct _sub_data // a subcomponent + { int _supp_id; // group index within _intermediateMED::groupes - std::vector _comp_names; // componenet names + std::vector _comp_names; // component names + std::vector _nb_gauss; // nb values per element in a component + void setData( int nb_comp, int supp_id ) - { _supp_id = supp_id - 1; _comp_names.resize(nb_comp); } + { _supp_id = supp_id - 1; _comp_names.resize(nb_comp); _nb_gauss.resize(nb_comp,1); } int nbComponents() const { return _comp_names.size(); } std::string & compName( int i_comp ) { return _comp_names[ i_comp ]; } + bool isValidNbGauss() const { return *std::max_element( _nb_gauss.begin(), _nb_gauss.end() ) == + *std::min_element( _nb_gauss.begin(), _nb_gauss.end() ); } + int nbGauss() const { return std::max( 1, _nb_gauss[0] ); } + bool hasGauss() const { return nbGauss() > 1; } }; std::vector< _sub_data > _sub; int _group_id; // group index within _intermediateMED::groupes @@ -107,11 +126,13 @@ struct _fieldBase { // are converted into one MEDMEM::FIELD. The latter is possible only if nb of components in all subs // is the same and supports of subcomponents do not overlap MED_EN::med_type_champ _type; - string _name; + std::string _name; + std::string _description;// field description _fieldBase( MED_EN::med_type_champ theType, int nb_sub ) : _group_id(-1),_type(theType) { _sub.resize( nb_sub ); } - virtual std::list > getField(std::vector<_groupe>& groupes) const = 0; + virtual std::list > getField(std::vector<_groupe>& groupes, + std::vector& medGroups) const = 0; void getGroupIds( std::set & ids, bool all ) const; // return ids of main and/or sub-groups bool hasCommonSupport() const { return _group_id >= 0; } // true if there is one support for all subs bool hasSameComponentsBySupport() const; @@ -126,7 +147,8 @@ template< class T > class _field: public _fieldBase _field< T > ( MED_EN::med_type_champ theType, int nb_sub, int total_nb_comp ) : _fieldBase( theType, nb_sub ) { comp_values.reserve( total_nb_comp ); } std::vector< T >& addComponent( int nb_values ); // return a vector ready to fill in - std::list > getField(std::vector<_groupe>& groupes) const; + std::list > getField(std::vector<_groupe>& groupes, + std::vector& medGroups) const; virtual void dump(std::ostream&) const; }; @@ -140,31 +162,34 @@ template< class T > class _field: public _fieldBase * Read the conception ducumentation for more details. * \endif */ -struct _intermediateMED +struct MEDMEM_EXPORT _intermediateMED { - std::set<_maille> maillage; - std::vector<_groupe> groupes; - std::vector medGroupes; - std::map< int, _noeud > points; - std::list< _fieldBase* > fields; - bool hasMixedCells; // true if there are groups with mixed entity types - - CONNECTIVITY * getConnectivity(); // set MED connectivity from the intermediate structure - COORDINATE * getCoordinate(const string & coordinateSystem="CARTESIAN"); // set MED coordinate from the - // intermediate structure - void getFamilies(std::vector & _famCell, std::vector & _famFace, - std::vector & _famEdge, std::vector & _famNode, MESH * _ptrMesh); - void getGroups(std::vector & _groupCell, std::vector & _groupFace, - std::vector & _groupEdge, std::vector & _groupNode, MESH * _ptrMesh); - GROUP * getGroup( int i ); - - void getFields(std::list< FIELD_* >& fields); - - // used by previous functions to renumber points & mesh. - void treatGroupes(); // detect groupes of mixed dimention - void numerotationMaillage(); - void numerotationPoints(); + std::set<_maille> maillage; + std::vector<_groupe> groupes; + std::vector medGroupes; + std::map< int, _noeud > points; + std::list< _fieldBase* > fields; + bool hasMixedCells; // true if there are groups with mixed entity types + + CONNECTIVITY * getConnectivity(); // set MED connectivity from the intermediate structure + COORDINATE * getCoordinate(const string & coordinateSystem="CARTESIAN"); // set MED coordinate from the + // intermediate structure + void getFamilies(std::vector & _famCell, std::vector & _famFace, + std::vector & _famEdge, std::vector & _famNode, MESH * _ptrMesh); + void getGroups(std::vector & _groupCell, std::vector & _groupFace, + std::vector & _groupEdge, std::vector & _groupNode, MESH * _ptrMesh); + GROUP * getGroup( int i ); + + void getFields(std::list< FIELD_* >& fields); + // used by previous functions to renumber points & mesh. + void treatGroupes(); // detect groupes of mixed dimention + void numerotationMaillage(); + void numerotationPoints(); + bool myGroupsTreated; + bool myPointsNumerated; + + _intermediateMED() { myGroupsTreated = myPointsNumerated = false; } ~_intermediateMED(); }; @@ -193,89 +218,193 @@ template //======================================================================= template -std::list > _field< T >::getField(std::vector<_groupe> & groupes) const +std::list > _field< T >::getField(std::vector<_groupe> & groupes, + std::vector & medGroups) const { + const char* LOC = "_field< T >::getField()"; + std::list > res; - _groupe* grp = 0; - if ( hasCommonSupport() ) { // several subs are combined into one field - grp = & groupes[ _group_id ]; - if ( !grp || grp->empty() ) + // gauss array data + int nbtypegeo = 0; + vector nbelgeoc(2,0), nbgaussgeo(2,0); + + int i_comp_tot = 0, nb_fields = 0; + std::set supp_id_set; // to create a new field when support repeats if hasCommonSupport() + std::vector< _sub_data >::const_iterator sub_data, sub_end = _sub.end(); + + _groupe* grp = 0; + GROUP* medGrp = 0; + if ( hasCommonSupport() ) // several subs are combined into one field + { + grp = & groupes[ _group_id ]; + medGrp = medGroups[ _group_id ]; + if ( !grp || grp->empty() || !medGrp || !medGrp->getNumberOfTypes()) return res; + + // Make gauss array data + nbtypegeo = medGrp->getNumberOfTypes(); + nbelgeoc .resize( nbtypegeo + 1, 0 ); + nbgaussgeo.resize( nbtypegeo + 1, 0 ); + const int * nbElemByType = medGrp->getNumberOfElements(); + sub_data = _sub.begin(); + for (int iType = 0; iType < nbtypegeo; ++iType) { + nbelgeoc [ iType+1 ] = nbelgeoc[ iType ] + nbElemByType[ iType ]; + nbgaussgeo[ iType+1 ] = sub_data->nbGauss(); + int nbElemInSubs = 0; + while ( nbElemInSubs < nbElemByType[ iType ] && sub_data != sub_end ) { + nbElemInSubs += groupes[ sub_data->_supp_id ].relocMap.size(); + ++sub_data; + } + } } - FIELD< T, NoInterlace > * f = 0; - int i_comp_tot = 0, nb_fields = 0; - std::set supp_id_set; + typedef typename MEDMEM_ArrayInterface::Array TArrayNoGauss; + typedef typename MEDMEM_ArrayInterface::Array TArrayGauss; + FIELD< T, FullInterlace > * f = 0; + TArrayNoGauss * arrayNoGauss = 0; + TArrayGauss * arrayGauss = 0; + // loop on subs of this field - std::vector< _sub_data >::const_iterator sub_data = _sub.begin(); - for ( int i_sub = 1; sub_data != _sub.end(); ++sub_data, ++i_sub ) + int i_sub = 1; + for ( sub_data = _sub.begin(); sub_data != sub_end; ++sub_data, ++i_sub ) { // nb values in a field - if ( !hasCommonSupport() ) - grp = & groupes[ sub_data->_supp_id ]; + if ( !hasCommonSupport() ) { + grp = & groupes[ sub_data->_supp_id ]; + medGrp = medGroups[ sub_data->_supp_id ]; + } int nb_val = grp->relocMap.size(); + + // check validity of a sub_data + bool validSub = true; if ( !nb_val ) { INFOS("Skip field <" << _name << ">: invalid supporting group " << (hasCommonSupport() ? _group_id : sub_data->_supp_id ) << " of " << i_sub << "-th subcomponent" ); - return res; + validSub = false; + } + if ( !sub_data->isValidNbGauss() ) { + INFOS("Skip field <" << _name << ">: different nb of gauss points in components "); + validSub = false; + } + if ( !validSub ) { + if ( hasCommonSupport() ) { + if ( !res.empty() ) { + delete f; + res.clear(); + } + return res; + } + i_comp_tot += sub_data->nbComponents(); + continue; } - //create a field + // Create a field + if ( !f || !hasCommonSupport() || !supp_id_set.insert( sub_data->_supp_id ).second ) { - supp_id_set.clear(); ++nb_fields; - f = new FIELD< T, NoInterlace >(); + supp_id_set.clear(); + arrayNoGauss = 0; + arrayGauss = 0; + + f = new FIELD< T, FullInterlace >(); + f->setNumberOfComponents( sub_data->nbComponents() ); f->setComponentsNames( & sub_data->_comp_names[ 0 ] ); f->setNumberOfValues ( nb_val ); f->setName( _name ); - // f->setValueType( _type ); + f->setDescription( _description ); vector str( sub_data->nbComponents() ); f->setComponentsDescriptions( &str[0] ); f->setMEDComponentsUnits( &str[0] ); + res.push_back( make_pair( f , hasCommonSupport() ? _group_id : sub_data->_supp_id )); MESSAGE(" MAKE " << nb_fields << "-th field <" << _name << "> on group_id " << _group_id ); + + // make an array + if ( !sub_data->hasGauss() ) { + arrayNoGauss = new TArrayNoGauss( sub_data->nbComponents(), nb_val ); + f->setArray( arrayNoGauss ); + } + else { + if ( !hasCommonSupport() ) { + nbtypegeo = 1; + nbelgeoc [1] = nb_val; + nbgaussgeo[1] = sub_data->nbGauss(); + } + arrayGauss = new TArrayGauss(sub_data->nbComponents(), nb_val, + nbtypegeo, & nbelgeoc[0], & nbgaussgeo[0]); + f->setArray( arrayGauss ); + + // PAL11040 "GIBI driver for Castem fields with Gauss point values" + const MED_EN::medGeometryElement* types = medGrp->getTypes(); + for (int iGeom = 0; iGeom < nbtypegeo; ++iGeom) { + ostringstream name; + name << "Gauss_" << nbgaussgeo[iGeom+1] << "points_on" << types[iGeom] << "geom"; + GAUSS_LOCALIZATION_* loc = GAUSS_LOCALIZATION_::makeDefaultLocalization + (name.str(), types[iGeom], nbgaussgeo[iGeom+1]); + f->setGaussLocalization( types[iGeom], loc ); + } + } } - // set values - MEDMEM_Array< T, NoInterlaceNoGaussPolicy > * medarray = - new MEDMEM_Array < T, NoInterlaceNoGaussPolicy >( sub_data->nbComponents(), - nb_val ); - f->setArray( medarray ); + + // Set values + + // get nb elements in a group + _groupe & sub_grp = groupes[ sub_data->_supp_id ]; + int nb_supp_elems = sub_grp.mailles.size(); + int nb_gauss = sub_data->nbGauss(); + MESSAGE("insert sub data, group_id: " << sub_data->_supp_id << + ", nb values: " << comp_values[ i_comp_tot ].size() << + ", relocMap size: " << sub_grp.relocMap.size() << + ", nb mailles: " << nb_supp_elems); + +#ifdef CASTEM_FULL_INTERLACE + const int gauss_step = 1; + const int elem_step = nb_gauss; +#else + const int gauss_step = nb_supp_elems; + const int elem_step = 1; +#endif + int i; // elem index // loop on components of a sub - for ( int i_comp = 0; i_comp < sub_data->nbComponents(); ++i_comp ) + for ( int i_comp = 1; i_comp <= sub_data->nbComponents(); ++i_comp ) { - // get nb elements in a group - _groupe & sub_grp = groupes[ sub_data->_supp_id ]; - int nb_supp_elems = sub_grp.mailles.size(); - MESSAGE("insert sub data, group_id: " << sub_data->_supp_id << - ", nb values: " << comp_values[ i_comp_tot ].size() << - ", relocMap.size: " << sub_grp.relocMap.size() << - ", nb mailles: " << nb_supp_elems); - // store values const std::vector< T > & values = comp_values[ i_comp_tot++ ]; bool oneValue = ( values.size() == 1 ); - ASSERT( oneValue || values.size() == nb_supp_elems ); + ASSERT( oneValue || values.size() == nb_supp_elems * nb_gauss ); for ( int k = 0; k < nb_supp_elems; ++k ) { - const T& val = oneValue ? values[ 0 ] : values[ k ]; + const T& val = oneValue ? values[ 0 ] : values[ k * elem_step ]; const _maille* ma = &(*sub_grp.mailles[ k ]); - std::map::const_iterator ma_i = grp->relocMap.find( ma ); - if ( ma_i == grp->relocMap.end() ) - throw MEDEXCEPTION - (LOCALIZED(STRING("_field< T >::getField(), cant find elem index. ") - << k << "-th elem: " << ma)); - if ( ma_i->second > nb_val ) - throw MEDEXCEPTION - (LOCALIZED(STRING("_field< T >::getField(), wrong elem position. ") - << k << "-th elem: " << ma - << ", pos (" << ma_i->second << ") must be <= " << nb_val)); - medarray->setIJ( ma_i->second, i_comp + 1, val ); + if ( medGrp->isOnAllElements() ) { + i = ma->ordre; + if ( i > nb_val ) + throw MEDEXCEPTION (LOCALIZED(STRING(LOC) << ", wrong elem position. " + << k << "-th elem: " << ma + << ", pos (" << i << ") must be <= " << nb_val)); + } + else { + std::map::const_iterator ma_i = grp->relocMap.find( ma ); + if ( ma_i == grp->relocMap.end() ) + throw MEDEXCEPTION (LOCALIZED(STRING(LOC) << ", cant find elem index. " + << k << "-th elem: " << ma)); + i = ma_i->second; + } + if ( arrayNoGauss ) { + arrayNoGauss->setIJ( i, i_comp, val ); + } + else { + const T* pVal = & val; + for ( int iGauss = 1; iGauss <= nb_gauss; ++iGauss, pVal += gauss_step ) + arrayGauss->setIJK( i, i_comp, iGauss, *pVal); + } } } - } + } // loop on subs of the field + return res; } @@ -284,7 +413,7 @@ template void _field< T >::dump(std::ostream& os) const { _fieldBase::dump(os); os << endl; - for ( int i = 0 ; i < comp_values.size(); ++i ) + for ( int i = 0 ; i < (int)comp_values.size(); ++i ) { os << " " << i+1 << "-th component, nb values: " << comp_values[ i ].size() << endl; } diff --git a/src/MEDMEM/MEDMEM_DriversDef.cxx b/src/MEDMEM/MEDMEM_DriversDef.cxx index 2fd03f1c1..dc65ac489 100644 --- a/src/MEDMEM/MEDMEM_DriversDef.cxx +++ b/src/MEDMEM/MEDMEM_DriversDef.cxx @@ -44,7 +44,9 @@ GEO_NAME::GEO_NAME() : map() table[(int)MED_PENTA15] = "MED_PENTA15"; table[(int)MED_PYRA5 ] = "MED_PYRA5" ; table[(int)MED_PYRA13 ] = "MED_PYRA13" ; - assert( table.find( (int)MED_PYRA13 ) != table.end() ) ; + table[(int)MED_POLYGON] = "MED_POLYGON"; + table[(int)MED_POLYHEDRA] = "MED_POLYHEDRA"; + assert( table.find( (int)MED_POLYHEDRA ) != table.end() ) ; } GEO_NAME::~GEO_NAME() @@ -110,7 +112,9 @@ MESH_ENTITIES::MESH_ENTITIES () : map geomList(T,T+sizeof(T)/sizeof(MED_EN::medGeometryElement)); (*this)[MED_CELL] = geomList; @@ -121,7 +125,8 @@ MESH_ENTITIES::MESH_ENTITIES () : map geomList(T,T+sizeof(T)/sizeof(MED_EN::medGeometryElement)); (*this)[MED_FACE] = geomList; diff --git a/src/MEDMEM/MEDMEM_DriversDef.hxx b/src/MEDMEM/MEDMEM_DriversDef.hxx index 62f91791e..2c54c6c35 100644 --- a/src/MEDMEM/MEDMEM_DriversDef.hxx +++ b/src/MEDMEM/MEDMEM_DriversDef.hxx @@ -20,6 +20,8 @@ # ifndef DRIVERS_DEF_HXX # define DRIVERS_DEF_HXX +#include + // STL # include # include @@ -39,7 +41,7 @@ namespace MED_EN { the name of the geometry of an element : MED_FR:GEO_NAME A simple test/use case can be found in test/testUGeoNameMeshEntities.cxx */ //---------------------------------------- -class GEO_NAME : public map +class MEDMEM_EXPORT GEO_NAME : public map //---------------------------------------- { @@ -63,7 +65,7 @@ static const GEO_NAME geoNames ; A simple test/use case can be found in test/testUGeoNameMeshEntities.cxx */ //---------------------------------------- -class ENT_NAME : public map +class MEDMEM_EXPORT ENT_NAME : public map //---------------------------------------- { @@ -88,7 +90,7 @@ static const ENT_NAME entNames ; //-------------------------------------------------------------------------------- -class MESH_ENTITIES : public map > +class MEDMEM_EXPORT MESH_ENTITIES : public map > //-------------------------------------------------------------------------------- { diff --git a/src/MEDMEM/MEDMEM_EnsightFieldDriver.hxx b/src/MEDMEM/MEDMEM_EnsightFieldDriver.hxx new file mode 100644 index 000000000..e23c6aac3 --- /dev/null +++ b/src/MEDMEM/MEDMEM_EnsightFieldDriver.hxx @@ -0,0 +1,907 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef ENSIGHT_FIELD_DRIVER_HXX +#define ENSIGHT_FIELD_DRIVER_HXX + +#include +#include +#include +#include + +#include "MEDMEM_define.hxx" + +#include "MEDMEM_GenDriver.hxx" +#include "MEDMEM_Utilities.hxx" + +#include "MEDMEM_ArrayInterface.hxx" + +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Unit.hxx" +#include "MEDMEM_nArray.hxx" +#include "MEDMEM_ArrayConvert.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_CellModel.hxx" + + +/*! + + Driver Ensight for FIELD. + + Generic part : implement open and close methods. + +*/ + +namespace MEDMEM { + +template class ENSIGHT_FIELD_DRIVER : public GENDRIVER +{ +protected: + FIELD * _ptrField; + string _fieldName; + int _fieldNum; + +public : + + /*! + Constructor. + */ + ENSIGHT_FIELD_DRIVER():GENDRIVER(), + _ptrField((FIELD *) 0), _fieldName(""), + _fieldNum(MED_INVALID) + {} + /*! + Constructor. + */ + template + ENSIGHT_FIELD_DRIVER(const string & fileName, + FIELD * ptrField, + MED_EN::med_mode_acces accessMode): + GENDRIVER(fileName,accessMode), + _ptrField((FIELD *) ptrField), + _fieldNum(MED_INVALID) + { + _fieldName = ptrField->getName(); + } + + /*! + Copy constructor. + */ + ENSIGHT_FIELD_DRIVER(const ENSIGHT_FIELD_DRIVER & fieldDriver): + GENDRIVER(fieldDriver), + _ptrField(fieldDriver._ptrField), + _fieldName(fieldDriver._fieldName), + _fieldNum(fieldDriver._fieldNum) + { + } + + /*! + Destructor. + */ + virtual ~ENSIGHT_FIELD_DRIVER() + { + } + virtual void open() throw (MEDEXCEPTION) = 0; + virtual void close() =0; + virtual void write( void ) const = 0 ; + virtual void read ( void ) = 0 ; + + /*! + Set the name of the FIELD asked in file. + + It could be different than the name of the FIELD object. + */ + virtual void setFieldName(const string & fieldName) { _fieldName = fieldName; } + /*! + Get the name of the FIELD asked in file. + */ + virtual string getFieldName() const { return _fieldName; } +protected: + virtual GENDRIVER * copy ( void ) const = 0 ; + +}; + + + +template class ENSIGHT_FIELD_RDONLY_DRIVER : public ENSIGHT_FIELD_DRIVER +{ + +public : + + /*! + Constructor. + */ + ENSIGHT_FIELD_RDONLY_DRIVER():ENSIGHT_FIELD_DRIVER() + { + const char * LOC = "ENSIGHT_FIELD_RDONLY_DRIVER::ENSIGHT_FIELD_RDONLY_DRIVER() "; + BEGIN_OF(LOC); + + _ensightFile = new ifstream(); + + END_OF(LOC); + } + /*! + Constructor. + */ + template + ENSIGHT_FIELD_RDONLY_DRIVER(const string & fileName, + FIELD * ptrField):ENSIGHT_FIELD_DRIVER(fileName,ptrField,MED_EN::MED_RDONLY) + { + const char * LOC = "ENSIGHT_FIELD_RDONLY_DRIVER::ENSIGHT_FIELD_RDONLY_DRIVER(const string & fileName, FIELD * ptrField) "; + BEGIN_OF(LOC); + _ensightFile = new ifstream(); + + END_OF(LOC); + } + + /*! + Copy constructor. + */ + ENSIGHT_FIELD_RDONLY_DRIVER(const ENSIGHT_FIELD_RDONLY_DRIVER & fieldDriver):ENSIGHT_FIELD_DRIVER(fieldDriver) + { + _ensightFile = new ifstream(); + } + + /*! + Destructor. + */ + ~ENSIGHT_FIELD_RDONLY_DRIVER() + { + const char * LOC ="ENSIGHT_FIELD_RDONLY_DRIVER::~ENSIGHT_FIELD_RDONLY_DRIVER()"; + BEGIN_OF(LOC); + + close(); + + SCRUTE(_ensightFile); + + delete _ensightFile ; + + SCRUTE(_ensightFile); + + END_OF(LOC); + } + + void openConst() const throw (MEDEXCEPTION) + { + const char * LOC = "ENSIGHT_FIELD_RDONLY_DRIVER::openConst()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< ENSIGHT_FIELD_DRIVER::_fileName.c_str()<<",mode : "<< ENSIGHT_FIELD_DRIVER::_accessMode); + + if ( ENSIGHT_FIELD_DRIVER::_fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + if (!(*_ensightFile).is_open()) + (*_ensightFile).open(ENSIGHT_FIELD_DRIVER::_fileName.c_str()) ; + + SCRUTE((*_ensightFile).is_open()); + SCRUTE(_ensightFile); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << ENSIGHT_FIELD_DRIVER::_fileName) + ); +// _ensightFile.setf(ios::scientific); +// _ensightFile.precision(5); + END_OF(LOC); + } + + void openConstAppend() const throw (MEDEXCEPTION) + { + const char * LOC = "ENSIGHT_FIELD_DRIVER::openConstAppend()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< ENSIGHT_FIELD_DRIVER::_fileName.c_str()<<",mode : "<< ENSIGHT_FIELD_DRIVER::_accessMode); + + if ( ENSIGHT_FIELD_DRIVER::_fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + SCRUTE((*_ensightFile).is_open()); + + if (!(*_ensightFile).is_open()) + { + MESSAGE(LOC<<"The file is already close and it is opened with the right option"); + (*_ensightFile).open(ENSIGHT_FIELD_DRIVER::_fileName.c_str(), ofstream::out | ofstream::app) ; + } + else + { + MESSAGE(LOC<<"The file is still open, it is closed to make sure that it will be opened with the right option"); + + (*_ensightFile).close() ; + + _ensightFile->open(ENSIGHT_FIELD_DRIVER::_fileName.c_str(), ofstream::out | ofstream::app) ; + } + + SCRUTE((*_ensightFile).is_open()); + SCRUTE(_ensightFile); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << ENSIGHT_FIELD_DRIVER::_fileName) + ); +// _ensightFile.setf(ios::scientific); +// _ensightFile.precision(5); + END_OF(LOC); + } + + void open() throw (MEDEXCEPTION) + { + openConst() ; + } + + void openAppend() throw (MEDEXCEPTION) + { + openConstAppend() ; + } + + void closeConst() const throw (MEDEXCEPTION) + { + const char * LOC = "ENSIGHT_FIELD_DRIVER::closeConst() " ; + BEGIN_OF(LOC); + + SCRUTE(_ensightFile); + SCRUTE(*_ensightFile); + + + if ((*_ensightFile).is_open()) + (*_ensightFile).close(); + + SCRUTE(_ensightFile); + SCRUTE(*_ensightFile); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file " + << ENSIGHT_FIELD_DRIVER::_fileName) + ); + + END_OF(LOC); + } + + void close() { + closeConst() ; + } + + /*! + Set the name of the FIELD asked in file. + + It could be different than the name of the FIELD object. + */ + void setFieldName(const string & fieldName) ; + + /*! + Get the name of the FIELD asked in file. + */ + string getFieldName() const ; + + /*! + Return a MEDEXCEPTION : it is the write-only driver. + */ + void read ( void ) throw (MEDEXCEPTION) ; + + /*! + Write FIELD in the specified file, with its mesh through its support + which has to be on all entities (excluding the faces in 3d and edges + in 2d). + */ + void write( void ) const throw (MEDEXCEPTION) ; + + /*! + Write FIELD in the specified file, the mesh is supposed to be + written in this file. The field support has to be on all entities + (excluding the faces in 3d and edges in 2d). + */ + void writeAppend( void ) const throw (MEDEXCEPTION); + +private: + ifstream * _ensightFile; // The main _ensightFile used to read + GENDRIVER * copy ( void ) const ; + +}; + +template class ENSIGHT_FIELD_WRONLY_DRIVER : public ENSIGHT_FIELD_DRIVER +{ + +public : + + /*! + Constructor. + */ + ENSIGHT_FIELD_WRONLY_DRIVER():ENSIGHT_FIELD_DRIVER() + { + const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::ENSIGHT_FIELD_WRONLY_DRIVER() "; + BEGIN_OF(LOC); + + _ensightFile = new ifstream(); + + END_OF(LOC); + } + /*! + Constructor. + */ + template + ENSIGHT_FIELD_WRONLY_DRIVER(const string & fileName, + FIELD * ptrField): + ENSIGHT_FIELD_DRIVER(fileName,ptrField,MED_EN::MED_WRONLY) + { + const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::ENSIGHT_FIELD_WRONLY_DRIVER(const string & fileName, FIELD * ptrField) "; + BEGIN_OF(LOC); + _ensightFile = new ifstream(); + + END_OF(LOC); + } + + /*! + Copy constructor. + */ + ENSIGHT_FIELD_WRONLY_DRIVER(const ENSIGHT_FIELD_WRONLY_DRIVER & fieldDriver):ENSIGHT_FIELD_DRIVER(fieldDriver) + { + _ensightFile = new ifstream(); + } + + /*! + Destructor. + */ + ~ENSIGHT_FIELD_WRONLY_DRIVER() + { + const char * LOC ="ENSIGHT_FIELD_WRONLY_DRIVER::~ENSIGHT_FIELD_WRONLY_DRIVER()"; + BEGIN_OF(LOC); + + close(); + + SCRUTE(_ensightFile); + + delete _ensightFile ; + + SCRUTE(_ensightFile); + + END_OF(LOC); + } + + void openConst() const throw (MEDEXCEPTION) + { + const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::openConst()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< ENSIGHT_FIELD_DRIVER::_fileName.c_str()<<",mode : "<< ENSIGHT_FIELD_DRIVER::_accessMode); + + if ( ENSIGHT_FIELD_DRIVER::_fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + if (!(*_ensightFile).is_open()) + (*_ensightFile).open(ENSIGHT_FIELD_DRIVER::_fileName.c_str()) ; + + SCRUTE((*_ensightFile).is_open()); + SCRUTE(_ensightFile); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << ENSIGHT_FIELD_DRIVER::_fileName) + ); +// _ensightFile.setf(ios::scientific); +// _ensightFile.precision(5); + END_OF(LOC); + } + + void openConstAppend() const throw (MEDEXCEPTION) + { + const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::openConstAppend()" ; + BEGIN_OF(LOC); + + MESSAGE(LOC<<" : _fileName.c_str : "<< ENSIGHT_FIELD_DRIVER::_fileName.c_str()<<",mode : "<< ENSIGHT_FIELD_DRIVER::_accessMode); + + if ( ENSIGHT_FIELD_DRIVER::_fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + SCRUTE((*_ensightFile).is_open()); + + if (!(*_ensightFile).is_open()) + { + MESSAGE(LOC<<"The file is already close and it is opened with the right option"); + (*_ensightFile).open(ENSIGHT_FIELD_DRIVER::_fileName.c_str(), ofstream::out | ofstream::app) ; + } + else + { + MESSAGE(LOC<<"The file is still open, it is closed to make sure that it will be opened with the right option"); + + (*_ensightFile).close() ; + + _ensightFile->open(ENSIGHT_FIELD_DRIVER::_fileName.c_str(), ofstream::out | ofstream::app) ; + } + + SCRUTE((*_ensightFile).is_open()); + SCRUTE(_ensightFile); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file " + << ENSIGHT_FIELD_DRIVER::_fileName) + ); +// _ensightFile.setf(ios::scientific); +// _ensightFile.precision(5); + END_OF(LOC); + } + + void open() throw (MEDEXCEPTION) + { + openConst() ; + } + + void openAppend() throw (MEDEXCEPTION) + { + openConstAppend() ; + } + + void closeConst() const throw (MEDEXCEPTION) + { + const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::closeConst() " ; + BEGIN_OF(LOC); + + SCRUTE(_ensightFile); + SCRUTE(*_ensightFile); + + + if ((*_ensightFile).is_open()) + (*_ensightFile).close(); + + SCRUTE(_ensightFile); + SCRUTE(*_ensightFile); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file " + << ENSIGHT_FIELD_DRIVER::_fileName) + ); + + END_OF(LOC); + } + + void close() { + closeConst() ; + } + + /*! + Set the name of the FIELD asked in file. + + It could be different than the name of the FIELD object. + */ + void setFieldName(const string & fieldName) ; + + /*! + Get the name of the FIELD asked in file. + */ + string getFieldName() const ; + + /*! + Return a MEDEXCEPTION : it is the write-only driver. + */ + void read ( void ) throw (MEDEXCEPTION) ; + + /*! + Write FIELD in the specified file, with its mesh through its support + which has to be on all entities (excluding the faces in 3d and edges + in 2d). + */ + void write( void ) const throw (MEDEXCEPTION) ; + + /*! + Write FIELD in the specified file, the mesh is supposed to be + written in this file. The field support has to be on all entities + (excluding the faces in 3d and edges in 2d). + */ + void writeAppend( void ) const throw (MEDEXCEPTION); + +private: + ifstream * _ensightFile; // The main _ensightFile used to read + GENDRIVER * copy ( void ) const ; + +}; + +/*-------------------------*/ +/* template implementation */ +/*-------------------------*/ + +/*--------------------- DRIVER PART -------------------------------*/ + +template void ENSIGHT_FIELD_RDONLY_DRIVER::setFieldName(const string & fieldName) +{ + GENDRIVER::setFieldName(fieldName); +} + +template string ENSIGHT_FIELD_RDONLY_DRIVER::getFieldName() const +{ + return ENSIGHT_FIELD_DRIVER::_fieldName; +} + +template GENDRIVER * ENSIGHT_FIELD_RDONLY_DRIVER::copy(void) const +{ + ENSIGHT_FIELD_RDONLY_DRIVER * myDriver = new ENSIGHT_FIELD_RDONLY_DRIVER(*this); + + return myDriver ; +} + +template void ENSIGHT_FIELD_RDONLY_DRIVER::read (void) + throw (MEDEXCEPTION) +{ + + vector var ; + double myVar ; + char ligne[80]; + string mot_lu ; + + string field_namefile ; + string field_read_name ; + + int is_scalar=0 ; + int is_vector=0; + int is_node=0; + int is_element=0; + + // recuperation des valeurs du champ + + ifstream ensightCaseFile(ENSIGHT_FIELD_DRIVER::_fileName.c_str(),ios::in); + cout << "-> Ensight case file name to read " << ENSIGHT_FIELD_DRIVER::_fileName << endl ; + + field_read_name = "EnsightField"; // defaut name for the field + + if (ensightCaseFile.is_open() ) + { + while ( ensightCaseFile >> mot_lu ) + { + if ( mot_lu == "VARIABLE" ) { + cout << "field detected" << endl ; + while ( ensightCaseFile >> mot_lu ){ + if ( mot_lu == "scalar" || mot_lu == "vector" ) { + if ( mot_lu == "scalar" ) is_scalar = 1 ; + if ( mot_lu == "vector" ) is_vector = 1 ; + ensightCaseFile >> mot_lu ; //per + ensightCaseFile >> mot_lu ; //node + if ( mot_lu == "node:" ) is_node = 1 ; + if ( mot_lu == "element:" ) is_element = 1 ; + else { + ensightCaseFile >> mot_lu ; //description + ensightCaseFile >> mot_lu ; + field_namefile = mot_lu ; + cout << "name of field : " << field_namefile << endl ; + break ; // couple la boucle sur les champs + } + } + } + // cout << " scalar " << is_scalar << " vector " << is_vector << " node " << is_node << " element " << is_element << endl ; + if ( !(is_scalar+is_vector) ) { + cout << " the field ist not a scalar and is not a vector " << endl ; + break ; + } + else if ( !(is_node+is_element) ) { + cout << " the field ist not on nodes and is not on elements " << endl ; + break ; + } + } + } + } + else + { + cout << "Error : requested file " << ensightCaseFile << " not found " << endl; + exit( EXIT_FAILURE ); + } + + ifstream ensightFieldFile(field_namefile.c_str(),ios::in); + cout << "-> Entering into the field file " << field_namefile << endl ; + + if ( ensightFieldFile.is_open() ) + { + ensightFieldFile.getline(ligne, 80, '\n') ; // read the first line of comment + +// while ( ensightFieldFile.eof() == 0 ) + + while ( ensightFieldFile >> setw(12) >> myVar ) + { + var.push_back(myVar) ; + } + } + int NumberOfValues = var.size() ; + + // construction med + + ENSIGHT_FIELD_DRIVER::_ptrField->setName(field_read_name) ; + + int NumberOfComponents = 1 ; + if ( is_vector ) NumberOfComponents = 3 ; + ENSIGHT_FIELD_DRIVER::_ptrField->setNumberOfComponents(NumberOfComponents) ; + string * componentsNames = new string[NumberOfComponents] ; + if ( NumberOfComponents == 1 ) componentsNames[0] = "scalar comp" ; + else if ( NumberOfComponents == 3 ) { + componentsNames[0] = "X comp" ; + componentsNames[1] = "Y comp" ; + componentsNames[2] = "Z comp" ; + } + ENSIGHT_FIELD_DRIVER::_ptrField->setComponentsNames(componentsNames); + delete[] componentsNames ; + + ENSIGHT_FIELD_DRIVER::_ptrField->setNumberOfValues(NumberOfValues); + + int NumberOf = NumberOfValues / NumberOfComponents; + cout << "-> Loading " << NumberOf << " NumberOf values " << endl ; + ENSIGHT_FIELD_DRIVER::_ptrField->allocValue(NumberOfComponents); + for ( int i = 1 ; i <= NumberOf ; i++) { + for ( int j = 1 ; j <= NumberOfComponents ; j++) { +// cout << "-> EnsightFieldDriver : write v = " << var[NumberOfComponents*(i-1)+j-1] << endl ; + ENSIGHT_FIELD_DRIVER::_ptrField->setValueIJ(i,j,(T)var[NumberOfComponents*(i-1)+j-1]); + } + } + cout << "NOM DU MAILLAGE : " << ENSIGHT_FIELD_DRIVER::_ptrField->getSupport()->getMesh()->getName() << endl; + +} + +template void ENSIGHT_FIELD_RDONLY_DRIVER::write(void) const + throw (MEDEXCEPTION) +{ + throw MEDEXCEPTION("ENSIGHT_FIELD_RDONLY_DRIVER::write : Can't write with a RDONLY driver !"); +} + +template void ENSIGHT_FIELD_RDONLY_DRIVER::writeAppend(void) const + throw (MEDEXCEPTION) +{ + throw MEDEXCEPTION("ENSIGHT_FIELD_RDONLY_DRIVER::write : Can't write with a RDONLY driver !"); +} + +template void ENSIGHT_FIELD_WRONLY_DRIVER::setFieldName(const string & fieldName) +{ + ENSIGHT_FIELD_DRIVER::_fieldName = fieldName; +} + +template string ENSIGHT_FIELD_WRONLY_DRIVER::getFieldName() const +{ + return ENSIGHT_FIELD_DRIVER::_fieldName; +} + +template GENDRIVER * ENSIGHT_FIELD_WRONLY_DRIVER::copy(void) const +{ + ENSIGHT_FIELD_WRONLY_DRIVER * myDriver = new ENSIGHT_FIELD_WRONLY_DRIVER(*this); + + return myDriver ; +} + +template void ENSIGHT_FIELD_WRONLY_DRIVER::read (void) + throw (MEDEXCEPTION) +{ + throw MEDEXCEPTION("ENSIGHT_FIELD_WRONLY_DRIVER::read : Can't read with a ENSIGHT driver because it is write only driver !"); +} + +template void ENSIGHT_FIELD_WRONLY_DRIVER::write(void) const + throw (MEDEXCEPTION) +{ + + const char * LOC = "ENSIGHT_FIELD_WRONLY_DRIVER::write(void) const " ; + BEGIN_OF(LOC); + + string mot_lu ; + int is_node = 0 ; + int is_element = 0 ; + int is_variable = 0 ; + +// FIELD_ * myField = ENSIGHT_FIELD_DRIVER::_ptrField ; +// MESH * meshField = supportField->getMesh(); + + const SUPPORT * supportField = ENSIGHT_FIELD_DRIVER::_ptrField->getSupport(); + + int dt = ENSIGHT_FIELD_DRIVER::_ptrField->getIterationNumber(); + int it = ENSIGHT_FIELD_DRIVER::_ptrField->getOrderNumber(); + + ostringstream name ; + string nameField = ENSIGHT_FIELD_DRIVER::_ptrField->getName(); + MED_EN::medEntityMesh entitySupport = supportField->getEntity(); + name << nameField << "_" << dt << "_" << it << ".sol" ; + + if ( ENSIGHT_FIELD_DRIVER::_ptrField->getGaussPresence() ) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<::_ptrField->getName()<<" which use Gauss Points !" << entitySupport)); + + if (!(supportField->isOnAllElements())) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<::_ptrField->getName()<<" which is not on all entities of the mesh !" << entitySupport)); + +// if (entitySupport == MED_EN::MED_NODE) int NumberOfNodes = ENSIGHT_FIELD_DRIVER::_ptrField->getNumberOfElements(MED_EN::MED_NODE,MED_EN::MED_ALL_ELEMENTS) ; +// else if (entitySupport == MED_EN::MED_CELL) int NumberOfElements = ENSIGHT_FIELD_DRIVER::_ptrField->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS) ; +// else +// throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<::_ptrField->getName()<<" which is not on all nodes or cells but it's on !" << entitySupport)); + + int NumberOfValue = ENSIGHT_FIELD_DRIVER::_ptrField->getSupport()->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS) ; + int NumberOfComponents = ENSIGHT_FIELD_DRIVER::_ptrField->getNumberOfComponents() ; + +// MED_EN::med_type_champ fieldType = ENSIGHT_FIELD_DRIVER::_ptrField->getValueType() ; + +// Case file part +//--------------- + + ifstream ensightCaseFile(ENSIGHT_FIELD_DRIVER::_fileName.c_str(),ios::in); + cout << "-> Creating the Ensight case file " << ENSIGHT_FIELD_DRIVER::_fileName << endl ; + + if (ensightCaseFile.is_open() ) // test si le mot clĂ© VARIABLE est dĂ©jĂ  dans le case file + { + while ( ensightCaseFile.eof() == 0 ) + { + ensightCaseFile >> mot_lu ; + if ( mot_lu == "VARIABLE" ) is_variable = 1 ; + } + } +// else +// cout << "-> Cannot access to the Ensight case file : " << ENSIGHT_FIELD_DRIVER::_fileName << endl ; + ensightCaseFile.close(); + + MED_EN::med_type_champ type = ENSIGHT_FIELD_DRIVER::_ptrField->getValueType() ; + SCRUTE(name); + SCRUTE(type); + + if ( ENSIGHT_FIELD_DRIVER::_ptrField->getSupport()->getEntity() == 0 ) is_element = 1 ; + else if ( ENSIGHT_FIELD_DRIVER::_ptrField->getSupport()->getEntity() == 3 ) is_node = 1 ; + + ofstream NensightCaseFile(ENSIGHT_FIELD_DRIVER::_fileName.c_str(),ios::out|ios::app); + NensightCaseFile << endl ; + if (!is_variable) NensightCaseFile << "VARIABLE" << endl ; // mot clĂ© VARIABLE non prĂ©sent dans le case file, on l'ajoute + + int len = ENSIGHT_FIELD_DRIVER::_fileName.size() ; + string prefix = ENSIGHT_FIELD_DRIVER::_fileName.substr(0,len-5); // extraction de .case + string dataname = prefix + ".sol" ; + + std::string aBaseName = getBaseName( (char*)dataname.c_str() ); + NensightCaseFile << "# --Field detected for " << aBaseName << endl ; + if ( NumberOfComponents > 1 ) { + if (is_node) NensightCaseFile << "vector per node: " << nameField << " " << aBaseName << endl ; + if (is_element) NensightCaseFile << "vector per element: " << nameField << " " << aBaseName << endl ; + } else { + if (is_node) NensightCaseFile << "scalar per node: " << nameField << " " << aBaseName << endl ; + if (is_element) NensightCaseFile << "scalar per element: " << nameField << " " << aBaseName << endl ; + } + NensightCaseFile.close(); + +// Field file part +//---------------- + + ofstream ensightDataFile(dataname.c_str(),ios::out) ; + cout << "-> Creating the Ensight data file " << dataname << endl ; + ensightDataFile.setf(ios::scientific); + ensightDataFile.precision(5); + + switch (type) + + { + case MED_EN::MED_INT32 : { + MESSAGE("MED_INT32"); + if (NumberOfComponents==3) { + if (is_node) ensightDataFile << "vector per node integer 32 mode for " << nameField << " following " << endl ; + if (is_element) ensightDataFile << "vector per element integer 32 mode for " << nameField << "following " << endl ; + } else if (NumberOfComponents<=4) { + if (is_node) ensightDataFile << "scalar per node integer 32 mode for " << nameField << " following " << endl ; + if (is_element) ensightDataFile << "scalar per element integer 32 mode for " << nameField << " following " << endl ; + } else { + MESSAGE(LOC << "Could not write field "<< nameField << " there are more than 4 components !"); + return ; + } + + const T * value; + if ( ENSIGHT_FIELD_DRIVER::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) { + value = ENSIGHT_FIELD_DRIVER::_ptrField->getValue(); + } + else if ( ENSIGHT_FIELD_DRIVER::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + MEDMEM_Array_ * ptrArray = ENSIGHT_FIELD_DRIVER::_ptrField->getArray(); + MEDMEM_Array * temp = dynamic_cast * > ( ptrArray ); + MEDMEM_Array * array = ArrayConvert2No( *temp ); + value = array->getPtr(); + } + else { + MEDMEM_Array_ * ptrArray = ENSIGHT_FIELD_DRIVER::_ptrField->getArray(); + MEDMEM_Array * temp = dynamic_cast * > ( ptrArray ); + MEDMEM_Array * array = ArrayConvert( *temp ); + value = array->getPtr(); + } + + int mypoint=0; + for (int i=0; i::_ptrField->getInterlacingType() != MED_EN::MED_NO_INTERLACE ) delete value; + break ; + } + + case MED_EN::MED_REEL64 : { + MESSAGE("MED_REEL64"); + if (NumberOfComponents==3) { + if (is_node) ensightDataFile << "vector per node real 64 mode for " << nameField << " following " << endl ; + if (is_element) ensightDataFile << "vector per element real 64 mode for " << nameField << " following " << endl ; + } else if (NumberOfComponents<=4) { + if (is_node) ensightDataFile << "scalar per node real 64 mode for " << nameField << " following " << endl ; + if (is_element) ensightDataFile << "scalar per element real 64 mode for " << nameField << " following " << endl ; + } else { + MESSAGE(LOC << "Could not write field "<::_ptrField->getName()<<" there are more than 4 components !"); + return ; + } + + const T * value; + if ( ENSIGHT_FIELD_DRIVER::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) + value = ENSIGHT_FIELD_DRIVER::_ptrField->getValue(); + else if ( ENSIGHT_FIELD_DRIVER::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + MEDMEM_Array_ * ptrArray = ENSIGHT_FIELD_DRIVER::_ptrField->getArray(); + MEDMEM_Array * temp = dynamic_cast * > ( ptrArray ); + MEDMEM_Array * array = ArrayConvert2No( *temp ); // ici ca pond un p'tain de core // + value = array->getPtr(); + } + else { + MEDMEM_Array_ * ptrArray = ENSIGHT_FIELD_DRIVER::_ptrField->getArray(); + MEDMEM_Array * temp = dynamic_cast * > ( ptrArray ); + MEDMEM_Array * array = ArrayConvert( *temp ); // ici ca pond un p'tain de core // + value = array->getPtr(); + } + + int mypoint=0; + for (int i=0; i::_ptrField->getInterlacingType() != MED_EN::MED_NO_INTERLACE ) delete value; + ensightDataFile << endl ; + break ; + } + default : { + MESSAGE(LOC << "Could not write field "< void ENSIGHT_FIELD_WRONLY_DRIVER::writeAppend(void) const + throw (MEDEXCEPTION) +{ + const char * LOC = "ENSIGHT_FIELD_DRIVER::writeAppend(void) const " ; + BEGIN_OF(LOC); + +// redondant avec write() + + END_OF(LOC); +} + +}//End namespace MEDMEM + +#endif /* ENSIGHT_FIELD_DRIVER_HXX */ diff --git a/src/MEDMEM/MEDMEM_EnsightMedDriver.cxx b/src/MEDMEM/MEDMEM_EnsightMedDriver.cxx new file mode 100644 index 000000000..c1fad8c8c --- /dev/null +++ b/src/MEDMEM/MEDMEM_EnsightMedDriver.cxx @@ -0,0 +1,1042 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "MEDMEM_EnsightMedDriver.hxx" + +#include +#include + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_CellModel.hxx" + +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_MedFieldDriver.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_Group.hxx" + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +ENSIGHT_MED_DRIVER::ENSIGHT_MED_DRIVER(): GENDRIVER(), + _ptrMed((MED * const)MED_NULL) +{} + +ENSIGHT_MED_DRIVER::ENSIGHT_MED_DRIVER(const string & fileName, MED * const ptrMed): + GENDRIVER(fileName,MED_EN::MED_RDWR), _ptrMed(ptrMed) +{ +} + +ENSIGHT_MED_DRIVER::ENSIGHT_MED_DRIVER(const string & fileName, + MED * const ptrMed, + MED_EN::med_mode_acces accessMode): + GENDRIVER(fileName,accessMode), _ptrMed(ptrMed) +{ +} + +ENSIGHT_MED_DRIVER::ENSIGHT_MED_DRIVER(const ENSIGHT_MED_DRIVER & driver): + GENDRIVER(driver), + _ptrMed(driver._ptrMed) +{ +} + +ENSIGHT_MED_DRIVER::~ENSIGHT_MED_DRIVER() +{ + MESSAGE("ENSIGHT_MED_DRIVER::~ENSIGHT_MED_DRIVER() has been destroyed"); +} + +void ENSIGHT_MED_DRIVER::open() { + openConst() ; +} + +void ENSIGHT_MED_DRIVER::close() { + closeConst() ; +} + +ENSIGHT_MED_WRONLY_DRIVER::ENSIGHT_MED_WRONLY_DRIVER() : ENSIGHT_MED_DRIVER() +{ + _ensightFile = new ofstream(); +} + +ENSIGHT_MED_WRONLY_DRIVER::ENSIGHT_MED_WRONLY_DRIVER(const string & fileName, MED * const ptrMed) : ENSIGHT_MED_DRIVER(fileName,ptrMed) +{ + _ensightFile = new ofstream(); +} + +ENSIGHT_MED_WRONLY_DRIVER::ENSIGHT_MED_WRONLY_DRIVER(const ENSIGHT_MED_WRONLY_DRIVER & driver) : ENSIGHT_MED_DRIVER(driver) +{ + _ensightFile = new ofstream(); +} + +ENSIGHT_MED_WRONLY_DRIVER::~ENSIGHT_MED_WRONLY_DRIVER() +{ + delete _ensightFile ; +} + +GENDRIVER * ENSIGHT_MED_WRONLY_DRIVER::copy() const +{ + return new ENSIGHT_MED_WRONLY_DRIVER(*this) ; +} + +void ENSIGHT_MED_WRONLY_DRIVER::openConst() const { + + const char * LOC ="ENSIGHT_MED_WRONLY_DRIVER::open() : "; + + BEGIN_OF(LOC); + + if ( _fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + if (!(*_ensightFile).is_open()) + (*_ensightFile).open(_fileName.c_str()) ; + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open main Ensight file " + << _fileName) + ); + END_OF(LOC); +} + +void ENSIGHT_MED_WRONLY_DRIVER::closeConst() const { + + const char * LOC = "ENSIGHT_MED_WRONLY_DRIVER::close() : "; + BEGIN_OF(LOC); + + (*_ensightFile).close(); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close main Ensight file " + << _fileName) + ); + END_OF(LOC); +} + +void ENSIGHT_MED_WRONLY_DRIVER::read() throw (MEDEXCEPTION) { + throw MEDEXCEPTION("ENSIGHT_MED_WRONLY_DRIVER::read : Can't read with a WRONLY driver !"); +} + +void ENSIGHT_MED_WRONLY_DRIVER::write() const throw (MEDEXCEPTION) { + + const char * LOC = "ENSIGHT_MED_WRONLY_DRIVER::write() : "; + BEGIN_OF(LOC); + + // Well we must open ensight file first, because there are + // no other driver than MED for ENSIGHT that do it ! + openConst() ; + + // Ensight case organization requires a main file (filename.case) which defines organization + // We also need a geom file (filemane.geo) to store the meshs + // We also need a data file (filemane.data) to store the fields + + int NumberOfMeshes = _ptrMed->getNumberOfMeshes() ; + deque MeshNames = _ptrMed->getMeshNames() ; + // In fact, we must take care of all supports + // We restrict Field on all nodes or cells + + int NumberOfFields = _ptrMed->getNumberOfFields() ; + deque FieldNames = _ptrMed->getFieldNames() ; + + cout << "-> creating the Ensight case file " << _fileName << endl ; + (*_ensightFile) << "FORMAT" << endl ; + (*_ensightFile) << "type: ensight" << endl ; + (*_ensightFile) << endl ; + if (NumberOfMeshes){ + (*_ensightFile) << "GEOMETRY" << endl ; + for (int i=0; igetMesh(MeshNames[i]) ; + writeMesh(myMesh, i) ; + // get all field which values are on this mesh => revoir api de Med !!! + // first : field on node + // fields is on all node ! + for (int j=0; j timeStep = _ptrMed->getFieldIteration(FieldNames[j]) ; + deque::const_iterator currentTimeStep ; + for ( currentTimeStep=timeStep.begin(); currentTimeStep!=timeStep.end(); currentTimeStep++) { + int dt = (*currentTimeStep).dt ; + int it = (*currentTimeStep).it ; + FIELD_ * myField = _ptrMed->getField(FieldNames[j],dt,it) ; + ostringstream name ; + name << myField->getName() << "_" << dt << "_" << it ; + (*_ensightFile) << "# -Field "<< j+1 << " detected with name = " << name.str() << endl ; + if( MeshNames[i] == myField->getSupport()->getMesh()->getName() ) { + // rigth in all case : better compare pointeur ? + if (MED_NODE == myField->getSupport()->getEntity()) + if (myField->getSupport()->isOnAllElements()) { + int NumberOfComponents = myField->getNumberOfComponents() ; + ostringstream name ; + name << myField->getName() << "_" << dt << "_" << it ; + if (NumberOfComponents==3) (*_ensightFile) << "vector per node: " << name.str() << " " << name.str() << ".sol" << endl ; + else if (NumberOfComponents<=4) (*_ensightFile) << "scalar per node: " << name.str() << " " << name.str() << ".sol" << endl ; + writeField(myField,name.str()) ; + } else + MESSAGE(LOC << "Could not write field "<getName()<<" which is not on all nodes !"); + } + } + } + + for (int j=0; j timeStep = _ptrMed->getFieldIteration(FieldNames[j]) ; + deque::const_iterator currentTimeStep ; + for ( currentTimeStep=timeStep.begin(); currentTimeStep!=timeStep.end(); currentTimeStep++) { + int dt = (*currentTimeStep).dt; + int it = (*currentTimeStep).it; + FIELD_ * myField = _ptrMed->getField(FieldNames[j],dt,it) ; + ostringstream name ; + name << myField->getName() << "_" << dt << "_" << it ; + (*_ensightFile) << "# --Field "<< j+1 << " detected for " << name.str() << endl ; + if( MeshNames[i] == myField->getSupport()->getMesh()->getName() ) { + // rigth in all case : better compare pointeur ? + if (MED_CELL == myField->getSupport()->getEntity()) + if (myField->getSupport()->isOnAllElements()) { + int NumberOfComponents = myField->getNumberOfComponents() ; + ostringstream name ; + name << myField->getName() << "_" << dt << "_" << it ; + if (NumberOfComponents==3) (*_ensightFile) << "vector per element: " << name.str() << " " << name.str() << ".sol" << endl ; + else if (NumberOfComponents<=4) (*_ensightFile) << "scalar per element: " << name.str() << " " << name.str() << ".sol" << endl ; + writeField(myField,name.str()) ; + } else + MESSAGE(LOC << "Could not write field "<getName()<<" which is not on all cells !"); + } + } + } + + } + + // Well we must close ensight file first, because there are + // no other driver than MED for ENSIGHT that do it ! + // closeConst() ; + + END_OF(LOC); +} + +void ENSIGHT_MED_WRONLY_DRIVER::writeMesh(MESH * myMesh , int imesh) const { + + const char * LOC = "ENSIGHT_MED_DRIVER::writeMesh() : "; + BEGIN_OF(LOC); + + int len = _fileName.size() ; + string prefix = _fileName.substr(0,len-5); // extraction de .case + strstream w_mesh ; + w_mesh << prefix << "-" << imesh+1 << ".geom" << ends ; + string ensight_geomf = w_mesh.str() ; + + ofstream ensightGeomFile(ensight_geomf.c_str(),ios::out); + cout << "-> creating the Ensight geometry file " << ensight_geomf << endl ; + + // ------------ create the Ensight file associated to this meshe + ensightGeomFile << "Ensight Geometry File : " << endl + << "Meshing from MedMemory" << endl ; +// ensightGeomFile << "node id given " << endl ; +// ensightGeomFile << "element id given " << endl ; + ensightGeomFile << "node id assign " << endl ; + ensightGeomFile << "element id assign " << endl ; + ensightGeomFile << "coordinates" << endl ; + // put points (all point are in 3D, so if we are in 1D or 2D, we complete by zero ! + int SpaceDimension = myMesh->getSpaceDimension() ; + int NumberOfNodes = myMesh->getNumberOfNodes() ; + ensightGeomFile << NumberOfNodes << endl ; + const double *coordinate = myMesh->getCoordinates(MED_FULL_INTERLACE) ; + ensightGeomFile.setf(ios::scientific); + ensightGeomFile.precision(5); + for (int i=0;igetNumberOfTypes(MED_CELL) ; +// int cells_sum = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) ; + const CELLMODEL * cells_type = myMesh->getCellsTypes(MED_CELL) ; + ensightGeomFile << "part 1 " << endl ; + ensightGeomFile << "elements are following " << endl ; + + // we put connectivity + for (int i=0;igetNumberOfElements(MED_CELL,cells_type[i].getType()) ; + int *filter = (int*) NULL ; + switch (cells_type[i].getType()) + { + case MED_POINT1 : { + ensightGeomFile << "point" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[1] ; + filter[0] = 0 ; + break ; + } + case MED_SEG2 : { + ensightGeomFile << "bar2" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[2] ; + filter[0] = 0 ; + filter[1] = 1 ; + break ; + } + case MED_SEG3 : { + filter = new int[3] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + break ; + } + case MED_TRIA3 : { + ensightGeomFile << "tria3" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[3] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + break ; + } + case MED_QUAD4 : { + ensightGeomFile << "quad4" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[4] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + break ; + } + case MED_TRIA6 : { + ensightGeomFile << "tria6" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[6] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 5 ; + filter[4] = 4 ; + filter[5] = 3 ; + break ; + } + case MED_QUAD8 : { + ensightGeomFile << "quad8" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[8] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + filter[4] = 7 ; + filter[5] = 6 ; + filter[6] = 5 ; + filter[7] = 4 ; + break ; + } + case MED_TETRA4 : { + ensightGeomFile << "tetra4" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[4] ; + filter[0] = 0 ; + filter[1] = 1 ; + filter[2] = 3 ; // 3td element in med are 4th in vtk (array begin at 0 !) + filter[3] = 2 ; // 4th element in med are 3rd in vtk (array begin at 0 !) + break ; + } + case MED_PYRA5 : { + ensightGeomFile << "pyramid5" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[5] ; + filter[0] = 0 ; + filter[1] = 3 ; // 2nd element in med are 4th in vtk (array begin at 0 !) + filter[2] = 2 ; + filter[3] = 1 ; // 4th element in med are 2nd in vtk (array begin at 0 !) + filter[4] = 4 ; + break ; + } + case MED_PENTA6 : { + ensightGeomFile << "penta6" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[6] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 3 ; + filter[4] = 4 ; + filter[5] = 5 ; + break ; + } + case MED_HEXA8 : { + ensightGeomFile << "hexa8" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[8] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + filter[4] = 4 ; + filter[5] = 7 ; + filter[6] = 6 ; + filter[7] = 5 ; + break ; + } + case MED_TETRA10 : { + ensightGeomFile << "tetra10" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[10] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 3 ; + filter[4] = 6 ; + filter[5] = 5 ; + filter[6] = 4 ; + filter[7] = 7 ; + filter[8] = 9 ; + filter[9] = 8 ; + break ; + } + case MED_PYRA13 : { + ensightGeomFile << "pyramid13" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + case MED_PENTA15 : { + ensightGeomFile << "penta15" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + case MED_HEXA20 : { + ensightGeomFile << "hexa20" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + default : { + break ; + } + } + if (filter==NULL) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": MED element type not supported yet : " << cells_type[i].getName() ) ) ; + int nodes_cell = cells_type[i].getNumberOfNodes(); + const int * connectivityArray = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,cells_type[i].getType()); + for (int j=0;j::Array ArrayIntNo; + typedef MEDMEM_ArrayInterface::Array ArrayDoubleNo; + + int NumberOfValue = myField->getSupport()->getNumberOfElements(MED_ALL_ELEMENTS) ; + int NumberOfComponents = myField->getNumberOfComponents() ; + + int is_node = 0 ; + int is_element = 0 ; + + string dataname = name += ".sol" ; + ofstream ensightDataFile(name.c_str(),ios::out) ; + cout << "-> creating the Ensight data file " << name << endl ; + ensightDataFile.setf(ios::scientific); + ensightDataFile.precision(5); + + med_type_champ type = myField->getValueType() ; + SCRUTE(name); + SCRUTE(type); + + if ( myField->getSupport()->getEntity() == 0 ) is_element = 1 ; + else if ( myField->getSupport()->getEntity() == 3 ) is_node = 1 ; + + switch (type) + + { + case MED_INT32 : { + MESSAGE("MED_INT32"); + if (NumberOfComponents==3) { + if (is_node) ensightDataFile << "vector per node integer 32 mode for " << name << " following " << endl ; + if (is_element) ensightDataFile << "vector per element integer 32 mode for " << name << " following " << endl ; + } else if (NumberOfComponents<=4) { + if (is_node) ensightDataFile << "scalar per node integer 32 mode for " << name << " following " << endl ; + if (is_element) ensightDataFile << "scalar per element integer 32 mode for " << name << " following " << endl ; + } else { + MESSAGE(LOC << "Could not write field "<getName()<<" there are more than 4 components !"); + return ; + } + + const int * value; + ArrayIntNo * myArray = 0; + if ( myField->getInterlacingType() == MED_FULL_INTERLACE ) { + myArray = ArrayConvert( *( dynamic_cast< FIELD* > + (myField)->getArrayNoGauss() + ) + ); + value = myArray->getPtr(); + } else if ( myField->getInterlacingType() == MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< FIELD* > + (myField)->getArrayNoGauss() + ) + ); + value = myArray->getPtr(); + } else { + value = ((FIELD*)myField)->getValue() ; + } + + for (int i=0; igetInterlacingType() != MED_NO_INTERLACE ) + delete myArray; + break ; + } + case MED_REEL64 : { + MESSAGE("MED_REEL64"); + if (NumberOfComponents==3) { + if (is_node) ensightDataFile << "vector per node real 64 mode for " << name << " following " << endl ; + if (is_element) ensightDataFile << "vector per element real 64 mode for " << name << " following " << endl ; + } else if (NumberOfComponents<=4) { + if (is_node) ensightDataFile << "scalar per node real 64 mode for " << name << " following " << endl ; + if (is_element) ensightDataFile << "scalar per element real 64 mode for " << name << " following " << endl ; + } else { + MESSAGE(LOC << "Could not write field "<getName()<<" there are more than 4 components !"); + return ; + } + + const double * value; + ArrayDoubleNo * myArray = 0; + if ( myField->getInterlacingType() == MED_FULL_INTERLACE ) { + myArray = ArrayConvert( *( dynamic_cast< FIELD* > + (myField)->getArrayNoGauss() + ) + ); + value = myArray->getPtr(); + } else if ( myField->getInterlacingType() == MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< FIELD* > + (myField)->getArrayNoGauss() + ) + ); + value = myArray->getPtr(); + } else { + value = ((FIELD*)myField)->getValue() ; + } + + int mypoint=0; + //cout << "-> number of values " << NumberOfValue << " number of components " << NumberOfComponents << endl ; + for (int i=0; igetInterlacingType() != MED_NO_INTERLACE ) + delete myArray; + + break ; + } + default : { + MESSAGE(LOC << "Could not write field "< type_read ; + vector nbcell_read ; + vector< vector > total_conn ; + vector var ; + + char ligne[80]; + //int number_of_geom ; + string geom_namefile ; +// vector field_namefile ; + string field_namefile ; + string mot_lu ; + int geom_given = 0 ; + int num_coordinate ; + string type_cell ; + int number_of_cell ; + int conn ; + //----- ? + int SpaceDimension = 3 ; + //----- ? + int NumberOfTypes = 0 ; + int NumberOfNodes ; + int iType ; + + int is_scalar=0 ; + int is_vector=0; + int is_node=0; + int is_element=0; + int my_field=0 ; + int is_doublon=0 ; + int type_doublon=0 ; +// strstream w_field ; + + MESHING* MyMeshing = new MESHING(); + + MyMeshing->setName( "MeshFromEnsight" ); + + // recuperation des arguments du fichier ensight case + // -------------------------------------------------- + + // In this release, the following options are available : + // For GEOMETRY -> model: + // For VARIABLE -> scalar per node: + // -> vector per node: + // -> scalar per element: + // -> vector per element: + + cout << "****************** READ **************** starting " << endl ; + + ifstream ensightCaseFile(_fileName.c_str(),ios::in); + cout << "Ensight case file name to read " << _fileName << endl ; + string diren = getDirName((char*)_fileName.c_str()); + + if (ensightCaseFile.is_open() ) + { + while ( ensightCaseFile >> mot_lu ) + { + if ( mot_lu == "GEOMETRY" ) { + cout << "geometry detected" << endl ; + while ( ensightCaseFile >> mot_lu ){ + if ( mot_lu == "model:" ) { +// ensightCaseFile >> number_of_geom ; +// cout << "number of geometries " << number_of_geom << endl ; + ensightCaseFile >> mot_lu ; + geom_namefile = mot_lu; + cout << "name of geometrie : " << geom_namefile << endl ; + break ; + } + } + } + else if ( mot_lu == "VARIABLE" ) { + cout << "field detected" << endl ; + while ( ensightCaseFile >> mot_lu ){ + if ( mot_lu == "scalar" || mot_lu == "vector" ) { + if ( mot_lu == "scalar" ) is_scalar = 1 ; + if ( mot_lu == "vector" ) is_vector = 1 ; + ensightCaseFile >> mot_lu ; //per + ensightCaseFile >> mot_lu ; //node + if ( mot_lu == "node:" ) is_node = 1 ; + if ( mot_lu == "element:" ) is_element = 1 ; + else { + ensightCaseFile >> mot_lu ; //description + ensightCaseFile >> mot_lu ; + field_namefile = mot_lu ; + my_field +=1 ; + cout << "name of field : " << my_field << " = " << field_namefile << endl ; + break ; // couple la boucle sur les champs + } + } + } + // cout << " scalar " << is_scalar << " vector " << is_vector << " node " << is_node << " element " << is_element << endl ; + if ( !(is_scalar+is_vector) ) { + cout << " the field ist not a scalar and is not a vector " << endl ; + break ; + } + else if ( !(is_node+is_element) ) { + cout << " the field ist not on nodes and is not on elements " << endl ; + break ; + } + } + } + } + else + { + cout << "Error : requested file " << ensightCaseFile << " not found " << endl; + exit( EXIT_FAILURE ); + } + + // chargement des noeuds et connectivites necessaires depuis le fichier ensight geom + // --------------------------------------------------------------------------------- + + string cgeom_namefile; + if( diren.length() > 0 ) + cgeom_namefile = diren + '/' + geom_namefile; + else + cgeom_namefile = geom_namefile; + cout << "-> Entering into the geometry file " << cgeom_namefile << endl; + + ifstream ensightGeomFile(cgeom_namefile.c_str(),ios::in); + if (ensightGeomFile.is_open() ) + { + while ( ensightGeomFile >> mot_lu ){ + if ( mot_lu == "given" ) geom_given=1 ; + if ( mot_lu == "coordinates" ) { +//---------------- Nodes part -------------------------------------------------- + ensightGeomFile >> NumberOfNodes ; + cout << "-> loading " << NumberOfNodes << " coordinates " << endl ; + int NumberOfCoordinates = NumberOfNodes*SpaceDimension ; + double* Coordinates = new double[NumberOfCoordinates]; + int iCoord = 0 ; + cout << "-> geom given " << geom_given << endl ; + for ( int i=0 ; i < NumberOfNodes ; i++) { + if( geom_given) ensightGeomFile >> setw(8) >> num_coordinate ; + ensightGeomFile >> setw(12) >> Coordinates[iCoord] ; + ensightGeomFile >> setw(12) >> Coordinates[iCoord+1] ; + ensightGeomFile >> setw(12) >> Coordinates[iCoord+2] ; +// cout << "coordinate " << i+1 << " read : x = " << Coordinates[iCoord] << " y = " << Coordinates[iCoord+1] << " z = " << Coordinates[iCoord+2] << endl ; +// cout << "coordinate read " << num_coordinate << " : x = " << Coordinates[iCoord] << " y = " << Coordinates[iCoord+1] << " z = " << Coordinates[iCoord+2] << endl ; + iCoord+=3 ; + } + + MyMeshing->setSpaceDimension(SpaceDimension); + MyMeshing->setNumberOfNodes(NumberOfNodes); + MyMeshing->setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_EN::MED_FULL_INTERLACE); + string coordname[3] = { "x", "y", "z" } ; + MyMeshing->setCoordinatesNames(coordname) ; + delete [] Coordinates; + } + else if ( mot_lu == "part" ) { +//---------------- Connectivities part -------------------------------------------- + + while ( ensightGeomFile >> mot_lu ){ + for ( int j = 0 ; j < 15 ; j++){ + if( mot_lu == type_Ensight[j] ) { + is_doublon=0 ; + for ( int ltype = 0 ; ltype < NumberOfTypes ; ltype++ ){ + if ( mot_lu == type_read[ltype] ) { + is_doublon=1 ; + type_doublon=ltype ; + } + } + if ( is_doublon ) { + // type_read already stored + ensightGeomFile >> number_of_cell ; + int last_number_of_cell = nbcell_read[type_doublon] ; + int total_number_of_cell = number_of_cell + last_number_of_cell ; + nbcell_read[type_doublon] = total_number_of_cell ; + total_conn[type_doublon].resize(nb_edge[j]*total_number_of_cell); + cout << "-> loading again by adding " << number_of_cell << " to " << last_number_of_cell << " cells connectivities of type " << type_Ensight[j] << " existing" << endl << "-> new results for " << type_Ensight[j] << " are : number of cells connectivities = " << total_number_of_cell << " and total number of values = " << nb_edge[j]*total_number_of_cell << endl ; + for ( int k=0 ; k < nb_edge[j]*number_of_cell ; k++ ) { + ensightGeomFile >> setw(8) >> conn ; + int last_dim = last_number_of_cell*nb_edge[j] ; + total_conn[type_doublon][last_dim+k]=conn ; +// cout << " connectivitie " << last_number_of_cell+k+1 << " read = " << total_conn[type_doublon][last_dim+k] << endl ; + } + } + else { + NumberOfTypes+=1; + iType=NumberOfTypes-1 ; + total_conn.resize(NumberOfTypes) ; + type_read.push_back(mot_lu) ; + ensightGeomFile >> number_of_cell ; + nbcell_read.push_back(number_of_cell) ; + total_conn[iType].resize(nb_edge[j]*number_of_cell); + cout << "-> loading " << number_of_cell << " cell connectivities of type " << type_Ensight[j] << " (total number of values = " << nb_edge[j]*number_of_cell << ") " << endl ; + for ( int k=0 ; k < nb_edge[j]*number_of_cell ; k++ ) { + ensightGeomFile >> setw(8) >> conn ; + total_conn[iType][k]=conn ; +// cout << " connectivitie " << k+1 << " read = " << total_conn[iType][k] << endl ; + } + } + } + } + } + + + + } + } + } + // for compilation on WNT +#ifndef WNT + medGeometryElement classicalTypesCell[NumberOfTypes]; + int nbOfClassicalTypesCell[NumberOfTypes]; +#else // massive with zero size can't exist on Win32 + medGeometryElement* classicalTypesCell = new medGeometryElement(NumberOfTypes); + int* nbOfClassicalTypesCell = new int(NumberOfTypes); +#endif + + int ind=0 ; + for (int k=0 ; ksetNumberOfTypes(NumberOfTypes, MED_EN::MED_CELL) ; + MyMeshing->setTypes(classicalTypesCell, MED_EN::MED_CELL) ; + MyMeshing->setNumberOfElements(nbOfClassicalTypesCell, MED_EN::MED_CELL); + int MeshDimension ; + MeshDimension = 2 ; + for (int k=0 ; k6 ) MeshDimension = 3 ; + } + MyMeshing->setMeshDimension(MeshDimension); + + for (int k = 0 ; k < NumberOfTypes ; k++) { + int nb_connectivities = total_conn[k].size(); + cout << "-> type = " << k+1 << " has for total number of values of connectivities : " << nb_connectivities << endl ; + int *connectivities = new int[nb_connectivities]; + for (int itab=0 ; itab < nb_connectivities ; itab++) connectivities[itab]=total_conn[k][itab] ; + for (int j=0 ; j<15 ; j++) { + if( type_read[k] == type_Ensight[j] ) { + cout << "-> type read = " << type_read[k] << endl ; + switch ( j+1 ) + { + case 1 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_POINT1) ; break ;} + case 2 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_SEG2) ; break ;} + case 3 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_SEG3) ; break ;} + case 4 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_TRIA3) ; break ;} + case 5 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_TRIA6) ; break ;} + case 6 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_QUAD4) ; break ;} + case 7 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_QUAD8) ; break ;} + case 8 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_TETRA4) ; break ;} + case 9 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_TETRA10) ; break ;} + case 10 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_PYRA5) ; break ;} + case 11 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_PYRA13) ; break ;} + case 12 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_HEXA8) ; break ;} + case 13 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_HEXA20) ; break ;} + case 14 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_PENTA6) ; break ;} + case 15 : {MyMeshing->setConnectivity(connectivities,MED_EN::MED_CELL,MED_EN::MED_PENTA15) ; break ;} + default : break ; + } + } + } + delete [] connectivities; + } + cout << "-> connectivities OK " << endl ; + +// cout << "-> Writing the mesh into med file" << endl ; +// int id = MyMeshing->addDriver(MED_DRIVER,med_filename,MyMeshing->getName()); +// MyMeshing->write(id) ; + cout << "-> Writing the mesh into the med object" << endl ; + _ptrMed->addMesh(MyMeshing); + + // chargement des variables depuis le fichier ensight data + // ------------------------------------------------------- + // ! faire le distinguo champs aux noeuds et aux mailles OK + // ! faire le cas des champs multiples + +// for (int ifield=0 ; ifield < my_field ; ifield++) { + string cfield_namefile; + if( diren.length() > 0 ) + cfield_namefile = diren + '/' + field_namefile; + else + cfield_namefile = field_namefile; + cout << "-> Entering into the field file " << cfield_namefile << endl ; + + ifstream ensightFieldFile(cfield_namefile.c_str(),ios::in); + if (ensightFieldFile.is_open() ) + { + ensightFieldFile.getline(ligne, 80, '\n') ; // read the first line of comment + + medEntityMesh Entity ; + if ( is_node ) { + cout << "-> loading " << NumberOfNodes << " variables on nodes " << endl ; + var.resize(NumberOfNodes); + for (int k = 0 ; k < NumberOfNodes ; k++) ensightFieldFile >> setw(12) >> var[k] ; + Entity = MED_EN::MED_NODE ; + } + else if ( is_element ) { + int NumberOfElements = 0 ; + for ( int i = 0 ; i < NumberOfTypes ; i++ ) { + NumberOfElements = NumberOfElements + nbcell_read[i] ; + } + cout << "-> loading " << NumberOfElements << " variables on elements " << endl ; + var.resize(NumberOfElements); + for (int k = 0 ; k < NumberOfElements ; k++) ensightFieldFile >> setw(12) >> var[k] ; + Entity = MED_EN::MED_CELL ; + } + + SUPPORT * MySupport = new SUPPORT(MyMeshing,"Support",Entity); + + int NumberOfComponents = 1 ; + if ( is_vector ) NumberOfComponents = 3 ; + FIELD *MyField = new FIELD(MySupport,NumberOfComponents); + +// w_field << "FieldFromEnsight" << ifield << ends ; +// const string FieldName = "FieldFromEnsight" ; +// const string FieldName = w_field.str() ; + + const string FieldName = "FieldFromEnsight" ; + MyField->setName(FieldName) ; + string * ComponentsNames = new string[NumberOfComponents] ; + if ( NumberOfComponents == 1 ) ComponentsNames[0] = "scalar comp" ; + else if ( NumberOfComponents == 3 ) { + ComponentsNames[0] = "X comp" ; + ComponentsNames[1] = "Y comp" ; + ComponentsNames[2] = "Z comp" ; + } + + MyField->setComponentsNames(ComponentsNames) ; + const int NumberOfValues = MySupport->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS) ; + MyField->setNumberOfValues(NumberOfValues) ; + + int NumberOf = NumberOfValues / NumberOfComponents; + for ( int i = 1 ; i <= NumberOf ; i++) { + for ( int j = 1 ; j <= NumberOfComponents ; j++) { + MyField->setValueIJ(i,j,var[NumberOfComponents*(i-1)+j-1]) ; + } + } + cout << "-> Writing the field into the med object" << endl ; + _ptrMed->addField(MyField); + +// cout << "-> Writing the field into the med file" << endl ; +// int id = MyField.addDriver(MED_DRIVER,med_filename,MyField.getName()); +// MyField.write(id) ; + } +// } + + + cout << "****************** READ **************** ending " << endl ; + +} diff --git a/src/MEDMEM/MEDMEM_EnsightMedDriver.hxx b/src/MEDMEM/MEDMEM_EnsightMedDriver.hxx new file mode 100644 index 000000000..93808b3f6 --- /dev/null +++ b/src/MEDMEM/MEDMEM_EnsightMedDriver.hxx @@ -0,0 +1,109 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef ENSIGHT_MED_DRIVER_HXX +#define ENSIGHT_MED_DRIVER_HXX + +#include +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Utilities.hxx" +#include "MEDMEM_Exception.hxx" + +#include "MEDMEM_GenDriver.hxx" + +#include + +using namespace std ; + + +namespace MEDMEM { +class MESH; +class SUPPORT; +class FIELD_; +class MED; +// This driver pilots within a ENSIGHT class read/write accesses of fields/meshes +class ENSIGHT_MED_DRIVER : public GENDRIVER +{ +protected: + + MED * const _ptrMed ; // Store 'ENSIGHT_DRIVER (0..n)----(1) ENSIGHT' associations + + virtual void openConst() const =0; + virtual void closeConst() const =0; + +public : + ENSIGHT_MED_DRIVER(); + ENSIGHT_MED_DRIVER(const string & fileName, MED * const ptrMed); + ENSIGHT_MED_DRIVER(const string & fileName, MED * const ptrMed, + MED_EN::med_mode_acces accessMode); + ENSIGHT_MED_DRIVER(const ENSIGHT_MED_DRIVER & driver); + virtual ~ENSIGHT_MED_DRIVER(); + // OPERATEUR DE RECOPIE AVEC _ensightFile ?? + + void open(); + void close(); + virtual void write( void ) const = 0 ; + virtual void read( void ) = 0 ; + virtual GENDRIVER * copy (void ) const = 0; + +}; + +class ENSIGHT_MED_RDONLY_DRIVER : public virtual ENSIGHT_MED_DRIVER +{ +public : + ENSIGHT_MED_RDONLY_DRIVER(); + ENSIGHT_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed); + ENSIGHT_MED_RDONLY_DRIVER(const ENSIGHT_MED_RDONLY_DRIVER & driver); + virtual ~ENSIGHT_MED_RDONLY_DRIVER(); + void openConst() const; + void closeConst() const; + void write ( void ) const throw (MEDEXCEPTION) ; + virtual void read ( void ) ; +// virtual void readFileStruct ( void ) ; +private: + ifstream * _ensightFile; // The main _ensightFile used to read geom and data _filename + GENDRIVER * copy ( void ) const; +}; + +class ENSIGHT_MED_WRONLY_DRIVER : public virtual ENSIGHT_MED_DRIVER +{ + +public : + ENSIGHT_MED_WRONLY_DRIVER(); + ENSIGHT_MED_WRONLY_DRIVER(const string & fileName, MED * const ptrMed); + ENSIGHT_MED_WRONLY_DRIVER(const ENSIGHT_MED_WRONLY_DRIVER & driver); + virtual ~ENSIGHT_MED_WRONLY_DRIVER(); + void openConst() const; + void closeConst() const; + void write ( void ) const throw (MEDEXCEPTION) ; +// void writeFrom ( void ) const throw (MEDEXCEPTION) ; + virtual void read ( void ) throw (MEDEXCEPTION) ; +// virtual void readFileStruct ( void ) throw (MEDEXCEPTION) ; +private: + ofstream * _ensightFile; // The main _ensightFile used to write geom and data _filename + GENDRIVER * copy ( void ) const; + void writeMesh(MESH * myMesh,int imesh) const ; + void writeSupport(SUPPORT * mySupport) const ; + void writeField(FIELD_ * myField,string name) const ; +}; + +}; + + +#endif /* ENSIGTH_MED_DRIVER_HXX */ diff --git a/src/MEDMEM/MEDMEM_EnsightMeshDriver.cxx b/src/MEDMEM/MEDMEM_EnsightMeshDriver.cxx new file mode 100644 index 000000000..8939639d7 --- /dev/null +++ b/src/MEDMEM/MEDMEM_EnsightMeshDriver.cxx @@ -0,0 +1,893 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "MEDMEM_EnsightMeshDriver.hxx" + +#include +#include +#include + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_Coordinate.hxx" +#include "MEDMEM_Connectivity.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_Grid.hxx" + +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_MedMeshDriver.hxx" + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +#define MED_NULL NULL + +ENSIGHT_MESH_DRIVER::ENSIGHT_MESH_DRIVER(): GENDRIVER(), + _ptrMesh((MESH *)MED_NULL) +{ +} + +ENSIGHT_MESH_DRIVER::ENSIGHT_MESH_DRIVER(const string & fileName, + MESH * ptrMesh) : + GENDRIVER(fileName,MED_EN::MED_RDWR), _ptrMesh(ptrMesh) +{ +} + +ENSIGHT_MESH_DRIVER::ENSIGHT_MESH_DRIVER(const string & fileName, + MESH * ptrMesh, + MED_EN::med_mode_acces accessMode): + GENDRIVER(fileName,accessMode), _ptrMesh(ptrMesh) +{ +} + +ENSIGHT_MESH_DRIVER::ENSIGHT_MESH_DRIVER(const ENSIGHT_MESH_DRIVER & driver): + GENDRIVER(driver), + _ptrMesh(driver._ptrMesh), + _meshName(driver._meshName) +{ +} + +ENSIGHT_MESH_DRIVER::~ENSIGHT_MESH_DRIVER() +{ + MESSAGE("ENSIGHT_MESH_DRIVER::~ENSIGHT_MESH_DRIVER() has been destroyed"); +} + +void ENSIGHT_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; }; + +string ENSIGHT_MESH_DRIVER::getMeshName() const { return _meshName; }; + +void ENSIGHT_MESH_DRIVER::open() { + openConst() ; +} + +void ENSIGHT_MESH_DRIVER::close() { + closeConst() ; +} + +ENSIGHT_MESH_WRONLY_DRIVER::ENSIGHT_MESH_WRONLY_DRIVER() : ENSIGHT_MESH_DRIVER() +{ + _ensightFile = new ofstream(); +} + +ENSIGHT_MESH_WRONLY_DRIVER::ENSIGHT_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) : ENSIGHT_MESH_DRIVER(fileName,ptrMesh) +{ + _ensightFile = new ofstream(); +} + +ENSIGHT_MESH_WRONLY_DRIVER::ENSIGHT_MESH_WRONLY_DRIVER(const ENSIGHT_MESH_WRONLY_DRIVER & driver) : ENSIGHT_MESH_DRIVER(driver),_support(driver._support) +{ + _ensightFile = new ofstream(); +} + +ENSIGHT_MESH_WRONLY_DRIVER::~ENSIGHT_MESH_WRONLY_DRIVER() +{ + delete _ensightFile ; +} + +GENDRIVER * ENSIGHT_MESH_WRONLY_DRIVER::copy() const +{ + return new ENSIGHT_MESH_WRONLY_DRIVER(*this) ; +} + +void ENSIGHT_MESH_WRONLY_DRIVER::openConst() const +{ + const char * LOC = "ENSIGHT_MESH_WRONLY_DRIVER::open()" ; + + BEGIN_OF(LOC); + + if ( _fileName == "" ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "_fileName is |\"\"|, please set a correct fileName before calling open()" + ) + ); + + if (!(*_ensightFile).is_open()) + (*_ensightFile).open(_fileName.c_str()) ; + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open main Ensight file " + << _fileName) + ); + + END_OF(LOC); +} + +void ENSIGHT_MESH_WRONLY_DRIVER::closeConst() const { + + const char * LOC = "ENSIGHT_MESH_WRONLY_DRIVER::close() : "; + BEGIN_OF(LOC); + + (*_ensightFile).close(); + + if (!(*_ensightFile)) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close main Ensight file " + << _fileName) + ); + END_OF(LOC); +} + +void ENSIGHT_MESH_WRONLY_DRIVER::read() throw (MEDEXCEPTION) { + throw MEDEXCEPTION("ENSIGHT_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !"); +} + +void ENSIGHT_MESH_WRONLY_DRIVER::write() const throw (MEDEXCEPTION) +{ + + const char * LOC = "ENSIGHT_MESH_WRONLY_DRIVER::write() : "; + BEGIN_OF(LOC); + + // Well we must open ensight file first, because there are + // no other driver than MESH for ENSIGHT that do it ! + openConst() ; + + // Ensight case organization requires a main file (filename.case) which defines organization + // We also need a geom file (filemane.geo) to store the meshs + // We also need a data file (filemane.data) to store the fields + + string MeshName = _ptrMesh->getName() ; + // In fact, we must take care of all supports + // We restrict Field on all nodes or cells + + cout << "-> creating the Ensight case file " << _fileName << endl ; + (*_ensightFile) << "FORMAT" << endl ; + (*_ensightFile) << "type: ensight" << endl ; + (*_ensightFile) << endl ; + (*_ensightFile) << "GEOMETRY" << endl ; + int len = _fileName.size() ; + string prefix = _fileName.substr(0,len-5); // extraction de .case + string ensight_geomf = prefix + ".geom" ; + string basen = getBaseName((char*)ensight_geomf.c_str()); + (*_ensightFile) << "# Mesh detected with name = " << MeshName << endl ; + (*_ensightFile) << "model: " << basen << endl ; + (*_ensightFile) << endl ; + + ofstream ensightGeomFile(ensight_geomf.c_str(),ios::out); + cout << "-> creating the Ensight geometry file " << ensight_geomf << endl ; + + // ------------ create the Ensight file associated to this meshe + ensightGeomFile << "Ensight Geometry File : " << endl + << "Meshing from MedMemory" << endl ; +// ensightGeomFile << "node id given " << endl ; +// ensightGeomFile << "element id given " << endl ; + ensightGeomFile << "node id assign " << endl ; + ensightGeomFile << "element id assign " << endl ; + ensightGeomFile << "coordinates" << endl ; + // put points (all point are in 3D, so if we are in 1D or 2D, we complete by zero ! + int SpaceDimension = _ptrMesh->getSpaceDimension() ; + int NumberOfNodes = _ptrMesh->getNumberOfNodes() ; + ensightGeomFile << NumberOfNodes << endl ; + const double *coordinate = _ptrMesh->getCoordinates(MED_FULL_INTERLACE) ; + ensightGeomFile.setf(ios::scientific); + ensightGeomFile.precision(5); + for (int i=0;igetNumberOfTypes(MED_CELL) ; + const CELLMODEL * cells_type =_ptrMesh->getCellsTypes(MED_CELL) ; + ensightGeomFile << "part 1 " << endl ; + ensightGeomFile << "elements are following " << endl ; + + // we put connectivity + for (int i=0;igetNumberOfElements(MED_CELL,cells_type[i].getType()) ; + int *filter = (int*) NULL ; + switch (cells_type[i].getType()) + { + case MED_POINT1 : { + ensightGeomFile << "point" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[1] ; + filter[0] = 0 ; + break ; + } + case MED_SEG2 : { + ensightGeomFile << "bar2" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[2] ; + filter[0] = 0 ; + filter[1] = 1 ; + break ; + } + case MED_SEG3 : { + filter = new int[3] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + break ; + } + case MED_TRIA3 : { + ensightGeomFile << "tria3" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[3] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + break ; + } + case MED_QUAD4 : { + ensightGeomFile << "quad4" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[4] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + break ; + } + case MED_TRIA6 : { + ensightGeomFile << "tria6" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[6] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 5 ; + filter[4] = 4 ; + filter[5] = 3 ; + break ; + } + case MED_QUAD8 : { + ensightGeomFile << "quad8" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[8] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + filter[4] = 7 ; + filter[5] = 6 ; + filter[6] = 5 ; + filter[7] = 4 ; + break ; + } + case MED_TETRA4 : { + ensightGeomFile << "tetra4" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[4] ; + filter[0] = 0 ; + filter[1] = 1 ; + filter[2] = 3 ; // 3td element in med are 4th in vtk (array begin at 0 !) + filter[3] = 2 ; // 4th element in med are 3rd in vtk (array begin at 0 !) + break ; + } + case MED_PYRA5 : { + ensightGeomFile << "pyramid5" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[5] ; + filter[0] = 0 ; + filter[1] = 3 ; // 2nd element in med are 4th in vtk (array begin at 0 !) + filter[2] = 2 ; + filter[3] = 1 ; // 4th element in med are 2nd in vtk (array begin at 0 !) + filter[4] = 4 ; + break ; + } + case MED_PENTA6 : { + ensightGeomFile << "penta6" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[6] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 3 ; + filter[4] = 4 ; + filter[5] = 5 ; + break ; + } + case MED_HEXA8 : { + ensightGeomFile << "hexa8" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[8] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + filter[4] = 4 ; + filter[5] = 7 ; + filter[6] = 6 ; + filter[7] = 5 ; + break ; + } + case MED_TETRA10 : { + ensightGeomFile << "tetra10" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[10] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 3 ; + filter[4] = 6 ; + filter[5] = 5 ; + filter[6] = 4 ; + filter[7] = 7 ; + filter[8] = 9 ; + filter[9] = 8 ; + break ; + } + case MED_PYRA13 : { + ensightGeomFile << "pyramid13" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + case MED_PENTA15 : { + ensightGeomFile << "penta15" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + case MED_HEXA20 : { + ensightGeomFile << "hexa20" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + default : { + break ; + } + } + if (filter==NULL) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": MED element type not supported yet : " << cells_type[i].getName() ) ) ; + int nodes_cell = cells_type[i].getNumberOfNodes(); + const int * connectivityArray = _ptrMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,cells_type[i].getType()); + for (int j=0;jgetNumberOfTypes() ; + const medGeometryElement * geo_type = _support[i]->getTypes() ; + + ensightGeomFile << "part " << i+2 << endl; + ensightGeomFile << "connectivities description" << endl; + + int nodes_cell; + // we put connectivity + for (int i=0;igetNumberOfElements(geo_type[i]) ; + int *filter = (int*) NULL ; // index in ensight connectivity + switch (geo_type[i]){ + case MED_POINT1 : { + nodes_cell=1; + ensightGeomFile << "point" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[1] ; + filter[0] = 0 ; + break ; + } + case MED_SEG2 : { + nodes_cell=2; + ensightGeomFile << "bar2" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[2] ; + filter[0] = 0 ; + filter[1] = 1 ; + break ; + } + case MED_SEG3 : { + nodes_cell=3; + ensightGeomFile << "bar3" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[3] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + break ; + } + case MED_TRIA3 : { + nodes_cell=3; + ensightGeomFile << "tria3" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[3] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + break ; + } + case MED_QUAD4 : { + nodes_cell=4; + ensightGeomFile << "quad4" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[4] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + break ; + } + case MED_TRIA6 : { + nodes_cell=6; + ensightGeomFile << "tria6" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[6] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 5 ; + filter[4] = 4 ; + filter[5] = 3 ; + break ; + } + case MED_QUAD8 : { + nodes_cell=8; + ensightGeomFile << "quad8" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[8] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + filter[4] = 7 ; + filter[5] = 6 ; + filter[6] = 5 ; + filter[7] = 4 ; + break ; + } + case MED_TETRA4 : { + nodes_cell=4; + ensightGeomFile << "tetra4" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[4] ; + filter[0] = 0 ; + filter[1] = 1 ; + filter[2] = 3 ; // 3td element in med are 4th in ensight (array begin at 0 !) + filter[3] = 2 ; // 4th element in med are 3rd in ensight (array begin at 0 !) + break ; + } + case MED_PYRA5 : { + nodes_cell=5; + ensightGeomFile << "pyramid5" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[5] ; + filter[0] = 0 ; + filter[1] = 3 ; // 2nd element in med are 4th in ensight (array begin at 0 !) + filter[2] = 2 ; + filter[3] = 1 ; // 4th element in med are 2nd in ensight (array begin at 0 !) + filter[4] = 4 ; + break ; + } + case MED_PENTA6 : { + nodes_cell=6; + ensightGeomFile << "penta6" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[6] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 3 ; + filter[4] = 5 ; + filter[5] = 4 ; + break ; + } + case MED_HEXA8 : { + nodes_cell=8; + ensightGeomFile << "hexa8" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[8] ; + filter[0] = 0 ; + filter[1] = 3 ; + filter[2] = 2 ; + filter[3] = 1 ; + filter[4] = 4 ; + filter[5] = 7 ; + filter[6] = 6 ; + filter[7] = 5 ; + break ; + } + case MED_TETRA10 : { + nodes_cell=10; + ensightGeomFile << "tetra10" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + filter = new int[10] ; + filter[0] = 0 ; + filter[1] = 2 ; + filter[2] = 1 ; + filter[3] = 3 ; + filter[4] = 6 ; + filter[5] = 5 ; + filter[6] = 4 ; + filter[7] = 7 ; + filter[8] = 9 ; + filter[9] = 8 ; + break ; + } + case MED_PYRA13 : { + nodes_cell=13; + ensightGeomFile << "pyramid13" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + case MED_PENTA15 : { + nodes_cell=15; + ensightGeomFile << "penta15" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + case MED_HEXA20 : { + nodes_cell=20; + ensightGeomFile << "hexa20" << endl ; + ensightGeomFile << setw(8) << numberOfCell << endl ; + break ; + } + default : { + break ; + } + } + if (filter==NULL) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": MED element type not supported yet : " << cells_type[i].getName() ) ) ; + + const int * connectivityArray = _ptrMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,_support[i]->getEntity(),geo_type[i]); + const int *type = _support[i]->getNumber(geo_type[i]); + + for (int j=0;j type_read ; + vector nbcell_read ; + vector< vector > total_conn ; + vector var ; + + //int number_of_geom ; + string geom_namefile ; + string field_namefile ; + string mot_lu ; + int geom_given = 0 ; + int num_coordinate ; + string type_cell ; + int number_of_cell ; + int conn ; + //----- ? + int SpaceDimension = 3 ; + //----- ? + + int NumberOfTypes = 0 ; + int NumberOfNodes ; + int iType ; + + string mesh_read_name = "EnsightMesh"; // defaut name for the mesh + + // recuperation des arguments du fichier ensight case + // -------------------------------------------------- + + // In this release, the following options are available : + // For GEOMETRY -> model: + + cout << "****************** READ **************** starting " << endl ; + + ifstream ensightCaseFile(_fileName.c_str(),ios::in); + cout << "Ensight case file name to read " << _fileName << endl ; + string diren = getDirName((char*)_fileName.c_str()); + + if (ensightCaseFile.is_open() ) + { + while ( ensightCaseFile >> mot_lu ) + { + if ( mot_lu == "GEOMETRY" ) { + cout << "geometry detected" << endl ; + while ( ensightCaseFile >> mot_lu ){ + if ( mot_lu == "model:" ) { +// ensightCaseFile >> number_of_geom ; +// cout << "number of geometries " << number_of_geom << endl ; + ensightCaseFile >> mot_lu ; + geom_namefile = mot_lu; + cout << "name of geometry file : " << geom_namefile << endl ; + break ; + } + } + } + } + } + else + { + cout << "Error : requested file " << ensightCaseFile << " not found " << endl; + exit( EXIT_FAILURE ); + } + + // chargement des noeuds et connectivites necessaires depuis le fichier ensight geom + // --------------------------------------------------------------------------------- + + _ptrMesh->_name = mesh_read_name ; + + string cgeom_namefile; + if( diren.length() > 0 ) + cgeom_namefile = diren + '/' + geom_namefile; + else + cgeom_namefile = geom_namefile; + cout << "-> Entering into the geometry file " << geom_namefile << endl ; + ifstream ensightGeomFile(cgeom_namefile.c_str(),ios::in); + if (ensightGeomFile.is_open() ) + { + while ( ensightGeomFile >> mot_lu ){ + if ( mot_lu == "given" ) geom_given=1 ; + if ( mot_lu == "coordinates" ) { +//---------------- Nodes part -------------------------------------------------- + ensightGeomFile >> NumberOfNodes ; + cout << "-> loading " << NumberOfNodes << " coordinates " << endl ; + int NumberOfCoordinates = NumberOfNodes*SpaceDimension ; + double* Coordinates = new double[NumberOfCoordinates]; + int iCoord = 0 ; + //cout << "-> geom given " << geom_given << endl ; + for ( int i=0 ; i < NumberOfNodes ; i++) { + if( geom_given) ensightGeomFile >> setw(8) >> num_coordinate ; + ensightGeomFile >> setw(12) >> Coordinates[iCoord] ; + ensightGeomFile >> setw(12) >> Coordinates[iCoord+1] ; + ensightGeomFile >> setw(12) >> Coordinates[iCoord+2] ; +// cout << "coordinate read " << num_coordinate << " : x = " << Coordinates[iCoord] << " y = " << Coordinates[iCoord+1] << " z = " << Coordinates[iCoord+2] << endl ; + iCoord+=3 ; + } + _ptrMesh->_spaceDimension = SpaceDimension; + _ptrMesh->_numberOfNodes = NumberOfNodes; + _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,MED_EN::MED_FULL_INTERLACE); + _ptrMesh->_coordinate->setCoordinates(MED_EN::MED_FULL_INTERLACE,Coordinates); + _ptrMesh->_coordinate->setCoordinatesSystem("CARTESIAN"); + delete [] Coordinates; + } + else if ( mot_lu == "part" ) { +//---------------- Connectivities part -------------------------------------------- + while ( ensightGeomFile >> mot_lu ){ + for ( int j = 0 ; j < 15 ; j++){ + if( mot_lu == type_Ensight[j] ) { + NumberOfTypes+=1; + iType=NumberOfTypes-1 ; + total_conn.resize(NumberOfTypes) ; + type_read.push_back(mot_lu) ; + ensightGeomFile >> number_of_cell ; + nbcell_read.push_back(number_of_cell) ; + total_conn[iType].resize(nb_edge[j]*number_of_cell); + cout << "-> loading " << number_of_cell << " cells connectivities of type " << type_Ensight[j] << " (" << nb_edge[j]*number_of_cell << ") values " << endl ; + for ( int k=0 ; k < nb_edge[j]*number_of_cell ; k++ ) { + ensightGeomFile >> setw(8) >> conn ; + total_conn[iType][k]=conn ; + // cout << " connectivitie " << k << " read = " << total_conn[iType][k] << endl ; + } + } + } + } + } + } + } + // for compilation on WNT +#ifndef WNT + medGeometryElement classicalTypesCell[NumberOfTypes]; + int nbOfClassicalTypesCell[NumberOfTypes]; +#else // massive with zero size can't exist on Win32 + medGeometryElement* classicalTypesCell = new medGeometryElement(NumberOfTypes); + int* nbOfClassicalTypesCell = new int(NumberOfTypes); +#endif + int ind=0 ; + for (int k=0 ; k_connectivity = new CONNECTIVITY(NumberOfTypes,MED_EN::MED_CELL); + _ptrMesh->_connectivity->setGeometricTypes(classicalTypesCell,MED_EN::MED_CELL); + int * Count = new int[NumberOfTypes+1] ; + Count[0]=1 ; + for (int i=0; i_connectivity->setCount(Count,MED_EN::MED_CELL) ; + delete[] Count ; + int MeshDimension ; + MeshDimension = 2 ; + for (int k=0 ; k6 ) MeshDimension = 3 ; + } + _ptrMesh->_meshDimension = MeshDimension; + _ptrMesh->_connectivity->setEntityDimension(MeshDimension); + + for (int k = 0 ; k < NumberOfTypes ; k++) { + int nb_connectivities = total_conn[k].size(); + int *connectivities = new int[nb_connectivities]; + for (int itab=0 ; itab < nb_connectivities ; itab++) connectivities[itab]=total_conn[k][itab] ; + for (int j=0 ; j<15 ; j++) { + if( type_read[k] == type_Ensight[j] ) { + switch ( j+1 ) + { + case 1 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_POINT1) ; break ;} + case 2 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_SEG2) ; break ;} + case 3 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_SEG3) ; break ;} + case 4 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_TRIA3) ; break ;} + case 5 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_TRIA6) ; break ;} + case 6 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_QUAD4) ; break ;} + case 7 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_QUAD8) ; break ;} + case 8 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_TETRA4) ; break ;} + case 9 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_TETRA10) ; break ;} + case 10 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_PYRA5) ; break ;} + case 11 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_PYRA13) ; break ;} + case 12 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_HEXA8) ; break ;} + case 13 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_HEXA20) ; break ;} + case 14 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_PENTA6) ; break ;} + case 15 : {_ptrMesh->_connectivity->setNodal(connectivities,MED_EN::MED_CELL,MED_EN::MED_PENTA15) ; break ;} + default : break ; + } + } + } + delete [] connectivities; + } + +// cout << "Impression de _ptrmesh dans EnsightMeshDriver: " << endl; +// cout << *_ptrMesh ; + + END_OF(LOC); +} + diff --git a/src/MEDMEM/MEDMEM_EnsightMeshDriver.hxx b/src/MEDMEM/MEDMEM_EnsightMeshDriver.hxx new file mode 100644 index 000000000..34a427ac2 --- /dev/null +++ b/src/MEDMEM/MEDMEM_EnsightMeshDriver.hxx @@ -0,0 +1,122 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef ENSIGHT_MESH_DRIVER_HXX +#define ENSIGHT_MESH_DRIVER_HXX + +#include +#include +#include "MEDMEM_define.hxx" +#include "MEDMEM_GenDriver.hxx" +#include "MEDMEM_Support.hxx" + +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Utilities.hxx" + +#include + +using namespace std ; + +/*! + + Driver Ensight for MESH ( writing and reading ). + + Generic part : implement open and close methods. + +*/ +namespace MEDMEM { +class MESH; +class FAMILY; +class GROUP; +class CONNECTIVITY; +class ENSIGHT_MESH_DRIVER : public GENDRIVER +{ +protected: + + MESH * _ptrMesh; + string _meshName; + + virtual void openConst() const =0; + virtual void closeConst() const =0; + +public : + ENSIGHT_MESH_DRIVER() ; + ENSIGHT_MESH_DRIVER(const string & fileName, MESH * ptrMesh) ; + ENSIGHT_MESH_DRIVER(const string & fileName, MESH * ptrMesh, + MED_EN::med_mode_acces accessMode); + ENSIGHT_MESH_DRIVER(const ENSIGHT_MESH_DRIVER & driver) ; + virtual ~ENSIGHT_MESH_DRIVER() ; + + void open(); + void close(); + virtual void write( void ) const = 0 ; + virtual void read( void ) = 0 ; + virtual GENDRIVER * copy (void ) const = 0; + + void setMeshName(const string & meshName) ; + string getMeshName() const ; + +}; + +class ENSIGHT_MESH_RDONLY_DRIVER : public virtual ENSIGHT_MESH_DRIVER +{ +public : + ENSIGHT_MESH_RDONLY_DRIVER(); + ENSIGHT_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh); + ENSIGHT_MESH_RDONLY_DRIVER(const ENSIGHT_MESH_RDONLY_DRIVER & driver); + virtual ~ENSIGHT_MESH_RDONLY_DRIVER(); + void openConst() const; + void closeConst() const; + void write ( void ) const throw (MEDEXCEPTION) ; + void read ( void ) ; +private: + ifstream * _ensightFile; // The main _ensightFile used to read geom and data _filename + GENDRIVER * copy ( void ) const; +}; + +class ENSIGHT_MESH_WRONLY_DRIVER : public virtual ENSIGHT_MESH_DRIVER +{ +public : + ENSIGHT_MESH_WRONLY_DRIVER(); + ENSIGHT_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh); + ENSIGHT_MESH_WRONLY_DRIVER(const ENSIGHT_MESH_WRONLY_DRIVER & driver); + virtual ~ENSIGHT_MESH_WRONLY_DRIVER(); + void openConst() const; + void closeConst() const; + void write ( void ) const throw (MEDEXCEPTION) ; +// void writeFrom ( void ) const throw (MEDEXCEPTION) ; + void read ( void ) throw (MEDEXCEPTION) ; +// virtual void readFileStruct ( void ) throw (MEDEXCEPTION) ; + // add one support + void addSupport(SUPPORT *sup); + +private: + ofstream * _ensightFile; // The main _ensightFile used to write geom and data _filename + GENDRIVER * copy ( void ) const; + vector _support; + +// void writeMesh(MESH * myMesh,int imesh) const ; +// void writeSupport(SUPPORT * mySupport) const ; +}; + +}; + +#endif /* ENSIGHT_MESH_DRIVER_HXX */ + diff --git a/src/MEDMEM/MEDMEM_Exception.hxx b/src/MEDMEM/MEDMEM_Exception.hxx index 5a9edc1d6..8e243f7ef 100644 --- a/src/MEDMEM/MEDMEM_Exception.hxx +++ b/src/MEDMEM/MEDMEM_Exception.hxx @@ -25,6 +25,8 @@ #ifndef MEDEXCEPTION_HXX #define MEDEXCEPTION_HXX +#include + #include #include @@ -41,8 +43,10 @@ using namespace std; Inherits from public exception. */ namespace MEDMEM { + class MEDEXCEPTION; + ostream & operator<< (ostream &os, const MEDEXCEPTION &ex ); //--------------------------------------// - class MEDEXCEPTION : public std::exception + class MEDMEM_EXPORT MEDEXCEPTION : public std::exception //--------------------------------------// { private : diff --git a/src/MEDMEM/MEDMEM_Family.cxx b/src/MEDMEM/MEDMEM_Family.cxx index f42a4e0fa..45dd81714 100644 --- a/src/MEDMEM/MEDMEM_Family.cxx +++ b/src/MEDMEM/MEDMEM_Family.cxx @@ -162,7 +162,8 @@ FAMILY::FAMILY(MESH* Mesh, int Identifier, string Name, int NumberOfAttribute, } // on face ? if (!Find) { - if ((_mesh->existConnectivity(MED_NODAL,MED_FACE))|(_mesh->existConnectivity(MED_DESCENDING,MED_FACE))) { + if ((_mesh->existConnectivityWithPoly(MED_NODAL,MED_FACE)) | + (_mesh->existConnectivityWithPoly(MED_DESCENDING,MED_FACE))) { Find = build(MED_FACE,MEDArrayFaceFamily) ; } } @@ -214,10 +215,12 @@ FAMILY::FAMILY(const FAMILY & m):SUPPORT(m) _identifier = m._identifier; _numberOfAttribute = m._numberOfAttribute; - _attributeIdentifier.set(_numberOfAttribute,m._attributeIdentifier); - _attributeValue.set(_numberOfAttribute,m._attributeValue); - _attributeDescription.set(_numberOfAttribute); + if (_numberOfAttribute) { + _attributeIdentifier.set(_numberOfAttribute,m._attributeIdentifier); + _attributeValue.set(_numberOfAttribute,m._attributeValue); + } + _attributeDescription.set(_numberOfAttribute); for (int i=0;iremoveReference(); } /*! diff --git a/src/MEDMEM/MEDMEM_Field.hxx b/src/MEDMEM/MEDMEM_Field.hxx index 5c39c264d..f96ecfee0 100644 --- a/src/MEDMEM/MEDMEM_Field.hxx +++ b/src/MEDMEM/MEDMEM_Field.hxx @@ -25,6 +25,8 @@ #ifndef FIELD_HXX #define FIELD_HXX +#include "MEDMEM.hxx" + #include #include #include @@ -43,6 +45,9 @@ #include "MEDMEM_FieldForward.hxx" #include "MEDMEM_GaussLocalization.hxx" +#define DBL_MAX 1.0E+308 +#define DBL_MIN -1.0E+308 + /*! This class contains all the informations related with a template class FIELD : @@ -54,6 +59,22 @@ namespace MEDMEM { + template + struct MinMax { + }; + + template<> + struct MinMax { + static double getMin() { return DBL_MIN; } + static double getMax() { return DBL_MAX; } + }; + + template<> + struct MinMax { + static int getMin() { return INT_MIN; } + static int getMax() { return INT_MAX; } + }; + template < typename T > struct SET_VALUE_TYPE { static const MED_EN::med_type_champ _valueType = MED_EN::MED_UNDEFINED_TYPE;}; template < > struct SET_VALUE_TYPE { @@ -61,11 +82,12 @@ namespace MEDMEM { template < > struct SET_VALUE_TYPE { static const MED_EN::med_type_champ _valueType = MED_EN::MED_INT32; }; -class FIELD_ // GENERIC POINTER TO a template class FIELD +class MEDMEM_EXPORT FIELD_ // GENERIC POINTER TO a template class FIELD { protected: bool _isRead ; + bool _isMinMax; /*! \if developper @@ -579,7 +601,7 @@ inline MED_EN::med_type_champ FIELD_::getValueType () const } /*! - Get the FIELD med interlacing type (MED_FULL_INTERLACE or MED_NO_INTERLACE). + Get the FIELD med interlacing type (MED_FULL_INTERLACE, MED_NO_INTERLACE or MED_NO_INTERLACE_BY_TYPE). */ inline MED_EN::medModeSwitch FIELD_::getInterlacingType () const { @@ -604,8 +626,8 @@ inline MED_EN::med_type_champ FIELD_::getValueType () const /*! This template class contains informations related with a FIELD : - - Values of the field, their type (real or integer), the storage mode (full interlace or - no interlace). + - Values of the field, their type (real or integer), the storage mode (full interlace, + no interlace or no interlace by type). */ @@ -623,10 +645,12 @@ namespace MEDMEM { { protected: - typedef typename MEDMEM_ArrayInterface::Array ArrayNoGauss; - typedef typename MEDMEM_ArrayInterface::Array ArrayGauss; - typedef typename MEDMEM_ArrayInterface::Array ArrayNo; - typedef typename MEDMEM_ArrayInterface::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface::Array ArrayNoGauss; + typedef typename MEDMEM_ArrayInterface::Array ArrayGauss; + typedef typename MEDMEM_ArrayInterface::Array ArrayNo; + typedef typename MEDMEM_ArrayInterface::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface::Array ArrayNoByType; + typedef typename MEDMEM_ArrayInterface::Array ArrayNoByTypeGauss; typedef MEDMEM_Array_ Array; typedef T ElementType; typedef INTERLACING_TAG InterlacingTag; @@ -635,6 +659,10 @@ protected: // array of value of type T Array *_value ; + // extrema values + T _vmin; + T _vmax; + map _gaussModel; //A changer quand les drivers seront template de l'entrelacement static T _scalarForPow; @@ -683,6 +711,16 @@ public: static FIELD* div(const FIELD& m, const FIELD& n); static FIELD* divDeep(const FIELD& m, const FIELD& n); double normMax() const throw (MEDEXCEPTION); + + //------- TDG and BS addings + + void getMinMax(T &vmin, T &vmax) throw (MEDEXCEPTION); + vector getHistogram(int &nbint) throw (MEDEXCEPTION); + FIELD* buildGradient() const throw (MEDEXCEPTION); + FIELD* buildNorm2Field() const throw (MEDEXCEPTION); + + //------------------- + double norm2() const throw (MEDEXCEPTION); void applyLin(T a, T b); template void applyFunc(); @@ -735,11 +773,19 @@ public: inline T getValueIJ(int i,int j) const throw (MEDEXCEPTION); inline T getValueIJK(int i,int j,int k) const throw (MEDEXCEPTION); + inline int getValueByTypeLength(int t) const throw (MEDEXCEPTION); + inline const T* getValueByType(int t) const throw (MEDEXCEPTION); + inline T getValueIJByType(int i,int j,int t) const throw (MEDEXCEPTION); + inline T getValueIJKByType(int i,int j,int k,int t) const throw (MEDEXCEPTION); + bool getValueOnElement(int eltIdInSup,T* retValues) const throw (MEDEXCEPTION); const int getNumberOfGeometricTypes() const throw (MEDEXCEPTION); const GAUSS_LOCALIZATION & getGaussLocalization(MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); const GAUSS_LOCALIZATION * getGaussLocalizationPtr(MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + const GAUSS_LOCALIZATION_* getGaussLocalizationRoot(MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + void setGaussLocalization(MED_EN::medGeometryElement geomElement, const GAUSS_LOCALIZATION & gaussloc); + void setGaussLocalization(MED_EN::medGeometryElement geomElement, GAUSS_LOCALIZATION_* gaussloc); const int * getNumberOfGaussPoints() const throw (MEDEXCEPTION); const int getNumberOfGaussPoints( MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); const int getNbGaussI(int i) const throw (MEDEXCEPTION); @@ -752,6 +798,9 @@ public: inline void setRow( int i, T* value) throw (MEDEXCEPTION); inline void setColumn( int i, T* value) throw (MEDEXCEPTION); inline void setValueIJ(int i, int j, T value) throw (MEDEXCEPTION); + inline void setValueIJK(int i, int j, int k, T value) throw (MEDEXCEPTION); + inline void setValueIJByType(int i, int j, int t, T value) throw (MEDEXCEPTION); + inline void setValueIJKByType(int i, int j, int k, int t, T value) throw (MEDEXCEPTION); /*! This fonction feeds the FIELD private attributs _value with the @@ -803,6 +852,8 @@ public: typedef void (*myFuncType)(const double *,T*); void fillFromAnalytic(myFuncType f) throw (MEDEXCEPTION); + typedef void (*myFuncType2)(const T *,T*); + FIELD *execFunc(int nbOfComponents, myFuncType2 f) throw (MEDEXCEPTION); }; } @@ -859,7 +910,7 @@ FIELD::FIELD(const SUPPORT * Support, // becarefull about the numbre of gauss point _numberOfValues = Support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); } -#ifdef _DEBUG_ +#if defined(_DEBUG_) || defined(_DEBUG) catch (MEDEXCEPTION &ex) { #else catch (MEDEXCEPTION ) { @@ -895,17 +946,17 @@ template FIELD::FIELD(const if (m._value != NULL) { if ( m.getGaussPresence() ) - _value = new ArrayGauss( *(dynamic_cast< ArrayGauss * > (m._value) ) ,false); + _value = new ArrayGauss( *(static_cast< ArrayGauss * > (m._value) ) ,false); else - _value = new ArrayNoGauss( *(dynamic_cast< ArrayNoGauss * > (m._value)) ,false); + _value = new ArrayNoGauss( *(static_cast< ArrayNoGauss * > (m._value)) ,false); } else _value = (ArrayNoGauss *) NULL; locMap::const_iterator it; for ( it = m._gaussModel.begin();it != m._gaussModel.end(); it++ ) - _gaussModel[dynamic_cast * > ((*it).second)->getType()]= + _gaussModel[static_cast * > ((*it).second)->getType()]= new GAUSS_LOCALIZATION( - *dynamic_cast * > ( (*it).second ) + *static_cast * > ( (*it).second ) ); _valueType = m._valueType; @@ -932,9 +983,9 @@ FIELD & FIELD::operator=(const FIELD &m) //CF :Commentaire dans MEDMEM_Array locMap::const_iterator it; for ( it = m._gaussModel.begin();it != m._gaussModel.end(); it++ ) - _gaussModel[dynamic_cast * > ((*it).second)->getType()]= + _gaussModel[static_cast * > ((*it).second)->getType()]= new GAUSS_LOCALIZATION( - *dynamic_cast * > ( (*it).second ) + *static_cast * > ( (*it).second ) ); _valueType = m._valueType; @@ -1563,6 +1614,297 @@ template double FIELD::norm2( } +//------------- TDG and BS addings + +/*! Return Extremums of field + */ + template void FIELD::getMinMax(T &vmin, T &vmax) throw (MEDEXCEPTION) +{ + const T* value=getValue(); // get pointer to the values + const int size=getNumberOfValues()*getNumberOfComponents(); + const T* lastvalue=value+size; // point just after last value + + if (size <= 0){ // Size of array has to be strictly positive + + string diagnosis; + diagnosis="FIELD::getMinMax() : cannot compute the extremums of "+getName()+ + " : its size is non positive!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + + if (!_isMinMax){ + vmax=MinMax::getMin(); // init a max value + vmin=MinMax::getMax(); // init a min value + + for( ; value!=lastvalue ; ++value){ + if ( vmin > *value ) + vmin=*value; + if ( vmax < *value ) + vmax=*value; + } + _isMinMax=true; + _vmin=vmin; + _vmax=vmax; + } + else{ + vmin = _vmin; + vmax = _vmax; + } + +} + +/*! Return Histogram of field + */ + template vector FIELD::getHistogram(int &nbint) throw (MEDEXCEPTION) +{ + const T* value=getValue(); // get pointer to the values + const int size=getNumberOfValues()*getNumberOfComponents(); + const T* lastvalue=value+size; // point just after last value + + if (size <= 0){ // Size of array has to be strictly positive + + string diagnosis; + diagnosis="FIELD::getHistogram() : cannot compute the histogram of "+getName()+ + " : it size is non positive!"; + throw MEDEXCEPTION(diagnosis.c_str()); + } + // return static_cast(_value)->getIJ(valIndex,j) ; + + vector Histogram(nbint) ; + T vmin,vmax; + int j; + + for( j=0 ; j!=nbint ; j++) Histogram[j]=0 ; + + getMinMax(vmin,vmax); + for( ; value!=lastvalue ; ++value){ + if(*value==vmax) j = nbint-1; + else j = (int)(((double)nbint * (*value-vmin))/(vmax-vmin)); + Histogram[j]+=1 ; + } + + return Histogram ; + +} + +/*! Return vectorial gradient field + */ +template +FIELD* FIELD::buildGradient() const throw (MEDEXCEPTION) +{ + const char * LOC = "FIELD::buildGradient() : "; + BEGIN_OF(LOC); + + // space dimension of input mesh + int spaceDim = getSupport()->getMesh()->getSpaceDimension(); + double *x = new double[spaceDim]; + + FIELD* Gradient = + new FIELD(getSupport(),spaceDim); + + string name("gradient of "); + name += getName(); + Gradient->setName(name); + string descr("gradient of "); + descr += getDescription(); + Gradient->setDescription(descr); + + if( _numberOfComponents > 1 ){ + delete Gradient; + delete [] x; + throw MEDEXCEPTION("gradient calculation only on scalar field"); + } + + for(int i=1;i<=spaceDim;i++){ + string nameC("gradient of "); + nameC += getName(); + Gradient->setComponentName(i,nameC); + Gradient->setComponentDescription(i,"gradient"); + string MEDComponentUnit = getMEDComponentUnit(1)+getSupport()->getMesh()->getCoordinatesUnits()[i-1]; + Gradient->setMEDComponentUnit(i,MEDComponentUnit); + } + + Gradient->setIterationNumber(getIterationNumber()); + Gradient->setOrderNumber(getOrderNumber()); + Gradient->setTime(getTime()); + + // typ of entity on what is field + MED_EN::medEntityMesh typ = getSupport()->getEntity(); + + const int *C; + const int *iC; + const int *revC; + const int *indC; + const double *coord; + int NumberOf; + + switch (typ) { + case MED_CELL: + case MED_FACE: + case MED_EDGE: + { + // read connectivity array to have the list of nodes contained by an element + C = getSupport()->getMesh()->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,typ,MED_ALL_ELEMENTS); + iC = getSupport()->getMesh()->getConnectivityIndex(MED_NODAL,typ); + // calculate reverse connectivity to have the list of elements which contains node i + revC = getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ); + indC = getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ); + // coordinates of each node + coord = getSupport()->getMesh()->getCoordinates(MED_FULL_INTERLACE); + // number of elements + NumberOf = getSupport()->getNumberOfElements(MED_ALL_ELEMENTS); + // barycenter field of elements + FIELD* barycenter = getSupport()->getMesh()->getBarycenter(getSupport()); + + // calculate gradient vector for each element i + for (int i = 1; i < NumberOf + 1; i++) { + + // listElements contains elements which contains a node of element i + set listElements; + set ::iterator elemIt; + listElements.clear(); + + // for each node j of element i + for (int ij = iC[i-1]; ij < iC[i]; ij++) { + int j = C[ij-1]; + for (int k = indC[j-1]; k < indC[j]; k++) { + // c element contains node j + int c = revC[k-1]; + // we put the elements in set + if (c != i) + listElements.insert(c); + } + } + // coordinates of barycentre of element i in space of dimension spaceDim + for (int j = 0; j < spaceDim; j++) + x[j] = barycenter->getValueIJ(i,j+1); + + for (int j = 0; j < spaceDim; j++) { + // value of field of element i + double val = getValueIJ(i,1); + double grad = 0.; + // calculate gradient for each neighbor element + for (elemIt = listElements.begin(); elemIt != listElements.end(); elemIt++) { + int elem = *elemIt; + double d2 = 0.; + for (int l = 0; l < spaceDim; l++) { + // coordinate of barycenter of element elem + double xx = barycenter->getValueIJ(elem, l+1); + d2 += (x[l]-xx) * (x[l]-xx); + } + grad += (barycenter->getValueIJ(elem,j+1)-x[j])*(getValueIJ(elem,1)-val)/sqrt(d2); + } + if (listElements.size() != 0) grad /= listElements.size(); + Gradient->setValueIJ(i,j+1,grad); + } + } + delete barycenter; + } + break; + case MED_NODE: + // read connectivity array to have the list of nodes contained by an element + C = getSupport()->getMesh()->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS); + iC = getSupport()->getMesh()->getConnectivityIndex(MED_NODAL,MED_CELL); + // calculate reverse connectivity to have the list of elements which contains node i + revC=getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,MED_CELL); + indC=getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,MED_CELL); + // coordinates of each node + coord = getSupport()->getMesh()->getCoordinates(MED_FULL_INTERLACE); + + // calculate gradient for each node + NumberOf = getSupport()->getNumberOfElements(MED_ALL_ELEMENTS); + for (int i=1; i listNodes; + set ::iterator nodeIt ; + listNodes.clear(); + for(int j=indC[i-1];jsetValueIJ(i,j+1,grad); + } + } + break; + case MED_ALL_ENTITIES: + delete [] x; + delete Gradient; + throw MEDEXCEPTION("gradient calculation not yet implemented on all elements"); + break; + } + + delete [] x; + + END_OF(LOC); + return Gradient; +} + +/*! Return scalar norm2 field + */ +template +FIELD* FIELD::buildNorm2Field() const throw (MEDEXCEPTION) +{ + const char * LOC = "FIELD::buildNorm2Field() : "; + BEGIN_OF(LOC); + + FIELD* Norm2Field = + new FIELD(getSupport(),1); + + string name("norm2 of "); + name += getName(); + Norm2Field->setName(name); + string descr("norm2 of "); + descr += getDescription(); + Norm2Field->setDescription(descr); + + string nameC("norm2 of "); + nameC += getName(); + Norm2Field->setComponentName(1,nameC); + Norm2Field->setComponentDescription(1,"norm2"); + string MEDComponentUnit = getMEDComponentUnit(1); + Norm2Field->setMEDComponentUnit(1,MEDComponentUnit); + + Norm2Field->setIterationNumber(getIterationNumber()); + Norm2Field->setOrderNumber(getOrderNumber()); + Norm2Field->setTime(getTime()); + + // calculate nom2 for each element + int NumberOf = getSupport()->getNumberOfElements(MED_ALL_ELEMENTS); + for (int i=1; isetValueIJ(i,1,sqrt(norm2)); + } + + END_OF(LOC); + return Norm2Field; + +} + /*! Apply to each (scalar) field component the template parameter T_function, * which is a pointer to function. * Since the pointer is known at compile time, the function is inlined into the inner loop! @@ -1703,11 +2045,16 @@ double FIELD::normL2(int component, ArrayNo * myArray = NULL; if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE ) value = getValue(); + else if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< ArrayNoByType * > ( getArrayNoGauss() ) )); + value = myArray->getPtr(); + } else { myArray = ArrayConvert( *( dynamic_cast< ArrayFull * > ( getArrayNoGauss() ) )); value = myArray->getPtr(); } - + + value = value + (component-1) * getNumberOfValues(); const T* lastvalue=value+getNumberOfValues(); // pointing just after the end of column double integrale=0.0; @@ -1720,7 +2067,7 @@ double FIELD::normL2(int component, if(!p_field_volume) // if the user didn't supply the volume delete p_field_size; // delete temporary volume field - if ( getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) delete myArray; + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE ) delete myArray; if( totVol <= 0) throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); @@ -1747,6 +2094,10 @@ double FIELD::normL2(const FIELD * p_ ArrayNo * myArray = NULL; if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE ) value = getValue(); + else if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ){ + myArray = ArrayConvert2No( *( dynamic_cast< ArrayNoByType * > ( getArrayNoGauss() ) )); + value = myArray->getPtr(); + } else { myArray = ArrayConvert( *( dynamic_cast< ArrayFull * > ( getArrayNoGauss() ) )); value = myArray->getPtr(); @@ -1764,7 +2115,7 @@ double FIELD::normL2(const FIELD * p_ if(!p_field_volume) // if the user didn't supply the volume delete p_field_size; // delete temporary volume field - if ( getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) delete myArray; + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE ) delete myArray; if( totVol <= 0) throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); @@ -1793,6 +2144,10 @@ double FIELD::normL1(int component, ArrayNo * myArray = NULL; if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE ) value = getColumn(component); + else if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< ArrayNoByType * > ( getArrayNoGauss() ) )); + value = myArray->getColumn(component); + } else { myArray = ArrayConvert( *( dynamic_cast< ArrayFull * > ( getArrayNoGauss() ) )); value = myArray->getColumn(component); @@ -1810,7 +2165,7 @@ double FIELD::normL1(int component, if(!p_field_volume) // if the user didn't supply the volume delete p_field_size; // delete temporary volume field - if ( getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) delete myArray; + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE ) delete myArray; if( totVol <= 0) throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); @@ -1837,6 +2192,10 @@ double FIELD::normL1(const FIELD * p_ ArrayNo * myArray = NULL; if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE ) value = getValue(); + else if ( getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< ArrayNoByType * > ( getArrayNoGauss() ) )); + value = myArray->getPtr(); + } else { myArray = ArrayConvert( *( dynamic_cast< ArrayFull * > ( getArrayNoGauss() ) )); value = myArray->getPtr(); @@ -1854,7 +2213,7 @@ double FIELD::normL1(const FIELD * p_ if(!p_field_volume) // if the user didn't supply the volume delete p_field_size; // delete temporary volume field - if ( getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) delete myArray; + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE ) delete myArray; if( totVol <= 0) throw MEDEXCEPTION(STRING("cannot compute sobolev norm : volume is not positive!")); @@ -2415,7 +2774,7 @@ FIELD::getArrayGauss() const throw (MEDEXCEPTION) BEGIN_OF(LOC); if ( getGaussPresence() ) - return dynamic_cast (_value); + return static_cast (_value); else throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "The field has no Gauss Point")); @@ -2432,7 +2791,7 @@ FIELD::getArrayNoGauss() const throw (MEDEXCEPTION) BEGIN_OF(LOC); if ( ! getGaussPresence() ) - return dynamic_cast < ArrayNoGauss * > (_value); + return static_cast < ArrayNoGauss * > (_value); else throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "The field has Gauss Point")); @@ -2464,9 +2823,9 @@ inline int FIELD::getValueLength() const throw (MEDEXCEPTION) { if ( getGaussPresence() ) - return dynamic_cast(_value)->getArraySize() ; + return static_cast(_value)->getArraySize() ; else - return dynamic_cast(_value)->getArraySize() ; + return static_cast(_value)->getArraySize() ; } /*! @@ -2478,9 +2837,9 @@ inline const T* FIELD::getValue() const throw (MEDEXCEPTION) const char * LOC ="FIELD::getValue() : "; BEGIN_OF(LOC); if ( getGaussPresence() ) - return dynamic_cast(_value)->getPtr() ; + return static_cast(_value)->getPtr() ; else - return dynamic_cast(_value)->getPtr() ; + return static_cast(_value)->getPtr() ; } /*! Return a reference to i^{th} row @@ -2518,7 +2877,7 @@ FIELD::getRow(int i) const throw (MEDEXCEPTION) template inline const T* FIELD::getColumn(int j) const throw (MEDEXCEPTION) { - const char * LOC ="FIELD::getColumn(int j) : "; + //const char * LOC ="FIELD::getColumn(int j) : "; //BEGIN_OF(LOC); if ( getGaussPresence() ) return static_cast(_value)->getColumn(j) ; @@ -2564,6 +2923,84 @@ template inline T FIELD::getV return static_cast(_value)->getIJK(valIndex,j,k) ; } +/*! + Return number of values of a geomertic type in NoInterlaceByType mode +*/ +template +inline int FIELD::getValueByTypeLength(int t) const throw (MEDEXCEPTION) +{ + const char * LOC ="getValueByTypeLength() : "; + //BEGIN_OF(LOC); + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"not MED_NO_INTERLACE_BY_TYPE field" )); + + if ( getGaussPresence() ) { + ArrayNoByTypeGauss* array = static_cast(_value); + if ( t < 1 || t > array->getNbGeoType() ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Invalid type: "<< t )); + return array->getLengthOfType( t ); + } + else { + ArrayNoByType* array = static_cast(_value); + if ( t < 1 || t > array->getNbGeoType() ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Invalid type: "<< t )); + return array->getLengthOfType( t ); + } +} + +/*! + Return a reference to values array to read them. +*/ +template +inline const T* FIELD::getValueByType(int t) const throw (MEDEXCEPTION) +{ + const char * LOC ="getValueByType() : "; + //BEGIN_OF(LOC); + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"not MED_NO_INTERLACE_BY_TYPE field" )); + + if ( getGaussPresence() ) { + ArrayNoByTypeGauss* array = static_cast(_value); + return array->getPtr() + array->getIndex( t ); + } + else { + ArrayNoByType* array = static_cast(_value); + return array->getPtr() + array->getIndex( t ); + } +} + +/*! + Return the value of i^{th} element in indicated type t and j^{th} component. +*/ +template inline T FIELD::getValueIJByType(int i,int j, int t) const throw (MEDEXCEPTION) +{ + const char * LOC = "getValueIJByType(..)"; + //BEGIN_OF(LOC); + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"not MED_NO_INTERLACE_BY_TYPE field" )); + + if ( getGaussPresence() ) + return static_cast(_value)->getIJByType(i,j,t) ; + else + return static_cast(_value)->getIJByType(i,j,t) ; +} + +/*! + Return the j^{th} component of k^{th} gauss points of i^{th} value with type t. +*/ +template inline T FIELD::getValueIJKByType(int i,int j,int k,int t) const throw (MEDEXCEPTION) +{ + const char * LOC = "getValueIJKByType(..)"; + //BEGIN_OF(LOC); + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"not MED_NO_INTERLACE_BY_TYPE field" )); + + if ( getGaussPresence() ) + return static_cast(_value)->getIJKByType(i,j,k,t) ; + else + return static_cast(_value)->getIJKByType(i,j,k,t) ; +} + template const int FIELD::getNumberOfGeometricTypes() const throw (MEDEXCEPTION) { @@ -2609,6 +3046,53 @@ FIELD::getGaussLocalizationPtr(MED_EN::medGeometryElement geo }; +/*! + * \brief Return GAUSS_LOCALIZATION_* whose interlacing type may differ from one of the field + */ +template const GAUSS_LOCALIZATION_ * +FIELD::getGaussLocalizationRoot(MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION) +{ + const char * LOC ="getGaussLocalizationRoot(MED_EN::medGeometryElement geomElement) : "; + + locMap::const_iterator it; + if ( ( it = _gaussModel.find(geomElement)) != _gaussModel.end() ) { + return (*it).second; + } + else + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Can't find any GaussLocalization on this geometric type: "<< geomElement )); + +}; + +/*! + * \brief Take onership of GAUSS_LOCALIZATION_* whose interlacing type may differ from one of the field + */ +template void +FIELD::setGaussLocalization(MED_EN::medGeometryElement geomElement, GAUSS_LOCALIZATION_* gaussloc) +{ + locMap::iterator it = _gaussModel.find(geomElement); + if ( it != _gaussModel.end() ) { + delete it->second; + it->second = gaussloc; + } + else { + _gaussModel[ geomElement ] = gaussloc; + } +}; + + +template void +FIELD::setGaussLocalization(MED_EN::medGeometryElement geomElement, const GAUSS_LOCALIZATION& gaussloc) +{ + locMap::iterator it = _gaussModel.find(geomElement); + if ( it != _gaussModel.end() ) { + delete it->second; + it->second = new GAUSS_LOCALIZATION (gaussloc); + } + else { + _gaussModel[ geomElement ] = new GAUSS_LOCALIZATION (gaussloc); + } +}; + /*! Returns number of Gauss points for this medGeometryElement. @@ -2656,7 +3140,7 @@ template const int * FIELD::g if (_value) if ( getGaussPresence() ) { - return dynamic_cast(_value)->getNbGaussGeo()+1; + return static_cast(_value)->getNbGaussGeo()+1; } else throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"value hasn't Gauss points " )); @@ -2731,9 +3215,9 @@ template bool FIELD::isOnAll template inline void FIELD::setValue( T* value) throw (MEDEXCEPTION) { if ( getGaussPresence() ) - return dynamic_cast(_value)->setPtr(value) ; + static_cast(_value)->setPtr(value) ; else - return dynamic_cast(_value)->setPtr(value) ; + static_cast(_value)->setPtr(value) ; } /*! @@ -2751,9 +3235,9 @@ inline void FIELD::setRow( int i, T* value) throw (MEDEXCEPTI throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support not define |" )); if ( getGaussPresence() ) - return static_cast(_value)->setRow(valIndex, value) ; + static_cast(_value)->setRow(valIndex, value) ; else - return static_cast(_value)->setRow(valIndex, value) ; + static_cast(_value)->setRow(valIndex, value) ; } /*! @@ -2764,9 +3248,9 @@ template inline void FIELD::setColumn( int j, T* value) throw (MEDEXCEPTION) { if ( getGaussPresence() ) - return static_cast(_value)->setColumn(j, value) ; + static_cast(_value)->setColumn(j, value) ; else - return static_cast(_value)->setColumn(j, value) ; + static_cast(_value)->setColumn(j, value) ; } /*! @@ -2782,9 +3266,57 @@ template inline void FIELD::s throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support not define |" )); if ( getGaussPresence() ) - return static_cast(_value)->setIJ(valIndex,j,value) ; + static_cast(_value)->setIJ(valIndex,j,value) ; + else + static_cast(_value)->setIJ(valIndex,j,value) ; +} + +/*! + Set the value of i^{th} element, j^{th} component and k^{th} gauss point with the given one. +*/ +template inline void FIELD::setValueIJK(int i, int j, int k, T value) throw (MEDEXCEPTION) +{ + const char * LOC = "FIELD::setValueIJ(int i, int j, T value) : "; + int valIndex=-1; + if (_support) + valIndex = _support->getValIndFromGlobalNumber(i); + else + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Support not define |" )); + + if ( getGaussPresence() ) + static_cast(_value)->setIJK(valIndex,j,k,value) ; + else + static_cast(_value)->setIJK(valIndex,j,k,value) ; +} + +/*! + Set the value of i^{th} element and j^{th} component with the given one. +*/ +template inline void FIELD::setValueIJByType(int i, int j, int t, T value) throw (MEDEXCEPTION) +{ + const char * LOC = "FIELD::setValueIJByType(int i, int j, int t, T value) : "; + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"not MED_NO_INTERLACE_BY_TYPE field" )); + + if ( getGaussPresence() ) + return static_cast(_value)->setIJByType(i,j,t,value) ; + else + return static_cast(_value)->setIJByType(i,j,t,value) ; +} + +/*! + Set the value of component of k^{th} gauss points of i^{th} element and j^{th} component with the given one. +*/ +template inline void FIELD::setValueIJKByType(int i, int j, int k, int t, T value) throw (MEDEXCEPTION) +{ + const char * LOC = "FIELD::setValueIJKByType(int i, int j, int t, int k, T value) : "; + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"not MED_NO_INTERLACE_BY_TYPE field" )); + + if ( getGaussPresence() ) + return static_cast(_value)->setIJKByType(i,j,k,t,value) ; else - return static_cast(_value)->setIJ(valIndex,j,value) ; + return static_cast(_value)->setIJKByType(i,j,k,t,value) ; } /* @@ -2963,6 +3495,22 @@ void FIELD::fillFromAnalytic(myFuncType f) throw (MEDEXCEPTI delete [] xyz[j]; delete [] xyz; } +/*! + Execute a function on _values on 'this' and put the result on a newly created field that has to be deallocated. + WARNING : "this" must have allocated its array by setting this->_support and this->_numberOfComponents properly. + Typically you should use it on a field built with constructor FIELD::FIELD(SUPPORT *,int nbOfComponents) + */ + template + FIELD *FIELD::execFunc(int nbOfComponents, myFuncType2 f) throw (MEDEXCEPTION) +{ + FIELD *ret=new FIELD(_support,nbOfComponents); + const T* valsInput=getValue(); + T* valsOutPut=(T*)ret->getValue(); + int i; + for(i=0;i<_numberOfValues;i++) + f(valsInput+i*_numberOfComponents,valsOutPut+i*nbOfComponents); + return ret; +} }//End namespace MEDMEM diff --git a/src/MEDMEM/MEDMEM_FieldConvert.hxx b/src/MEDMEM/MEDMEM_FieldConvert.hxx index 2ddbbaaf8..996df2ebb 100644 --- a/src/MEDMEM/MEDMEM_FieldConvert.hxx +++ b/src/MEDMEM/MEDMEM_FieldConvert.hxx @@ -74,5 +74,28 @@ FieldConvert(const FIELD & field ) } +template FIELD * +FieldConvert(const FIELD & field ) +{ + typedef typename MEDMEM_ArrayInterface::Array ArrayFullNo; + typedef typename MEDMEM_ArrayInterface::Array ArrayFullGa; + + FIELD * myField = new FIELD(); + FIELD_ * myField_ = myField; + FIELD_ * field_ = &(const_cast< FIELD &> (field)); + *myField_ = *field_; // OpĂ©rateur d'affectation de FIELD_ OK + // *((FIELD_ *) myField) = (FIELD_ ) field; //Contructeur par recopie de FIELD_ Pourquoi? + + if ( field.getGaussPresence() ) { + ArrayFullGa * myArray = ArrayConvert( *(field.getArrayGauss()) ); + myField->setArray(myArray); + return myField; + } else { + ArrayFullNo * myArray = ArrayConvert( *(field.getArrayNoGauss()) ); + myField->setArray(myArray); + return myField; + } +} + } #endif diff --git a/src/MEDMEM/MEDMEM_GaussLocalization.cxx b/src/MEDMEM/MEDMEM_GaussLocalization.cxx new file mode 100644 index 000000000..5414d5189 --- /dev/null +++ b/src/MEDMEM/MEDMEM_GaussLocalization.cxx @@ -0,0 +1,61 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +// PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : MEDMEM_GaussLocalization.cxx +// Created : Thu Dec 20 12:26:33 2007 +// Author : Edward AGAPOV (eap) + +#include "MEDMEM_GaussLocalization.hxx" + +#include "MED_GaussDef.hxx" + +#include + +using namespace MED; + +//======================================================================= +/*! + * Creates a localization filled with default values. The caller gets pointer ownership + */ +//======================================================================= + +namespace MEDMEM { + + GAUSS_LOCALIZATION_* + GAUSS_LOCALIZATION_::makeDefaultLocalization(const string & locName, + medGeometryElement typeGeo, + int nGauss) throw (MEDEXCEPTION) + { + TGaussDef gaussDef( typeGeo, nGauss, 1 ); + + GAUSS_LOCALIZATION_ * gsloc = 0; + try { + gsloc = new GAUSS_LOCALIZATION ( locName.c_str(), + typeGeo, + nGauss, + &gaussDef.myRefCoords[0], + &gaussDef.myCoords[0], + &gaussDef.myWeights[0] ); + } + catch ( const std::logic_error & e ) { + throw MEDEXCEPTION( e.what() ) ; + } + + return gsloc; + } +} diff --git a/src/MEDMEM/MEDMEM_GaussLocalization.hxx b/src/MEDMEM/MEDMEM_GaussLocalization.hxx index 9e691e01d..b05a686e8 100644 --- a/src/MEDMEM/MEDMEM_GaussLocalization.hxx +++ b/src/MEDMEM/MEDMEM_GaussLocalization.hxx @@ -37,6 +37,13 @@ namespace MEDMEM { public: virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;} virtual ~GAUSS_LOCALIZATION_() {}; //Indispensable pour dĂ©truire le vrai objet pointĂ© + + /*! + * \brief Creates a localization filled with default values. The caller gets pointer ownership + */ + static GAUSS_LOCALIZATION_* makeDefaultLocalization(const string & locName, + medGeometryElement typeGeo, + int nGauss) throw (MEDEXCEPTION); }; template class GAUSS_LOCALIZATION; diff --git a/src/MEDMEM/MEDMEM_GenDriver.cxx b/src/MEDMEM/MEDMEM_GenDriver.cxx index 15bf873e8..6d83a0e2c 100644 --- a/src/MEDMEM/MEDMEM_GenDriver.cxx +++ b/src/MEDMEM/MEDMEM_GenDriver.cxx @@ -136,6 +136,9 @@ ostream & MEDMEM::operator<<(ostream &os,const GENDRIVER & drv) case MED_REMP : os <<"C'est un IO de remplacement"< + #include #include "MEDMEM_define.hxx" @@ -37,8 +39,11 @@ using namespace std; namespace MEDMEM { /* Modify the following line to add a new driver type (step 1) */ -typedef enum { MED_DRIVER = 0, GIBI_DRIVER = 1, PORFLOW_DRIVER = 2, VTK_DRIVER = 254, ASCII_DRIVER = 3, NO_DRIVER = 255 } driverTypes; -class GENDRIVER { +typedef enum { MED_DRIVER = 0, GIBI_DRIVER = 1, PORFLOW_DRIVER = 2, ENSIGHT_DRIVER = 250, VTK_DRIVER = 254, ASCII_DRIVER = 3, NO_DRIVER = 255 } driverTypes; + class GENDRIVER; + ostream & operator<<(ostream &os,const GENDRIVER &genDriver); + +class MEDMEM_EXPORT GENDRIVER { protected : @@ -78,7 +83,7 @@ public: /*! Operator << : put GENDRIVER object information to the given stream */ - friend ostream & operator<<(ostream &os,const GENDRIVER &genDriver); + friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const GENDRIVER &genDriver); bool operator ==(const GENDRIVER &genDriver) const; /*! @@ -116,6 +121,7 @@ public: virtual void readFileStruct ( void ); // MESH related Part virtual void setMeshName ( const string & meshName); + virtual string getMeshName() const { return string(""); } // FIELD related Part virtual void setFieldName ( const string & fieldName); @@ -123,7 +129,7 @@ public: int getId ( void ) const ; string getFileName () const; void setFileName ( const string & fileName); - MED_EN::med_mode_acces getAccessMode() const; + virtual MED_EN::med_mode_acces getAccessMode() const; }; }; diff --git a/src/MEDMEM/MEDMEM_GibiMeshDriver.cxx b/src/MEDMEM/MEDMEM_GibiMeshDriver.cxx index 6fdb3d24c..d062be8bb 100644 --- a/src/MEDMEM/MEDMEM_GibiMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_GibiMeshDriver.cxx @@ -53,13 +53,12 @@ using namespace MED_EN; using namespace MEDMEM; ///// -// allows to continue reading if some data not supported by MEDMEM encountered, -// e.g. non-scalar fields -//#define STOP_READING_UNSUP_DATA - // read or not non-named fields //#define GIBI_READ_ONLY_NAMED_FIELD +// to throw an exception when try to write a name longer than 8 or non-unique encounters +#define THROW_ON_BAD_NAME + // to see full dump of RESULTATS STRUCTURE INTERMEDIAIRES #ifdef _DEBUG_ // #undef MESSAGE @@ -71,19 +70,19 @@ using namespace MEDMEM; // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor ///// -const size_t GIBI_MESH_DRIVER::nb_geometrie_gibi; +//const size_t GIBI_MESH_DRIVER::nb_geometrie_gibi; const medGeometryElement GIBI_MESH_DRIVER::geomGIBItoMED[nb_geometrie_gibi] = - { /*1 */ MED_POINT1 ,/*2 */ MED_SEG2 ,/*3 */ MED_SEG3 ,/*4 */ MED_TRIA3 ,/*5 */ MED_NONE , - /*6 */ MED_TRIA6 ,/*7 */ MED_NONE ,/*8 */ MED_QUAD4 ,/*9 */ MED_NONE ,/*10*/ MED_QUAD8 , - /*11*/ MED_NONE ,/*12*/ MED_NONE ,/*13*/ MED_NONE ,/*14*/ MED_HEXA8 ,/*15*/ MED_HEXA20 , - /*16*/ MED_PENTA6 ,/*17*/ MED_PENTA15,/*18*/ MED_NONE ,/*19*/ MED_NONE ,/*20*/ MED_NONE , - /*21*/ MED_NONE ,/*22*/ MED_NONE ,/*23*/ MED_TETRA4 ,/*24*/ MED_TETRA10,/*25*/ MED_PYRA5 , - /*26*/ MED_PYRA13 ,/*27*/ MED_NONE ,/*28*/ MED_NONE ,/*29*/ MED_NONE ,/*30*/ MED_NONE , - /*31*/ MED_NONE ,/*32*/ MED_NONE ,/*33*/ MED_NONE ,/*34*/ MED_NONE ,/*35*/ MED_NONE , - /*36*/ MED_NONE ,/*37*/ MED_NONE ,/*38*/ MED_NONE ,/*39*/ MED_NONE ,/*40*/ MED_NONE , - /*41*/ MED_NONE ,/*42*/ MED_NONE ,/*43*/ MED_NONE ,/*44*/ MED_NONE ,/*45*/ MED_NONE , - /*46*/ MED_NONE ,/*47*/ MED_NONE }; + { /*1 */ MED_POINT1 ,/*2 */ MED_SEG2 ,/*3 */ MED_SEG3 ,/*4 */ MED_TRIA3 ,/*5 */ MED_NONE , + /*6 */ MED_TRIA6 ,/*7 */ MED_NONE ,/*8 */ MED_QUAD4 ,/*9 */ MED_NONE ,/*10*/ MED_QUAD8 , + /*11*/ MED_NONE ,/*12*/ MED_NONE ,/*13*/ MED_NONE ,/*14*/ MED_HEXA8 ,/*15*/ MED_HEXA20 , + /*16*/ MED_PENTA6 ,/*17*/ MED_PENTA15,/*18*/ MED_NONE ,/*19*/ MED_NONE ,/*20*/ MED_NONE , + /*21*/ MED_NONE ,/*22*/ MED_NONE ,/*23*/ MED_TETRA4 ,/*24*/ MED_TETRA10,/*25*/ MED_PYRA5 , + /*26*/ MED_PYRA13 ,/*27*/ MED_NONE ,/*28*/ MED_NONE ,/*29*/ MED_NONE ,/*30*/ MED_NONE , + /*31*/ MED_NONE ,/*32*/ MED_NONE ,/*33*/ MED_NONE ,/*34*/ MED_NONE ,/*35*/ MED_NONE , + /*36*/ MED_NONE ,/*37*/ MED_NONE ,/*38*/ MED_NONE ,/*39*/ MED_NONE ,/*40*/ MED_NONE , + /*41*/ MED_NONE ,/*42*/ MED_NONE ,/*43*/ MED_NONE ,/*44*/ MED_NONE ,/*45*/ MED_NONE , + /*46*/ MED_NONE ,/*47*/ MED_NONE }; //======================================================================= //function : gibi2medGeom @@ -132,7 +131,7 @@ static int getGroupId(const vector& support_ids, _intermediateMED* medi) set sup_set; sup_set.insert( sb, se ); - for ( group_id = 0; group_id < medi->groupes.size(); ++group_id ) + for ( group_id = 0; group_id < (int)medi->groupes.size(); ++group_id ) { if (sup_set.size() == medi->groupes[ group_id ].groupes.size() && std::equal (sup_set.begin(), sup_set.end(), @@ -200,6 +199,11 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields PILE_FIELD, PILE_LAST_READABLE }; + // other known piles: + // PILE NUMERO 26 - Integers + // PILE NUMERO 25 - Floats + // PILE NUMERO 27 - Strings + // PILE NUMERO 10 - Tables char* ligne; // pour lire une ligne const char* enregistrement_type=" ENREGISTREMENT DE TYPE"; vector numero_noeuds; // tableau de travail (indices) @@ -283,10 +287,12 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // MESH GROUPS // ----------------------------------- - if (numero_pile == PILE_SOUS_MAILLAGE ) + if (numero_pile == PILE_SOUS_MAILLAGE ) // PILE NUMERO 1 { map strangeGroupType; medi->groupes.reserve(nb_objets*2); // fields may add some groups + map< int , int > nbElemsByGeomType; + for (int objet=0; objet!=nb_objets; ++objet) // pour chaque groupe { initIntReading( 5 ); @@ -319,20 +325,28 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields std::sort( groupe.groupes.begin(), groupe.groupes.end() ); } // lecture des references (non utilisĂƒÂ© pour MED) - for ( i = 0; i < nb_reference; i += 10 ) {// FORMAT(10I8) + for ( i = 0; i < (int)nb_reference; i += 10 ) {// FORMAT(10I8) getNextLine(ligne); } // lecture des couleurs (non utilisĂƒÂ© pour MED) - for ( i = 0; i < nb_elements; i += 10 ) { + for ( i = 0; i < (int)nb_elements; i += 10 ) { getNextLine(ligne); } // not a composit group if (type_geom_castem>0 && nb_sous_maillage==0) { medGeometryElement medType = gibi2medGeom(type_geom_castem); - bool goodType = ( medType!=MED_NONE ); - if ( !goodType ) + + initIntReading( nb_elements * nb_noeud ); + if ( medType == MED_NONE ) { // look for group end + while ( more() ) + next(); strangeGroupType.insert( make_pair( objet, type_geom_castem )); + continue; + } + if ( nbElemsByGeomType.find( medType ) == nbElemsByGeomType.end()) + nbElemsByGeomType[ medType ] = 0; + int & order = nbElemsByGeomType[ medType ]; pair::iterator,bool> p; pair::iterator,bool> p_no; @@ -340,31 +354,24 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields no.coord.resize(space_dimension); _maille ma( medType, nb_noeud ); ma.sommets.resize(nb_noeud); - if ( goodType ) - groupe.mailles.resize( nb_elements ); + groupe.mailles.resize( nb_elements ); // lecture pour chaque maille des sommets et insertions - initIntReading( nb_elements * nb_noeud ); - if ( !goodType ) { - while ( more() ) - next(); - } - else { - for ( i = 0; i < nb_elements; ++i ) + for ( i = 0; i < nb_elements; ++i ) + { + for (unsigned n = 0; n < nb_noeud; ++n, next() ) { - for (unsigned n = 0; n < nb_noeud; ++n, next() ) - { - if ( !more() ) { - INFOS( " Error while reading elem nodes "); - return false; - } - no.number = getInt(); - p_no=medi->points.insert(make_pair(no.number, no)); - ma.sommets[n]=p_no.first; + if ( !more() ) { + INFOS( " Error while reading elem nodes "); + return false; } - p=medi->maillage.insert(ma); - groupe.mailles[i] = p.first; // on stocke dans le groupe un iterateur sur la maille + no.number = getInt(); + p_no=medi->points.insert(make_pair(no.number, no)); + ma.sommets[n]=p_no.first; } + ma.ordre = ++order; + p=medi->maillage.insert(ma); + groupe.mailles[i] = p.first; // on stocke dans le groupe un iterateur sur la maille } } } // loop on groups @@ -382,6 +389,9 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields grp.nom=objets_nommes[i]; map::iterator it = strangeGroupType.find( grpID - 1 ); if ( it != strangeGroupType.end() ) { +#ifdef _DEBUG + cout << "Skip " << grp.nom << " of not supported CASTEM type: " << it->second << endl; +#endif //INFOS( "Skip " << grp.nom << " of not supported CASTEM type: " << it->second ); } } @@ -392,7 +402,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // NODES // --------------------------------- - else if ( numero_pile == PILE_NOEUDS ) + else if ( numero_pile == PILE_NOEUDS ) // PILE NUMERO 32 { getNextLine( ligne ); std::vector place_noeuds; @@ -421,7 +431,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // COORDINATES // --------------------------------------- - else if ( numero_pile == PILE_COORDONNEES ) + else if ( numero_pile == PILE_COORDONNEES )// PILE NUMERO 33 { getNextLine( ligne ); unsigned nb_reels = atoi( ligne ); @@ -456,7 +466,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // NODE FIELDS // --------------------------------------- - else if ( numero_pile == PILE_NODES_FIELD && readFields ) + else if ( numero_pile == PILE_NODES_FIELD && readFields ) // PILE NUMERO 2 { vector< _fieldBase* > fields( nb_objets ); for (int objet=0; objet!=nb_objets; ++objet) // pour chaque field @@ -536,7 +546,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields } } // (4) nb harmonics ( ignored ) - for ( initIntReading( nb_sub ); more(); next() ) + for ( initIntReading( total_nb_comp ); more(); next() ) ; // (5) TYPE ( ignored ) getNextLine( ligne ); @@ -570,7 +580,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // set field names for ( i = 0; i < nb_objets_nommes; ++i ) { int fieldIndex = indices_objets_nommes[ i ]; - if ( fields[ fieldIndex - 1 ] ) + if ( fields[ fieldIndex - 1 ] ) fields[ fieldIndex - 1 ]->_name = objets_nommes[ i ]; } @@ -580,7 +590,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // FIELDS // ------------------------------------------------- - else if ( numero_pile == PILE_FIELD && readFields ) + else if ( numero_pile == PILE_FIELD && readFields ) // PILE NUMERO 39 { // REAL EXAMPLE @@ -620,8 +630,13 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields } next(); next(); next(); // skip (1) 2 6 int title_length = getInt(); // - if ( title_length ) + string description; + if ( title_length ) { getNextLine( ligne ); // (2) title + const int len = 72; // line length + // title is right justified + description = string(ligne + len - title_length, title_length); + } // look for a line starting with '-' : <reference to support> do { initIntReading( nb_sub * 9 ); @@ -693,9 +708,10 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields medi->fields.push_back( fields[ objet ] = fbase ); // medi->fields is a std::list } // store support id and nb components of a sub - if ( fbase ) + if ( fbase ) { fbase->_sub[ i_sub ].setData( nb_comp[ i_sub ], support_ids[ i_sub ]); - + fbase->_description = description; + } // loop on components: read values for ( int i_comp = 0; i_comp < nb_comp[ i_sub ]; ++i_comp ) { @@ -703,22 +719,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields initIntReading( 2 ); int nb_val_by_elem = getInt(); next(); int nb_values = getInt(); - if ( nb_val_by_elem != 1 ) { -#ifdef STOP_READING_UNSUP_DATA - INFOS("Error of reading field " << objet + 1 << ": nb of values by element " - << " != 1 : " << nb_val_by_elem << DUMP_LINE_NB ); - return false; -#else - if ( fbase ) { - if ( isReal ) delete fdouble; - else delete fint; - fields[ objet ] = fbase = 0; - medi->fields.pop_back(); - INFOS("Skip field " << objet + 1 << ": nb of values by element != 1 : " - << nb_val_by_elem << DUMP_LINE_NB); - } -#endif - } + fbase->_sub[ i_sub ]._nb_gauss[ i_comp ] = nb_val_by_elem; // (10) values nb_values *= nb_val_by_elem; if ( fbase ) { @@ -755,7 +756,7 @@ bool GIBI_MESH_RDONLY_DRIVER::readFile (_intermediateMED* medi, bool readFields // set field names for ( i = 0; i < nb_objets_nommes; ++i ) { int fieldIndex = indices_objets_nommes[ i ] - 1; - if ( fields[ fieldIndex ]) + if ( fields[ fieldIndex ]) fields[ fieldIndex ]->_name = objets_nommes[ i ]; } @@ -939,7 +940,11 @@ bool GIBI_MESH_RDONLY_DRIVER::getLine(char* & aLine) if (nBytesRest < GIBI_MaxOutputLen) { if (nBytesRest > 0) { - memcpy (_start, _ptr, nBytesRest); + //memcpy (_start, _ptr, nBytesRest); + char* tmpBuf = new char [nBytesRest]; + memcpy (tmpBuf, _ptr, nBytesRest); + memcpy (_start, tmpBuf, nBytesRest); + delete [] tmpBuf; } else nBytesRest = 0; _ptr = _start; @@ -1130,6 +1135,10 @@ static void getReverseVector (const medGeometryElement type, swapVec[5] = make_pair( 13, 14 ); swapVec[6] = make_pair( 17, 19 ); break; +// case MED_SEG3: no need to reverse edges +// swapVec.resize(1); +// swapVec[0] = make_pair( 1, 2 ); +// break; case MED_TRIA6: swapVec.resize(2); swapVec[0] = make_pair( 1, 2 ); @@ -1155,9 +1164,8 @@ static void reverse(const _maille & aMaille, const vector<pair<int,int> > & swap { _maille* ma = (_maille*) & aMaille; for ( int i = 0; i < swapVec.size(); ++i ) { - _maille::iter tmp = ma->sommets[ swapVec[i].first ]; - ma->sommets[ swapVec[i].first ] = ma->sommets[ swapVec[i].second ]; - ma->sommets[ swapVec[i].second ] = tmp; + std::swap( ma->sommets[ swapVec[i].first ], + ma->sommets[ swapVec[i].second ]); } if ( swapVec.empty() ) ma->reverse = true; @@ -1179,12 +1187,14 @@ static const int * getGibi2MedConnectivity( const medGeometryElement type ) static int tetra10[] = {0,2,4, 9, 1,3,5, 6,7,8}; static int quad8 [] = {0,2,4,6, 1,3,5,7}; static int tria6 [] = {0,2,4, 1,3,5}; + static int seg3 [] = {0,2,1}; if ( conn.empty() ) { conn.resize( MED_HEXA20 + 1, 0 ); conn[ MED_HEXA20 ] = hexa20; conn[ MED_PENTA15] = penta15; conn[ MED_PYRA13 ] = pyra13; conn[ MED_TETRA10] = tetra10; + conn[ MED_SEG3 ] = seg3; conn[ MED_TRIA6 ] = tria6; conn[ MED_QUAD8 ] = quad8; } @@ -1221,6 +1231,7 @@ static void orientElements( _intermediateMED& medi ) int type = -100; vector< pair<int,int> > swapVec; + bool isQuadratic = ( getGibi2MedConnectivity( medi.maillage.rbegin()->geometricType )); if ( elemIt->sommets[0]->second.coord.size() == 2 ) { // space dimension @@ -1232,7 +1243,8 @@ static void orientElements( _intermediateMED& medi ) if ( elemIt->dimension() == 2 ) { // fix connectivity of quadratic faces - fixConnectivity( *elemIt ); + if ( isQuadratic ) + fixConnectivity( *elemIt ); // look for index of the most left node int iLeft = 0, iNode, nbNodes = elemIt->sommets.size(); @@ -1276,13 +1288,20 @@ static void orientElements( _intermediateMED& medi ) } } } + else + { + // fix connectivity of quadratic edges + if ( isQuadratic ) + fixConnectivity( *elemIt ); + } } else { // -------------------------------------- // orient equally all connected 3D faces // -------------------------------------- - // quadratic faces will be reversed in the following fixConnectivity(); + // connectivity of quadratic faces will be fixed by fixConnectivity() + // in the next loop on elements // fill map of links and their faces set<const _maille*> faces; @@ -1299,7 +1318,7 @@ static void orientElements( _intermediateMED& medi ) continue; for(; maIt!=grp.mailles.end(); ++maIt) { if ( faces.insert( &(**maIt )).second ) { - for ( int j = 0; j < (*maIt)->sommets.size(); ++j ) + for ( int j = 0; j < (int)(*maIt)->sommets.size(); ++j ) linkFacesMap[ (*maIt)->link( j ) ].push_back( &(**maIt) ); fgm.insert( make_pair( &(**maIt), &grp )); } @@ -1332,7 +1351,7 @@ static void orientElements( _intermediateMED& medi ) faceQueue.pop(); // loop on links of <face> - for ( int i = 0; i < face->sommets.size(); ++i ) { + for ( int i = 0; i < (int)face->sommets.size(); ++i ) { _link link = face->link( i ); // find the neighbor faces lfIt = linkFacesMap.find( link ); @@ -1349,7 +1368,7 @@ static void orientElements( _intermediateMED& medi ) { const _maille* badFace = *fIt; // reverse and remove badFace from linkFacesMap - for ( int j = 0; j < badFace->sommets.size(); ++j ) { + for ( int j = 0; j < (int)badFace->sommets.size(); ++j ) { _link badlink = badFace->link( j ); if ( badlink == link ) continue; lfIt2 = linkFacesMap.find( badlink ); @@ -1409,7 +1428,8 @@ static void orientElements( _intermediateMED& medi ) for ( ; elemIt != medi.maillage.end(); elemIt++ ) { // GIBI connectivity -> MED one - fixConnectivity( *elemIt ); + if ( isQuadratic ) + fixConnectivity( *elemIt ); // reverse quadratic faces if ( elemIt->reverse ) { @@ -1652,19 +1672,22 @@ void GIBI_MESH_WRONLY_DRIVER::open() default: throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Bad file mode access ! " << aMode)); } - if (_gibi && + //change for windows compilation + if ( !_gibi || #ifdef WNT - _gibi.is_open() + !_gibi.is_open() #else - _gibi.rdbuf()->is_open() + !_gibi.rdbuf()->is_open() #endif ) - _status = MED_OPENED; - else { _status = MED_CLOSED; throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName)); } + else + { + _status = MED_OPENED; + } END_OF(LOC); } @@ -1816,7 +1839,7 @@ bool GIBI_MESH_WRONLY_DRIVER::addSupport( const SUPPORT * support ) nbElems = (*sIt)->getNumberOfElements( geomType ); ptrElemIDs = (*sIt)->getNumber( geomType ); } - if ( geomType == 0 ) + if ( geomType == 0 || ( entity == MED_NODE )) geomType = MED_POINT1; data.addTypeData( geomType, nbElems, ptrElemIDs, elemID1 ); @@ -1975,8 +1998,6 @@ void GIBI_MESH_WRONLY_DRIVER::writeElements (medGeometryElement geomType, // raise if not unique //======================================================================= -#define THROW_ON_BAD_NAME - void GIBI_MESH_WRONLY_DRIVER::addName(map<string,int>& nameMap, string& theName, int index, @@ -2442,6 +2463,17 @@ void GIBI_MED_RDONLY_DRIVER::read ( void ) throw (MEDEXCEPTION) list< FIELD_* >::iterator it = fields.begin(); for ( ; it != fields.end(); it++ ) { + int nbComponents = (*it)->getNumberOfComponents(); + if(nbComponents>0) { + UNIT* compoUnits = new UNIT[nbComponents]; + string* MEDcompoUnits = new string[nbComponents]; + for(int l = 0; l<nbComponents; l++) { + compoUnits[l] = UNIT("", ""); + MEDcompoUnits[l] = ""; + } + (*it)->setComponentsUnits(compoUnits); + (*it)->setMEDComponentsUnits(MEDcompoUnits); + } _med->addField( *it ); } } @@ -2492,36 +2524,70 @@ GENDRIVER * GIBI_MED_WRONLY_DRIVER::copy ( void ) const //======================================================================= template< class T, class INTERLACING_TAG> -static void writeDataSection (fstream& file, - FIELD<T, INTERLACING_TAG> * field, - int id1, - int id2) throw (MEDEXCEPTION) +static void writeDataSection (fstream& file, + FIELD<T, INTERLACING_TAG> * field, + const int id1, + const int id2) throw (MEDEXCEPTION) { const char * LOC="writeDataSection (.....) :"; BEGIN_OF(LOC); - int ld = field->getNumberOfComponents(); + int nbGauss, nbComp = field->getNumberOfComponents(); + + typedef typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,NoGauss>::Array ArrayNoGauss; + typedef typename MEDMEM_ArrayInterface<T,INTERLACING_TAG,Gauss>::Array ArrayGauss; + + MEDMEM_Array_ * array = field->getArray(); + ArrayNoGauss * arrayNoGauss = 0; + ArrayGauss * arrayGauss = 0; + + if ( !array ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field |"<< field->getName() + << "| not allocated")); -// FIELD<T>* f = dynamic_cast<FIELD<T>*>( field ); -// if (!f) return; -// MEDARRAY<T>* array = f->getvalue(); -// int ld = array->getLeadingValue(); - //SCRUTE( array->getLengthValue() ); + if ( array->getGaussPresence() ) { + arrayGauss = field->getArrayGauss(); + nbGauss = arrayGauss->getNbGauss( id1 ); + } + else { + arrayNoGauss = field->getArrayNoGauss(); + nbGauss = 1; + } - for ( int iComp = 0; iComp < ld; ++iComp ) + TFieldCounter fcount( file, 3 ); // 3 values on a line + +#ifdef CASTEM_FULL_INTERLACE + const int gauss_step = field->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ? nbComp : 1; +#endif + + for ( int iComp = 1; iComp <= nbComp; ++iComp ) { - file << setw(8) << 1 // nb scalar values by element - << setw(8) << ( id2 - id1 ) // total nb of scalar values - << setw(8) << 0 - << setw(8) << 0 << endl; + file << setw(8) << nbGauss // nb scalar values by element + << setw(8) << ( id2 - id1 ) // total nb of scalar values + << setw(8) << 0 + << setw(8) << 0 + << endl; // * 8003 FORMAT(1P,3E22.14) - int id = id1; - while ( id < id2 ) - { - for ( int i = 0; id < id2 && i < 3; ++i ) - file << setw(22) << field->getValueIJ( id++, iComp + 1); - file << endl; + if ( arrayNoGauss ) { + for (int id = id1; id < id2; id++, fcount++ ) + file << setw(22) << arrayNoGauss->getIJ( id, iComp ); + } + else { +#ifdef CASTEM_FULL_INTERLACE + for (int id = id1; id < id2; id++ ) { + const T* val = & arrayGauss->getIJK( id, iComp, 1 ); + const T* valEnd = val + nbGauss * gauss_step; + for ( ; val < valEnd; val += gauss_step, fcount++ ) + file << setw(22) << *val; + } +#else + for ( int iGauss = 1; iGauss <= nbGauss; ++iGauss ) { + for (int id = id1; id < id2; id++, fcount++ ) + file << setw(22) << arrayGauss->getIJK( id, iComp, iGauss ); + } +#endif } + fcount.stop(); } END_OF(LOC); } @@ -2559,7 +2625,7 @@ void GIBI_MED_WRONLY_DRIVER::write( void ) const throw (MEDEXCEPTION) for ( ; fIt != dtit.end(); fIt++ ) { FIELD_ * f = _med->getField( names[ iField ], fIt->dt, fIt->it ); - if ( f->getValueType() != MED_EN::MED_INT32 ) + if ( f->getValueType() != MED_EN::MED_REEL64 ) { MESSAGE("GIBI_MED_WRONLY_DRIVER::write( FIELD< int > ) not implemented"); continue; @@ -2609,10 +2675,13 @@ void GIBI_MED_WRONLY_DRIVER::write( void ) const throw (MEDEXCEPTION) if ( cur_nb_sub == nb_sub && itNbSub != nb_sub_list.end() ) { // start the next field writting nb_sub = *(itNbSub++); - gibi << setw(8) << nb_sub << " -1 6 72" << endl; - gibi << left; - gibi << setw(72) << " Field" << endl; - gibi << right; + string description = (*itF)->getDescription(); + gibi << setw(8) << nb_sub + << setw(8) << -1 + << setw(8) << 6 + << setw(8) << description.size() << endl; + if ( !description.empty() ) + gibi << setw(72) << description << endl; gibi << setw(72) << " " << endl; // Sub Components section @@ -2630,7 +2699,7 @@ void GIBI_MED_WRONLY_DRIVER::write( void ) const throw (MEDEXCEPTION) { ++cur_nb_sub; vals[0] = -idsize->first; // support id - for ( int i = 0; i < vals.size(); ++i, fcount++ ) + for ( int i = 0; i < (int)vals.size(); ++i, fcount++ ) gibi << setw(8) << vals[ i ]; } } @@ -2660,8 +2729,12 @@ void GIBI_MED_WRONLY_DRIVER::write( void ) const throw (MEDEXCEPTION) fcount.stop(); // component names gibi << left; - for ( fcount.init(8), iComp = 0; iComp < nbComp; ++iComp, fcount++ ) - gibi << " " << setw(8) << f->getComponentName( iComp + 1 ); + for ( fcount.init(8), iComp = 0; iComp < nbComp; ++iComp, fcount++ ) { + string compName = f->getComponentName( iComp + 1 ); + if ( compName.size() > 8 ) + compName = compName.substr(0, 8); + gibi << " " << setw(8) << compName; + } fcount.stop(); // component types for ( fcount.init(4), iComp = 0; iComp < nbComp; ++iComp, fcount++ ) @@ -2672,13 +2745,16 @@ void GIBI_MED_WRONLY_DRIVER::write( void ) const throw (MEDEXCEPTION) // Data section int id2 = id1 + idsize->second; - if (f->getGaussPresence() ) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " GibiDriver don't support Field with Gauss point" )); + // PAL11040 + //if (f->getGaussPresence() ) + //throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "GibiDriver don't support Field with Gauss point")); if ( f->getInterlacingType() == MED_NO_INTERLACE ) - writeDataSection( gibi, dynamic_cast<FIELD<double,NoInterlace>*>(f), id1, id2 ); + writeDataSection( gibi, static_cast<FIELD<double,NoInterlace > * >(f), id1, id2 ); + else if ( f->getInterlacingType() == MED_FULL_INTERLACE ) + writeDataSection( gibi, static_cast<FIELD<double,FullInterlace> * >(f), id1, id2 ); else - writeDataSection( gibi, dynamic_cast< FIELD<double,FullInterlace> * >(f), id1, id2 ); + writeDataSection( gibi, static_cast<FIELD<double,NoInterlaceByType> * >(f), id1, id2 ); id1 = id2; } diff --git a/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx b/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx index 9bc3ba44f..9176f39bf 100644 --- a/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_GibiMeshDriver.hxx @@ -20,6 +20,8 @@ #ifndef GIBI_MESH_DRIVER_HXX #define GIBI_MESH_DRIVER_HXX +#include <MEDMEM.hxx> + #include <string> #include <vector> #include <map> @@ -56,8 +58,8 @@ class FAMILY; class GROUP; class SUPPORT; class CONNECTIVITY; -class _intermediateMED; -class GIBI_MESH_DRIVER : public GENDRIVER +struct _intermediateMED; +class MEDMEM_EXPORT GIBI_MESH_DRIVER : public GENDRIVER { protected: @@ -66,8 +68,14 @@ protected: string _meshName; ///// + // This enumeration is used to substitude static const + // memers data causing link errors on VC7 compiler. + enum + { + nb_geometrie_gibi = 47 + }; // tableau de correspondance des types gĂƒÂ©omĂƒÂ©triques de CASTEM -> MED - static const size_t nb_geometrie_gibi=47; + //static const size_t nb_geometrie_gibi=47; static const MED_EN::medGeometryElement geomGIBItoMED[nb_geometrie_gibi]; ///// @@ -116,7 +124,7 @@ public : }; -class GIBI_MESH_RDONLY_DRIVER : public virtual GIBI_MESH_DRIVER +class MEDMEM_EXPORT GIBI_MESH_RDONLY_DRIVER : public virtual GIBI_MESH_DRIVER { public : @@ -205,7 +213,7 @@ private: */ -class GIBI_MESH_WRONLY_DRIVER : public virtual GIBI_MESH_DRIVER { +class MEDMEM_EXPORT GIBI_MESH_WRONLY_DRIVER : public virtual GIBI_MESH_DRIVER { public : @@ -272,8 +280,7 @@ public : int _nbElems; const int * _ptrElemIDs; // elem ids or int _elemID1; // first elem id if isOnAllElements() - typeData(): _nbElems(0), _ptrElemIDs(NULL), _elemID1(0) {} - typeData( int nbElems, const int * ptrElemIDs, int elemID1 ) + typeData( int nbElems=0, const int * ptrElemIDs=NULL, int elemID1=0 ) : _nbElems(nbElems), _ptrElemIDs(ptrElemIDs), _elemID1(elemID1) {} }; struct supportData @@ -310,7 +317,7 @@ public : */ -class GIBI_MESH_RDWR_DRIVER : public GIBI_MESH_RDONLY_DRIVER, public GIBI_MESH_WRONLY_DRIVER { +class MEDMEM_EXPORT GIBI_MESH_RDWR_DRIVER : public GIBI_MESH_RDONLY_DRIVER, public GIBI_MESH_WRONLY_DRIVER { public : @@ -349,7 +356,7 @@ public : }; -class GIBI_MED_RDONLY_DRIVER : public GIBI_MESH_RDONLY_DRIVER { +class MEDMEM_EXPORT GIBI_MED_RDONLY_DRIVER : public GIBI_MESH_RDONLY_DRIVER { MED * _med; @@ -392,7 +399,7 @@ private: */ -class GIBI_MED_WRONLY_DRIVER : public GIBI_MESH_WRONLY_DRIVER { +class MEDMEM_EXPORT GIBI_MED_WRONLY_DRIVER : public GIBI_MESH_WRONLY_DRIVER { MED * _med; diff --git a/src/MEDMEM/MEDMEM_Grid.cxx b/src/MEDMEM/MEDMEM_Grid.cxx index 0d1f5b9ef..0119aa1c9 100644 --- a/src/MEDMEM/MEDMEM_Grid.cxx +++ b/src/MEDMEM/MEDMEM_Grid.cxx @@ -31,6 +31,7 @@ #include "MEDMEM_Grid.hxx" #include "MEDMEM_CellModel.hxx" #include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_DriverFactory.hxx" using namespace std; using namespace MEDMEM; @@ -50,10 +51,16 @@ GRID::GRID() { ////function : GRID ////purpose : array constructor ////======================================================================= -GRID::GRID(const std::vector<std::vector<double> >& xyz_array,const std::vector<std::string>& coord_name, - const std::vector<std::string>& coord_unit, const med_grid_type type) : _gridType(type) +GRID::GRID(const std::vector<std::vector<double> >& xyz_array, + const std::vector<std::string>& coord_name, + const std::vector<std::string>& coord_unit, + const med_grid_type type) : _gridType(type) { + init(); // PAL 12136 + _is_default_gridType = false; + _spaceDimension = xyz_array.size(); + _meshDimension = _spaceDimension; // PAL14482 // compute & set _numberOfNodes int NumberOfNodes=1 ; @@ -104,6 +111,7 @@ GRID::GRID(const med_grid_type type) { init(); _gridType = type; + _is_default_gridType = false; MESSAGE("A TYPED GRID CREATED"); } @@ -136,7 +144,8 @@ GRID::~GRID() { void GRID::init() { _gridType = MED_CARTESIAN; - + _is_default_gridType = true; + _iArray = _jArray = _kArray = (double* ) NULL; _iArrayLength = _jArrayLength = _kArrayLength = 0; @@ -168,35 +177,22 @@ GRID & GRID::operator=(const GRID & otherGrid) //======================================================================= GRID::GRID(driverTypes driverType, const string & fileName, - const string & driverName) : MESH(driverType, fileName, driverName) + const string & driverName)// : MESH(driverType, fileName, driverName) { const char * LOC ="GRID::GRID(driverTypes , const string & , const string &) : "; BEGIN_OF(LOC); -// int current; - -// init(); -// MESH(driverType,fileName,driverName); - -// current = addDriver(driverType,fileName,driverName); - -// switch(_drivers[current]->getAccessMode() ) { -// case MED_RDONLY : -// MESSAGE(LOC << "driverType must have a MED_RDWR accessMode"); -// rmDriver(current); -// break; -// default: {} -// } -// _drivers[current]->open(); -// _drivers[current]->read(); -// _drivers[current]->close(); - -// // fill some fields of MESH -// fillMeshAfterRead(); + init(); + GENDRIVER *myDriver=DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this,driverName,MED_LECT); + int current = addDriver(*myDriver); + delete myDriver; + _drivers[current]->open(); + _drivers[current]->read(); + _drivers[current]->close(); fillMeshAfterRead(); - + END_OF(LOC); }; diff --git a/src/MEDMEM/MEDMEM_Grid.hxx b/src/MEDMEM/MEDMEM_Grid.hxx index ac4837782..fd79c098a 100644 --- a/src/MEDMEM/MEDMEM_Grid.hxx +++ b/src/MEDMEM/MEDMEM_Grid.hxx @@ -29,12 +29,14 @@ #ifndef MEDMEM_Grid_HeaderFile #define MEDMEM_Grid_HeaderFile +#include <MEDMEM.hxx> + #include "MEDMEM_Mesh.hxx" // class containing structured mesh data namespace MEDMEM { -class GRID: public MESH +class MEDMEM_EXPORT GRID: public MESH { protected: //-----------------------// @@ -61,6 +63,9 @@ class GRID: public MESH bool _is_coordinates_filled; bool _is_connectivity_filled; + // 4. is _gridType a true value or just a default one + bool _is_default_gridType; + //-----------------------// // Protected Methods //-----------------------// @@ -245,6 +250,9 @@ class GRID: public MESH inline bool existConnectivity(MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + inline bool existConnectivityWithPoly(MED_EN::medConnectivity ConnectivityType, + MED_EN::medEntityMesh Entity) const; + inline MED_EN::medGeometryElement getElementType(MED_EN::medEntityMesh Entity, int Number) const; @@ -418,11 +426,26 @@ inline int GRID::getNumberOfElements(MED_EN::medEntityMesh entity, MED_EN::medGe // Cas oĂ¹ le nombre d'Ă©lĂ©ments n'est pas nul if (entity==MED_EN::MED_FACE && (Type==MED_EN::MED_QUAD4 || Type==MED_EN::MED_ALL_ELEMENTS) && _spaceDimension>2) + if ( _meshDimension == 2 ) numberOfElements=(_iArrayLength-1)*(_jArrayLength-1); - + else + numberOfElements= + (_iArrayLength-1)*(_jArrayLength-1)*_kArrayLength + + (_jArrayLength-1)*(_kArrayLength-1)*_iArrayLength + + (_iArrayLength-1)*(_kArrayLength-1)*_jArrayLength; + else if (entity==MED_EN::MED_EDGE && (Type==MED_EN::MED_SEG2 || Type==MED_EN::MED_ALL_ELEMENTS) && _spaceDimension>1) + if ( _meshDimension == 1 ) numberOfElements=_iArrayLength-1; - + else if ( _meshDimension == 2 ) + numberOfElements= + (_iArrayLength-1)*_jArrayLength + (_jArrayLength-1)*_iArrayLength; + else + numberOfElements= + (_iArrayLength-1)*_jArrayLength*_kArrayLength + + (_jArrayLength-1)*_kArrayLength*_iArrayLength + + (_kArrayLength-1)*_iArrayLength*_jArrayLength; + else if (entity==MED_EN::MED_NODE && (Type==MED_EN::MED_NONE || Type==MED_EN::MED_ALL_ELEMENTS) && _spaceDimension>0) numberOfElements=_numberOfNodes; @@ -460,6 +483,15 @@ inline bool GRID::existConnectivity(MED_EN::medConnectivity connectivityType, ME return _connectivity->existConnectivity(connectivityType,entity); } +/*! + Same as the previous + */ +inline bool GRID::existConnectivityWithPoly(MED_EN::medConnectivity ConnectivityType, + MED_EN::medEntityMesh Entity) const +{ + return existConnectivity(ConnectivityType,Entity); +} + /*! Return the geometric type of global element Number of entity Entity. diff --git a/src/MEDMEM/MEDMEM_Group.hxx b/src/MEDMEM/MEDMEM_Group.hxx index 04a73eaf7..4832d3d5e 100644 --- a/src/MEDMEM/MEDMEM_Group.hxx +++ b/src/MEDMEM/MEDMEM_Group.hxx @@ -25,6 +25,8 @@ #ifndef GROUP_HXX #define GROUP_HXX +#include <MEDMEM.hxx> + #include <vector> #include <list> #include "MEDMEM_Family.hxx" @@ -39,8 +41,11 @@ */ namespace MEDMEM { -class FAMILY; -class GROUP : virtual public SUPPORT + class FAMILY; + class GROUP; + ostream & operator<<(ostream &os, GROUP &my) ; + +class MEDMEM_EXPORT GROUP : virtual public SUPPORT { protected : /*! diff --git a/src/MEDMEM/MEDMEM_IndexCheckingPolicy.hxx b/src/MEDMEM/MEDMEM_IndexCheckingPolicy.hxx index 8ec18f91e..98761aed4 100644 --- a/src/MEDMEM/MEDMEM_IndexCheckingPolicy.hxx +++ b/src/MEDMEM/MEDMEM_IndexCheckingPolicy.hxx @@ -19,12 +19,14 @@ #ifndef MEDMEM_INDEX_CHECKING_POLICY_HXX #define MEDMEM_INDEX_CHECKING_POLICY_HXX +#include <MEDMEM.hxx> + #include "MEDMEM_Exception.hxx" #include "MEDMEM_STRING.hxx" namespace MEDMEM { -class IndexCheckPolicy { +class MEDMEM_EXPORT IndexCheckPolicy { public : inline void checkMoreThanZero(const std::string & classname, int index) const { if (index <= 0) @@ -48,7 +50,7 @@ public : }; -class NoIndexCheckPolicy { +class MEDMEM_EXPORT NoIndexCheckPolicy { public : inline void checkMoreThanZero(const string &classname, int index) const {} inline void checkLessOrEqualThan(const std::string & classname, int max, int index) const {} diff --git a/src/MEDMEM/MEDMEM_Init.cxx b/src/MEDMEM/MEDMEM_Init.cxx index 95b3a3867..aca96a49a 100644 --- a/src/MEDMEM/MEDMEM_Init.cxx +++ b/src/MEDMEM/MEDMEM_Init.cxx @@ -46,7 +46,11 @@ MEDMEM::INIT::INIT() if (traceKind == NULL) { +#ifndef WNT setenv("SALOME_trace","local",1); +#else + _putenv("SALOME_trace=%TEMP%\\local"); +#endif traceKind = getenv("SALOME_trace"); assert(traceKind); } diff --git a/src/MEDMEM/MEDMEM_InterlacingPolicy.hxx b/src/MEDMEM/MEDMEM_InterlacingPolicy.hxx index 8b4ba070e..a411955a1 100644 --- a/src/MEDMEM/MEDMEM_InterlacingPolicy.hxx +++ b/src/MEDMEM/MEDMEM_InterlacingPolicy.hxx @@ -19,6 +19,8 @@ #ifndef MEDMEM_INTERLACING_HXX #define MEDMEM_INTERLACING_HXX +#include <MEDMEM.hxx> + #include <iostream> #include "MEDMEM_Utilities.hxx" @@ -27,7 +29,7 @@ namespace MEDMEM { -class InterlacingPolicy { +class MEDMEM_EXPORT InterlacingPolicy { protected: ~InterlacingPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique public : @@ -79,7 +81,7 @@ public : }; -class FullInterlaceNoGaussPolicy : public InterlacingPolicy { +class MEDMEM_EXPORT FullInterlaceNoGaussPolicy : public InterlacingPolicy { protected: ~FullInterlaceNoGaussPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique @@ -105,7 +107,7 @@ public : }; -class NoInterlaceNoGaussPolicy : public InterlacingPolicy { +class MEDMEM_EXPORT NoInterlaceNoGaussPolicy : public InterlacingPolicy { protected: ~NoInterlaceNoGaussPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique @@ -132,7 +134,128 @@ public : }; -class FullInterlaceGaussPolicy : public InterlacingPolicy { +class MEDMEM_EXPORT NoInterlaceByTypeNoGaussPolicy : public InterlacingPolicy { + +protected: + ~NoInterlaceByTypeNoGaussPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique + + PointerOf<int> _T; //!< type of element + PointerOf<int> _G; //!< where type begin + int _nbtypegeo; + PointerOf<int> _nbelegeoc; + +public : + + NoInterlaceByTypeNoGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) + { + } + + NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim):InterlacingPolicy() + { + // constructor is incoorect for this type of interlace + throw MEDEXCEPTION(LOCALIZED("Wrong constructor of NoInterlaceByTypeNoGaussPolicy ")); + } + + NoInterlaceByTypeNoGaussPolicy(int nbelem, int dim, int nbtypegeo, + const int * const nbelgeoc) : + InterlacingPolicy(nbelem, dim, dim*nbelem,MED_EN::MED_NO_INTERLACE_BY_TYPE), + _nbtypegeo(nbtypegeo) + { + _nbelegeoc.set(_nbtypegeo+1,nbelgeoc); + _G.set(nbtypegeo+1); + _T.set(nbelem+1); + int elemno = 1; + int cumul = 0; + + for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) { + int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1]; + for (int i=0; i < nbelcurtype; i++ ) { + _T[ elemno ] = ntyp; + elemno++; + }; + _G[ ntyp ] = cumul; + cumul += nbelcurtype*_dim; +#ifdef ARRAY_DEBUG + std::cout << "Valeur de cumul " << cumul << std::endl; +#endif + }; + + _arraySize = cumul; + +#ifdef ARRAY_DEBUG + for (int i =0; i< nbelem+1; i++ ) + std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl; +#endif + } + + NoInterlaceByTypeNoGaussPolicy(const NoInterlaceByTypeNoGaussPolicy & policy, + bool shallowcopie=true) + : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo) + { + //Seuls les tableaux de grande taille sont recopiĂ©s superficiellement + if(shallowcopie) + { + this->_G.set(policy._G); + this->_T.set(policy._T); + } + else + { + this->_G.set(_nbtypegeo+1,policy._G); + this->_T.set(_nbelem+1,policy._T); + } + + // Tableaux toujours recopiĂ©s par recopie profonde + this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc); + } + + NoInterlaceByTypeNoGaussPolicy & operator=(const NoInterlaceByTypeNoGaussPolicy & policy) { + if ( this == &policy) return *this; + + BEGIN_OF("NoInterlaceNoGaussPolicy operator ="); + InterlacingPolicy::operator=(policy); + this->_G.set(policy._G); + this->_T.set(policy._T); + + // Tableaux toujours recopiĂ©s par recopie profonde + this->_nbtypegeo=policy._nbtypegeo; + this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc); + + return *this; + } + inline int getIndex(int t) const { + return _G[t]; + } + + inline int getIndex(int i,int j) const { + int t = _T[i]; + return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t ); + } + + inline int getIndex(int i,int j,int k) const { + return getIndex(i,j); + } + + inline int getIndexByType(int i,int j,int t) const { + return _G[t] + i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1]); + } + + inline int getIndexByType(int i,int j,int k,int t) const { + return getIndexByType( i, j, t ); + } + + inline int getLengthOfType(int t) const { + return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim; + } + + inline int getNbGauss(int i) const { return 1; } + + inline int getNbGeoType() const {return _nbtypegeo;} + + inline const int * const getNbElemGeoC() const {return _nbelegeoc;} + +}; + +class MEDMEM_EXPORT FullInterlaceGaussPolicy : public InterlacingPolicy { protected: ~FullInterlaceGaussPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique public : @@ -219,7 +342,7 @@ public : } inline int getIndex(int i,int j ) const { - return _G[i-1]-1 + (j-1)*_dim ; + return _G[i-1]-1 + (j-1); } inline int getIndex(int i,int j, int k ) const { @@ -238,7 +361,7 @@ public : }; -class NoInterlaceGaussPolicy : public InterlacingPolicy { +class MEDMEM_EXPORT NoInterlaceGaussPolicy : public InterlacingPolicy { protected: ~NoInterlaceGaussPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique @@ -348,6 +471,127 @@ public : }; +class MEDMEM_EXPORT NoInterlaceByTypeGaussPolicy : public InterlacingPolicy { + +protected: + ~NoInterlaceByTypeGaussPolicy() {} //pour Ă©viter qu'un utilisateur cast la class array en politique + + PointerOf<int> _T; //!< type of element + PointerOf<int> _G; //!< where type begin + int _nbtypegeo; + PointerOf<int> _nbelegeoc; + PointerOf<int> _nbgaussgeo; + +public : + + NoInterlaceByTypeGaussPolicy():InterlacingPolicy(),_nbtypegeo(-1) { + InterlacingPolicy::_gaussPresence=true; + } + + NoInterlaceByTypeGaussPolicy(int nbelem, int dim, int nbtypegeo, + const int * const nbelgeoc, const int * const nbgaussgeo) + : InterlacingPolicy(nbelem, dim, -1, MED_EN::MED_NO_INTERLACE_BY_TYPE),_nbtypegeo(nbtypegeo) { + + InterlacingPolicy::_gaussPresence=true; + + _nbelegeoc.set(_nbtypegeo+1,nbelgeoc); + _nbgaussgeo.set(_nbtypegeo+1,nbgaussgeo); + _G.set(_nbtypegeo+1); + _T.set(nbelem+1); + int elemno = 1; + int cumul = 0; + + for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) { + int nbelcurtype = nbelgeoc[ntyp]-nbelgeoc[ntyp-1]; + for (int i=0; i < nbelcurtype; i++ ) { + _T[ elemno ] = ntyp; + elemno++; + }; + _G[ ntyp ] = cumul; + cumul += nbelcurtype * _dim * nbgaussgeo[ntyp]; +#ifdef ARRAY_DEBUG + std::cout << "Valeur de cumul " << cumul << std::endl; +#endif + }; + + _arraySize = cumul; + +#ifdef ARRAY_DEBUG + for (int i =0; i< nbelem+1; i++ ) + std::cout << "Valeur de _T["<<i<<"] = "<<_T[i] << std::endl; +#endif + } + + + NoInterlaceByTypeGaussPolicy(const NoInterlaceByTypeGaussPolicy & policy, + bool shallowcopie=true) + : InterlacingPolicy(policy),_nbtypegeo(policy._nbtypegeo) + { + //Seuls les tableaux de grande taille sont recopiĂ©s superficiellement + if(shallowcopie) { + this->_G.set(policy._G); + this->_T.set(policy._T); + } else { + this->_G.set(_nbtypegeo+1,policy._G); + this->_T.set(_nbelem+1,policy._T); + } + // Tableaux toujours recopiĂ©s par recopie profonde + this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc); + this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo); + } + + NoInterlaceByTypeGaussPolicy & operator=(const NoInterlaceByTypeGaussPolicy & policy) { + if ( this == &policy) return *this; + + BEGIN_OF("NoInterlaceGaussPolicy operator ="); + InterlacingPolicy::operator=(policy); + this->_G.set(policy._G); + this->_T.set(policy._T); + + // Tableaux toujours recopiĂ©s par recopie profonde + this->_nbtypegeo=policy._nbtypegeo; + this->_nbelegeoc.set(_nbtypegeo+1,policy._nbelegeoc); + this->_nbgaussgeo.set(_nbtypegeo+1,policy._nbgaussgeo); + + return *this; + } + + inline int getIndex(int t) const { + return _G[t]; + } + inline int getIndex(int i,int j ) const { + int t = _T[i]; + return getIndexByType( i-(_nbelegeoc[t-1]-_nbelegeoc[0]), j, t ); + } + + inline int getIndex(int i,int j, int k ) const { + return getIndex( i, j ) + (k-1); + } + + inline int getIndexByType(int i,int j,int t) const { + return _G[t] + (i-1 + (j-1)*(_nbelegeoc[t]-_nbelegeoc[t-1])) * _nbgaussgeo[t]; + } + + inline int getIndexByType(int i,int j,int k,int t) const { + return getIndexByType( i,j,t ) + (k-1); + } + + inline int getNbGauss(int i) const { return _nbgaussgeo[ _T[i] ]; } + + inline int getNbGaussByType(int t) const { return _nbgaussgeo[ t ]; } + + inline int getNbGeoType() const {return _nbtypegeo;} + + inline const int * const getNbElemGeoC() const {return _nbelegeoc;} + + inline const int * const getNbGaussGeo() const {return _nbgaussgeo;} + + inline int getLengthOfType(int t) const { + return (_nbelegeoc[t]-_nbelegeoc[t-1]) * _dim * _nbgaussgeo[t]; + } + +}; + } //END NAMESPACE #endif diff --git a/src/MEDMEM/MEDMEM_InterlacingTraits.hxx b/src/MEDMEM/MEDMEM_InterlacingTraits.hxx index 002896d91..3d1cb2a5d 100644 --- a/src/MEDMEM/MEDMEM_InterlacingTraits.hxx +++ b/src/MEDMEM/MEDMEM_InterlacingTraits.hxx @@ -55,6 +55,18 @@ struct MEDMEM_InterlacingTraits< NoInterlace, NoGauss > typedef NoInterlaceNoGaussPolicy Type; }; +template <> +struct MEDMEM_InterlacingTraits< NoInterlaceByType, Gauss > +{ + typedef NoInterlaceByTypeGaussPolicy Type; +}; + +template <> +struct MEDMEM_InterlacingTraits< NoInterlaceByType, NoGauss > +{ + typedef NoInterlaceByTypeNoGaussPolicy Type; +}; + } // END NAMESPACE #endif diff --git a/src/MEDMEM/MEDMEM_MEDMEMchampLire.cxx b/src/MEDMEM/MEDMEM_MEDMEMchampLire.cxx index 40ecb817b..785fbe3bf 100644 --- a/src/MEDMEM/MEDMEM_MEDMEMchampLire.cxx +++ b/src/MEDMEM/MEDMEM_MEDMEMchampLire.cxx @@ -22,7 +22,7 @@ * on intègre la correction ici. */ -namespace med_2_2 { +namespace med_2_3 { extern "C" { # define ICI { \ diff --git a/src/MEDMEM/MEDMEM_MEDMEMchampLire.hxx b/src/MEDMEM/MEDMEM_MEDMEMchampLire.hxx index 9f51d99c4..ed6c7c93f 100644 --- a/src/MEDMEM/MEDMEM_MEDMEMchampLire.hxx +++ b/src/MEDMEM/MEDMEM_MEDMEMchampLire.hxx @@ -16,13 +16,16 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef MEDMEM_MEDMEM_CHAMPLIRE_HXX -#define MEDMEM_MEDMEM_CHAMPLIRE_HXX +#ifndef MEDMEM_MEDMEMCHAMPLIRE_HXX +#define MEDMEM_MEDMEMCHAMPLIRE_HXX + +#include "MEDMEM.hxx" + /* * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier * on intègre la correction ici. */ -namespace med_2_2 { +namespace med_2_3 { extern "C" { # define __UTILITES_H__ @@ -32,7 +35,7 @@ namespace med_2_2 { #include <string.h> #include <stdlib.h> -med_err +MEDMEM_EXPORT med_err MEDMEMchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switch interlace,med_int numco, char * locname, char *profil, med_mode_profil pflmod, med_entite_maillage type_ent, med_geometrie_element type_geo, diff --git a/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.cxx b/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.cxx index 704536366..280b87c9e 100644 --- a/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.cxx +++ b/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.cxx @@ -22,7 +22,7 @@ * on intègre la correction ici. */ -namespace med_2_2 { +namespace med_2_3 { extern "C" { # define ICI {\ fflush(stdout);\ @@ -117,7 +117,8 @@ namespace med_2_2 { * Sinon => erreur */ if ((chid = _MEDdatagroupOuvrir(gid,locname)) >= 0) { - if ( MED_MODE_ACCES != MED_LECTURE_ECRITURE ) { + if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE ) + { MESSAGE("Le nom de localisation existe dĂ©jĂ  : "); SSCRUTE(locname); goto ERROR; } diff --git a/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.hxx b/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.hxx index c64adf8e2..74fbf06e5 100644 --- a/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.hxx +++ b/src/MEDMEM/MEDMEM_MEDMEMgaussEcr.hxx @@ -16,13 +16,16 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef MEDMEM_MEDMEM_GAUSSECR_HXX -#define MEDMEM_MEDMEM_GAUSSECR_HXX +#ifndef MEDMEM_MEDMEMGAUSSECR_HXX +#define MEDMEM_MEDMEMGAUSSECR_HXX + +#include "MEDMEM.hxx" + /* * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier * on intègre la correction ici. */ -namespace med_2_2 { +namespace med_2_3 { extern "C" { # define __UTILITES_H__ @@ -32,7 +35,7 @@ namespace med_2_2 { #include <string.h> #include <stdlib.h> -med_err +MEDMEM_EXPORT med_err MEDMEMgaussEcr(med_idt fid, med_geometrie_element type_geo, med_float *refcoo, med_mode_switch mode_coo, med_int ngauss, med_float *gscoo, med_float * wg, char * locname ); diff --git a/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.cxx b/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.cxx index 37adbe0ec..1a6bfb887 100644 --- a/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.cxx +++ b/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.cxx @@ -22,7 +22,7 @@ * on intègre la correction ici. */ -namespace med_2_2 { +namespace med_2_3 { extern "C" { # define ICI { \ @@ -103,7 +103,8 @@ namespace med_2_2 { * Sinon => erreur */ if ((chid = _MEDdatagroupOuvrir(gid,profilname)) >= 0) { - if ( MED_MODE_ACCES != MED_LECTURE_ECRITURE ) { + if ( false )//MED_MODE_ACCES != MED_LECTURE_ECRITURE ) + { MESSAGE("Le profil existe dĂ©jĂ  : "); SSCRUTE(profilname); goto ERROR; } diff --git a/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.hxx b/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.hxx index fae4d74ee..d8e13630b 100644 --- a/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.hxx +++ b/src/MEDMEM/MEDMEM_MEDMEMprofilEcr.hxx @@ -16,13 +16,16 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef MEDMEM_MEDMEM_PROFILECR_HXX -#define MEDMEM_MEDMEM_PROFILECR_HXX +#ifndef MEDMEM_MEDMEMPROFILECR_HXX +#define MEDMEM_MEDMEMPROFILECR_HXX + +#include "MEDMEM.hxx" + /* * En attendant une correction de la gestion du mode d'accès au fichier dans MEDfichier * on intègre la correction ici. */ -namespace med_2_2 { +namespace med_2_3 { extern "C" { # define __UTILITES_H__ @@ -32,7 +35,7 @@ namespace med_2_2 { #include <string.h> #include <stdlib.h> - med_err + MEDMEM_EXPORT med_err MEDMEMprofilEcr(med_idt fid,med_int *pflval,med_int n,char *profilname); } diff --git a/src/MEDMEM/MEDMEM_Med.cxx b/src/MEDMEM/MEDMEM_Med.cxx index 1440b63d8..8476aa2a1 100644 --- a/src/MEDMEM/MEDMEM_Med.cxx +++ b/src/MEDMEM/MEDMEM_Med.cxx @@ -390,17 +390,7 @@ void MED::getMeshNames ( string * meshNames ) const { const char * LOC = "MED::getMeshNames ( string * ) const : "; BEGIN_OF(LOC); - unsigned int meshNamesSize; - - if ( ( meshNamesSize = sizeof(meshNames) / sizeof(string *) ) - != _meshes.size() ) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "Size of parameter meshNames is |" - << meshNamesSize << "| and should be |" - << _meshes.size() << "| and should be |" - ) - ); - + // REM : ALLOCATION D'UN TABLEAU DE POINTEURS SUR STRING FAITE PAR LE CLIENT map<MESH_NAME_,MESH*>::const_iterator currentMesh; // ??ITERATEUR CONST SUR UN OBJET NON CONST ?? @@ -483,21 +473,21 @@ MESH * MED::getMesh (const FIELD_ * const field ) const << "There is no known mesh associated with |" << field << "| pointer" ) - ); - + ); + string meshName = (*itMeshName).second; map<MESH_NAME_,MESH*>::const_iterator itMeshes = _meshes.find(meshName); if ( itMeshes == _meshes.end() ) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "There is no known mesh named |" - << meshName << " while it's associated with the found field |" + << meshName << " while it's associated with the found field |" << field << "| pointer" ) - ); - - return (*itMeshes).second; - + ); + END_OF(LOC); + + return (*itMeshes).second; }; @@ -723,7 +713,9 @@ SUPPORT * MED::getSupport (const string & meshName,MED_EN::medEntityMesh entity BEGIN_OF(LOC); int index = 0; - for (map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh=_support.begin(); const_itSupportOnMesh != _support.end(); + map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh; + + for (const_itSupportOnMesh=_support.begin(); const_itSupportOnMesh != _support.end(); const_itSupportOnMesh++ ) { map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ; @@ -733,7 +725,7 @@ SUPPORT * MED::getSupport (const string & meshName,MED_EN::medEntityMesh entity MESSAGE(LOC << "In this MED object there is(are) " << index << " support(s):"); - for (map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh=_support.begin();const_itSupportOnMesh != _support.end(); const_itSupportOnMesh++ ) + for (const_itSupportOnMesh=_support.begin();const_itSupportOnMesh != _support.end(); const_itSupportOnMesh++ ) { map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator const_itSupport ; for (const_itSupport=(*const_itSupportOnMesh).second.begin(); @@ -743,8 +735,7 @@ SUPPORT * MED::getSupport (const string & meshName,MED_EN::medEntityMesh entity } } - - map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::const_iterator const_itSupportOnMesh = _support.find(meshName) ; + const_itSupportOnMesh = _support.find(meshName) ; if ( const_itSupportOnMesh == _support.end() ) throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) @@ -786,24 +777,44 @@ SUPPORT * MED::getSupport (const string & meshName,MED_EN::medEntityMesh entity */ void MED::updateSupport () { - const char * LOC = "MED::updateSupport () : "; BEGIN_OF(LOC); map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> >::iterator itSupportOnMesh ; for ( itSupportOnMesh=_support.begin();itSupportOnMesh != _support.end(); itSupportOnMesh++ ) { + map<MED_EN::medEntityMesh,SUPPORT *>& anEntity2Support = (*itSupportOnMesh).second; + map<MED_EN::medEntityMesh,SUPPORT *> anEntity2SupportTmp; map<MED_EN::medEntityMesh,SUPPORT *>::iterator itSupport ; - for ( itSupport=(*itSupportOnMesh).second.begin();itSupport!=(*itSupportOnMesh).second.end();itSupport++) + for ( itSupport=anEntity2Support.begin();itSupport!=anEntity2Support.end();itSupport++) + { + MED_EN::medEntityMesh aKey = (*itSupport).first; + SUPPORT* aData = (*itSupport).second; try { - (*itSupport).second->update() ; + aData->update() ; + anEntity2SupportTmp[aKey] = aData; } catch (MEDEXCEPTION & ex) { // entity not defined in mesh -> we remove support on it ! MESSAGE(LOC<<ex.what()); delete (*itSupport).second ; - (*itSupportOnMesh).second.erase(itSupport) ; // that's rigth ???? - itSupport-- ; + //(*itSupportOnMesh).second.erase(itSupport) ; // that's right ???? + //itSupport-- ; + map<MED_EN::medEntityMesh,SUPPORT *>::iterator itSupportCurr = itSupport; + itSupport--; // decrement before erase() + (*itSupportOnMesh).second.erase(itSupportCurr); } + } + + // some entities has not defined in mesh -> we should remove their supports! + anEntity2Support.swap( anEntity2SupportTmp ); + + for ( itSupport=anEntity2SupportTmp.begin();itSupport!=anEntity2SupportTmp.end();itSupport++) + { + MED_EN::medEntityMesh aKey = (*itSupport).first; + SUPPORT* aData = (*itSupport).second; + if( anEntity2Support.find( aKey ) == anEntity2Support.end() ) + delete aData; + } } END_OF(LOC); diff --git a/src/MEDMEM/MEDMEM_Med.hxx b/src/MEDMEM/MEDMEM_Med.hxx index bae0e5b99..b7251676a 100644 --- a/src/MEDMEM/MEDMEM_Med.hxx +++ b/src/MEDMEM/MEDMEM_Med.hxx @@ -20,6 +20,8 @@ # ifndef MED_HXX # define MED_HXX +#include <MEDMEM.hxx> + // STL # include <string> # include <map> @@ -40,7 +42,7 @@ class SUPPORT ; typedef string MESH_NAME_; typedef string FIELD_NAME_; typedef struct { int dt; int it; } DT_IT_; -struct LT_DT_IT_ +struct MEDMEM_EXPORT LT_DT_IT_ { bool operator() (const DT_IT_ &p1, const DT_IT_ &p2) const { @@ -65,7 +67,7 @@ typedef map<DT_IT_, FIELD_*, LT_DT_IT_ > MAP_DT_IT_; */ -class MED +class MEDMEM_EXPORT MED { // Add your personnal driver line (step 2) friend class MED_MED_RDONLY_DRIVER21; diff --git a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx index 70410e3bb..c9ef5b812 100644 --- a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx @@ -284,11 +284,13 @@ public : MED_FIELD_RDONLY_DRIVER(const MED_FIELD_RDONLY_DRIVER & fieldDriver):IMED_FIELD_RDONLY_DRIVER<T>(fieldDriver) { _concreteFieldDrv = fieldDriver._concreteFieldDrv->copy(); } virtual ~MED_FIELD_RDONLY_DRIVER() { if (_concreteFieldDrv) delete _concreteFieldDrv; } virtual void read ( void ) throw (MEDEXCEPTION) { _concreteFieldDrv->read(); } + virtual MED_EN::med_mode_acces getAccessMode() const { return _concreteFieldDrv->getAccessMode(); } virtual void write( void ) const throw (MEDEXCEPTION) { _concreteFieldDrv->write(); } virtual void open() throw (MEDEXCEPTION) { _concreteFieldDrv->open(); } virtual void close() { _concreteFieldDrv->close(); } virtual void setFieldName(const string & fieldName) { _concreteFieldDrv->setFieldName(fieldName); } virtual string getFieldName() const { return MED_FIELD_DRIVER<T>::getFieldName(); } + private: virtual GENDRIVER * copy ( void ) const { return new MED_FIELD_RDONLY_DRIVER<T>(*this); } protected: @@ -306,6 +308,7 @@ public : MED_FIELD_WRONLY_DRIVER(const MED_FIELD_WRONLY_DRIVER & fieldDriver):IMED_FIELD_WRONLY_DRIVER<T>(fieldDriver) { _concreteFieldDrv = fieldDriver._concreteFieldDrv->copy(); } virtual ~MED_FIELD_WRONLY_DRIVER() { if (_concreteFieldDrv) delete _concreteFieldDrv;} virtual void read ( void ) throw (MEDEXCEPTION) { _concreteFieldDrv->read(); } + virtual MED_EN::med_mode_acces getAccessMode() const { return _concreteFieldDrv->getAccessMode(); } virtual void write( void ) const throw (MEDEXCEPTION) { _concreteFieldDrv->write(); } virtual void open() throw (MEDEXCEPTION) { _concreteFieldDrv->open(); } virtual void close() { _concreteFieldDrv->close(); } @@ -332,6 +335,7 @@ public: { _concreteFieldDrv = fieldDriver._concreteFieldDrv->copy(); } ~MED_FIELD_RDWR_DRIVER() { if (_concreteFieldDrv) delete _concreteFieldDrv;} virtual void read ( void ) throw (MEDEXCEPTION) { _concreteFieldDrv->read(); } + virtual MED_EN::med_mode_acces getAccessMode() const { return _concreteFieldDrv->getAccessMode(); } virtual void write( void ) const throw (MEDEXCEPTION) { _concreteFieldDrv->write(); } virtual void open() throw (MEDEXCEPTION) { _concreteFieldDrv->open(); } virtual void close() { _concreteFieldDrv->close(); } @@ -408,7 +412,7 @@ template <class T> MED_FIELD_WRONLY_DRIVER<T>::MED_FIELD_WRONLY_DRIVER() { template <class T> template < class INTERLACING_TAG > MED_FIELD_WRONLY_DRIVER<T>::MED_FIELD_WRONLY_DRIVER(const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField): - MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_RDONLY), + MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_WRONLY), IMED_FIELD_WRONLY_DRIVER<T>( fileName, ptrField) { BEGIN_OF("MED_FIELD_WRONLY_DRIVER::MED_FIELD_WRONLY_DRIVER(const string & fileName, const FIELD<T> * ptrField)"); @@ -429,7 +433,7 @@ template <class T> MED_FIELD_RDWR_DRIVER<T>::MED_FIELD_RDWR_DRIVER() { template <class T> template < class INTERLACING_TAG > MED_FIELD_RDWR_DRIVER<T>::MED_FIELD_RDWR_DRIVER(const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField): - MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_RDONLY), + MED_FIELD_DRIVER<T>(fileName,ptrField,MED_EN::MED_REMP), IMED_FIELD_RDWR_DRIVER<T>(fileName,ptrField) { BEGIN_OF("MED_FIELD_RDWR_DRIVER::MED_FIELD_RDWR_DRIVER(const string & fileName, const FIELD<T> * ptrField)"); diff --git a/src/MEDMEM/MEDMEM_MedFieldDriver21.hxx b/src/MEDMEM/MEDMEM_MedFieldDriver21.hxx index 8912451da..e96d5703f 100644 --- a/src/MEDMEM/MEDMEM_MedFieldDriver21.hxx +++ b/src/MEDMEM/MEDMEM_MedFieldDriver21.hxx @@ -36,6 +36,7 @@ #include "MEDMEM_Support.hxx" #include "MEDMEM_Mesh.hxx" +#include "MEDMEM_GaussLocalization.hxx" namespace MEDMEM { @@ -57,6 +58,7 @@ protected: med_2_1::med_int ndt, med_2_1::med_int od, SUPPORT & support, + vector<int> & numberOfGaussPoint, string & meshName) const throw (MEDEXCEPTION); void getMeshGeometricType(med_2_1::med_idt id, @@ -336,11 +338,12 @@ private: template <class T> bool MED_FIELD_DRIVER21<T>::createFieldSupport(med_2_1::med_idt id, - string & fieldName, - med_2_1::med_int ndt, - med_2_1::med_int od, - SUPPORT & support, - string & meshName) const throw (MEDEXCEPTION) + string & fieldName, + med_2_1::med_int ndt, + med_2_1::med_int od, + SUPPORT & support, + vector<int> & numberOfGaussPoints, + string & meshName) const throw (MEDEXCEPTION) { //EF : GĂ©rer le meshName pour le driver 2.2 @@ -359,13 +362,14 @@ MED_FIELD_DRIVER21<T>::createFieldSupport(med_2_1::med_idt id, //med_2_1::med_entite_maillage MED_EN::medEntityMesh entity; - bool alreadyFoundAnEntity=false, alreadyFoundPdtIt = false, anyGauss=false; + bool alreadyFoundAnEntity=false, alreadyFoundPdtIt = false/*, anyGauss=false*/; int numberOfElements = 0, numberOfElements1 = 0,numberOfElements2 = 0; int numberOfGeometricType = 0; //med_2_1::med_geometrie_element.. MED_EN::medGeometryElement geometricType[MED_NBR_GEOMETRIE_MAILLE]; int numberOfElementsOfType[MED_NBR_GEOMETRIE_MAILLE]; - int numberOfGaussPoints[MED_NBR_GEOMETRIE_MAILLE]; + //int numberOfGaussPoints[MED_NBR_GEOMETRIE_MAILLE]; + numberOfGaussPoints.resize(MED_NBR_GEOMETRIE_MAILLE, 1); med_2_1::med_int ngauss=0, numdt=-1, numo=-1, nbPdtIt=0; //nmaa=0 char dtunit[MED_TAILLE_PNOM21+1], maa[MED_TAILLE_NOM+1]; @@ -437,6 +441,8 @@ MED_FIELD_DRIVER21<T>::createFieldSupport(med_2_1::med_idt id, (med_2_1::med_entite_maillage) entityCurrent, (med_2_1::med_geometrie_element) *currentGeometry, j,maa,&ngauss,&numdt,dtunit,&dt,&numo); + + MED_FIELD_DRIVER<T>::_ptrField->setTime(dt); // PAL12664 // ret = med_2_2::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ), // (med_2_1::med_entite_maillage) (*currentEntity).first, @@ -479,12 +485,19 @@ MED_FIELD_DRIVER21<T>::createFieldSupport(med_2_1::med_idt id, << "| with (ndt,or) = (" << ndt << "," << od << ") for (entityType,geometricType)=(" << MED_EN::entNames[entityCurrent] << "," - << MED_EN::geoNames[*currentGeometry] << ")" )); ; + << MED_EN::geoNames[*currentGeometry] << ")" )); + if ( ngauss > 1000 ) { // some gabage + INFOS( "Set to 1 invalid nb of Gauss points " << ngauss << " for Field |" << fieldName + << "| with (ndt,or) = (" << ndt << "," << od << ") for (entityType,geometricType)=(" + << MED_EN::entNames[entityCurrent] << "," + << MED_EN::geoNames[*currentGeometry] << ")" ); + ngauss = 1; + } //totalNumberOfElements+=numberOfElements; numberOfElementsOfType[numberOfGeometricType] = numberOfElements/ngauss; numberOfGaussPoints[numberOfGeometricType] = ngauss; - anyGauss = (anyGauss || (ngauss-1) ); + //anyGauss = (anyGauss || (ngauss-1) ); geometricType[numberOfGeometricType]= *currentGeometry; numberOfGeometricType++; @@ -582,8 +595,12 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) const char * LOC = " MED_FIELD_RDONLY_DRIVER21::read() " ; BEGIN_OF(LOC); - typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array ArrayNo; - typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array ArrayNo; + typedef typename MEDMEM_ArrayInterface<T,NoInterlace,Gauss>::Array ArrayNoWg; + typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface<T,FullInterlace,Gauss>::Array ArrayFullWg; + typedef typename MEDMEM_ArrayInterface<T,NoInterlaceByType,NoGauss>::Array ArrayByType; + typedef typename MEDMEM_ArrayInterface<T,NoInterlaceByType,Gauss>::Array ArrayByTypeWg; if ( ( MED_FIELD_DRIVER<T>::_fieldName.empty() ) && ( MED_FIELD_DRIVER<T>::_ptrField->_name.empty() ) ) @@ -717,10 +734,11 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) // (MED_MAILLE ou MED_NOEUD uniquement car MEDMEMOIRE ne gère pas la connectivitĂ© descendante). // et crĂ©e le support correspondant. SUPPORT * mySupport = new SUPPORT(); + vector<int> numberOfGaussPoints; bool found = createFieldSupport(id,MED_FIELD_DRIVER<T>::_fieldName, MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber, MED_FIELD_DRIVER<T>::_ptrField->_orderNumber, - *mySupport, meshName) ; + *mySupport, numberOfGaussPoints, meshName) ; if ( !found ) { delete mySupport; delete[] componentName; delete[] unitName; MED_FIELD_DRIVER<T>::_fieldNum = MED_INVALID ; @@ -760,12 +778,12 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) // Pour tester les profils aussi ? vector< MED_EN::medGeometryElement > meshGeoType; vector< int > meshNbOfElOfType; - getMeshGeometricType(id,meshName,mySupport->getEntity(),meshGeoType,meshNbOfElOfType); - vector < MED_EN::medGeometryElement > v1( mySupport->getTypes(), - mySupport->getTypes()+mySupport->getNumberOfTypes() ); - vector < int > v2(mySupport->getNumberOfElements(), - mySupport->getNumberOfElements()+mySupport->getNumberOfTypes() ); - if ( ( meshGeoType != v1 ) || meshNbOfElOfType != v2 ) { + MED_FIELD_DRIVER21<T>::getMeshGeometricType(id,meshName,mySupport->getEntity(),meshGeoType,meshNbOfElOfType); + vector<MED_EN::medGeometryElement> supGeoType(mySupport->getTypes(), + mySupport->getTypes()+mySupport->getNumberOfTypes()); + vector < int > supNbOfElOfType(mySupport->getNumberOfElements(), + mySupport->getNumberOfElements()+mySupport->getNumberOfTypes() ); + if ( ( meshGeoType != supGeoType ) || meshNbOfElOfType != supNbOfElOfType ) { mySupport->setAll(false); } @@ -784,9 +802,9 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) for (int i=0; i<numberOfComponents; i++) { MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes[i] = 1 ; - MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i] = string(componentName,i*MED_TAILLE_PNOM21,MED_TAILLE_PNOM21) ; + MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i] = string(componentName+i*MED_TAILLE_PNOM21,MED_TAILLE_PNOM21) ; SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i]); - MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i] = string(unitName,i*MED_TAILLE_PNOM21,MED_TAILLE_PNOM21) ; + MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i] = string(unitName+i*MED_TAILLE_PNOM21,MED_TAILLE_PNOM21) ; SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i]); } @@ -801,21 +819,44 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) int TotalNumberOfValues = 0 ; // Profils a gerer en 2.2 Rmq from EF MESSAGE ("NumberOfTypes :"<< NumberOfTypes); MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues=0 ; + bool anyGauss=false; + + MED_EN::medModeSwitch interlacingType = MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType(); + bool isFullInterlace = ( interlacingType == MED_EN::MED_FULL_INTERLACE ); + bool isNoInterlaceByType = ( interlacingType == MED_EN::MED_NO_INTERLACE_BY_TYPE );//PAL17011 + + // PAL16681 (Read no interlace field from file) -> + // use medModeSwitch of a field in MEDMEMchampLire() if there is one geometric type + // to exclude array conversion + med_2_1::med_mode_switch modswt = med_2_1::MED_NO_INTERLACE; + // NOTE: field can be either of 3 medModeSwitch'es, MED_NO_INTERLACE_BY_TYPE added (PAL17011) + if ( NumberOfTypes == 1 && isFullInterlace ) + modswt = med_2_1::MED_FULL_INTERLACE; for (int i=0; i<NumberOfTypes; i++) { MESSAGE ("Type["<<i+1<<"] :"<< Types[i]); MESSAGE ("Entity :"<< mySupport->getEntity()); -// NumberOfValues[i] = -// MEDnVal(MED_FIELD_DRIVER21<T>::_medIdt, -// const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()), -// (med_2_1::med_entite_maillage)MED_FIELD_DRIVER<T>::_ptrField->_support->getEntity(), -// (med_2_1::med_geometrie_element)Types[i], -// MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber, -// MED_FIELD_DRIVER<T>::_ptrField->_orderNumber) ; - - NumberOfValues[i] = mySupport->getNumberOfElements(Types[i]) - * MED_FIELD_DRIVER<T>::_ptrField->getNumberOfGaussPoints(Types[i]); + int refNumberOfValues = + MEDnVal(MED_FIELD_DRIVER21<T>::_medIdt, + const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()), + (med_2_1::med_entite_maillage)mySupport->getEntity(), + (med_2_1::med_geometrie_element)Types[i], + MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber, + MED_FIELD_DRIVER<T>::_ptrField->_orderNumber); + + NumberOfValues[i] = mySupport->getNumberOfElements(Types[i]) * numberOfGaussPoints[i]; + // * MED_FIELD_DRIVER<T>::_ptrField->getNumberOfGaussPoints(Types[i]); + + // protect against spoiling memory when reading field values + if ( NumberOfValues[i] < refNumberOfValues ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< " Too many values (" << refNumberOfValues + << ") in field |" << MED_FIELD_DRIVER<T>::_fieldName + << "| with (it,or) = (" + << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << "," + << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << "), on mesh " + << meshName << "| while only " << NumberOfValues[i] + << " values expected")); myValues[i] = new T[ NumberOfValues[i]*numberOfComponents ] ; TotalNumberOfValues+=NumberOfValues[i] ; @@ -831,7 +872,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues+=mySupport->getNumberOfElements(Types[i]); // Ne doit pas prendre en compte les points de Gauss med_2_1::med_err ret; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) || defined(PCLINUX64_32) int lgth2=NumberOfValues[i]*numberOfComponents; if(MED_FIELD_DRIVER<T>::_ptrField->getValueType()==MED_EN::MED_INT32) { @@ -839,7 +880,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) ret=med_2_1::MEDchampLire(id,const_cast <char*> (meshName.c_str()), const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()), (unsigned char*) temp, - med_2_1::MED_NO_INTERLACE, + modswt /*med_2_1::MED_NO_INTERLACE*/, // PAL16681,17011 MED_ALL, ProfilName, (med_2_1::med_entite_maillage) mySupport->getEntity(), @@ -856,7 +897,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) ret=med_2_1::MEDchampLire(id,const_cast <char*> (meshName.c_str()), const_cast <char*> (MED_FIELD_DRIVER<T>::_fieldName.c_str()), (unsigned char*) myValues[i], - med_2_1::MED_NO_INTERLACE, + modswt /*med_2_1::MED_NO_INTERLACE*/, // PAL16681,17011 MED_ALL, ProfilName, (med_2_1::med_entite_maillage) mySupport->getEntity() @@ -866,7 +907,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) ); if (ret < 0) { - // The Field can't be read then we mustdelete all previously allocated members in FIELD + // The Field can't be read then we must delete all previously allocated members in FIELD for(int j=0; j<=i;j++) delete[] myValues[j]; delete[] myValues; @@ -887,55 +928,212 @@ template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::read(void) } delete[] ProfilName ; + } // allocate _value - // probleme avec les points de gauss : voir lorsqu-il y en a (!= 1) - // Creer un driver spĂ©cifique pour les modes MED_FULL_INTERLACE et MED_NO_INTERLACE - // serait plus efficicace. - ArrayNo * Values = new ArrayNo(numberOfComponents,TotalNumberOfValues); + MEDMEM_Array_ * Values; + if ( anyGauss ) { + vector<int> nbelgeoc( supNbOfElOfType.size()+1, 0 ), nbgaussgeo( supNbOfElOfType.size()+1, 0); + for ( int t = 0; t < NumberOfTypes; t++ ) { + nbelgeoc [ t+1 ] = nbelgeoc [ t ] + supNbOfElOfType [ t ]; + nbgaussgeo[ t+1 ] = /*nbgaussgeo[ t ] +*/ numberOfGaussPoints[ t ]; + } - for (int i=0; i<numberOfComponents; i++) + // PAL16681. If NumberOfTypes == 1 then myValues[0] is what should be + // in a field value, i.e. no conversion needed + if ( NumberOfTypes == 1 ) { - //T * ValuesT = Values->getRow(i+1) ; - int Count = 1 ; - for (int j=0; j<NumberOfTypes; j++) - { - T * myValue = myValues[j] ; - int NumberOf = NumberOfValues[j] ; - // MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues+=NumberOf; // problem with gauss point : _numberOfValues != TotalNumberOfValues !!!!!!! - int offset = NumberOf*i ; - for (int k=0 ; k<NumberOf; k++) { - //ValuesT[Count]=myValue[k+offset] ; - Values->setIJ(Count,i+1,myValue[k+offset]); - //jfa 22.07.2005:SCRUTE(Count); - //jfa 22.07.2005:SCRUTE(Values->getIJ(Count,i+1)); - Count++; - } - } + if ( isNoInterlaceByType ) // PAL17011 + Values = new ArrayByTypeWg(myValues[0], + numberOfComponents,TotalNumberOfValues,NumberOfTypes, + &nbelgeoc[0], &nbgaussgeo[0], + true, //shallowCopy + true); // ownershipOfValues + else if ( !isFullInterlace ) + Values = new ArrayNoWg(myValues[0], + numberOfComponents,TotalNumberOfValues,NumberOfTypes, + &nbelgeoc[0], &nbgaussgeo[0], + true, true); + else + Values = new ArrayFullWg(myValues[0], + numberOfComponents,TotalNumberOfValues,NumberOfTypes, + &nbelgeoc[0], &nbgaussgeo[0], + true, true); } - - for (int j=0; j<NumberOfTypes; j++) - delete[] myValues[j] ; + else if ( isNoInterlaceByType ) // PAL17011 + { + ArrayByTypeWg* aValues = new ArrayByTypeWg(numberOfComponents,TotalNumberOfValues, + NumberOfTypes, &nbelgeoc[0], &nbgaussgeo[0]); + Values = aValues; + T * myValue = new T[ aValues->getArraySize() ]; + int Count = 0 ; + for (int t=0; t<NumberOfTypes; t++) + { + int nbElem = supNbOfElOfType[ t ]; + int nbGauss = numberOfGaussPoints[ t ]; + int tSize = nbElem * nbGauss * numberOfComponents; + memcpy( myValue+Count, myValues[t], sizeof(T)*tSize ); + Count += tSize; + } + aValues->setPtr( myValue, true, true ); + } + else + { + ArrayNoWg* aValues = new ArrayNoWg(numberOfComponents,TotalNumberOfValues,NumberOfTypes, + &nbelgeoc[0], &nbgaussgeo[0]); + Values = aValues; + for (int j=1; j<=numberOfComponents; j++) + { + int Count = 1 ; + for (int t=0; t<NumberOfTypes; t++) + { + T * myValue = myValues[t] ; + int nbElem = supNbOfElOfType[ t ]; + int nbGauss = numberOfGaussPoints[ t ]; + nbelgeoc[1] = nbElem; + nbgaussgeo[1] = nbGauss; + ArrayNoWg indexer( numberOfComponents, nbElem, 1, &nbelgeoc[0], &nbgaussgeo[0]); + for (int i=1; i<=nbElem; i++) { + for (int k=1 ; k<=nbGauss; k++) + aValues->setIJK( Count, j, k, myValue[ indexer.getIndex( i, j, k )]); + Count++; + } + } + } + } + } + else { // if ( anyGauss ) + + // PAL16681. If NumberOfTypes == 1 then myValues[0] is what should be + // in a field value, i.e. no conversion needed + vector<int> nbelgeoc( supNbOfElOfType.size()+1, 0 ); + for ( int t = 0; t < NumberOfTypes; t++ ) + nbelgeoc[ t+1 ] = nbelgeoc[ t ] + supNbOfElOfType[ t ]; + if ( NumberOfTypes == 1 ) { + if ( isNoInterlaceByType ) // PAL17011 + Values = new ArrayByType(myValues[0],numberOfComponents,TotalNumberOfValues, + NumberOfTypes, &nbelgeoc[0], + true, //shallowCopy + true); // ownershipOfValues + else if ( !isFullInterlace ) + Values = new ArrayNo( myValues[0],numberOfComponents,TotalNumberOfValues,true, true); + else + Values = new ArrayFull( myValues[0],numberOfComponents,TotalNumberOfValues,true, true); + } + else if ( isNoInterlaceByType ) // PAL17011 + { + ArrayByType* aValues = new ArrayByType(numberOfComponents,TotalNumberOfValues, + NumberOfTypes, &nbelgeoc[0]); + Values = aValues; + T * myValue = new T[ aValues->getArraySize() ]; + int Count = 0 ; + for (int t=0; t<NumberOfTypes; t++) + { + int nbElem = supNbOfElOfType[ t ]; + int tSize = nbElem * numberOfComponents; + memcpy( myValue+Count, myValues[t], sizeof(T)*tSize ); + Count += tSize; + } + aValues->setPtr( myValue, true, true ); + } + else { + ArrayNo* aValues = new ArrayNo(numberOfComponents,TotalNumberOfValues); + Values = aValues; + + for (int i=0; i<numberOfComponents; i++) + { + //T * ValuesT = Values->getRow(i+1) ; + int Count = 1 ; + for (int j=0; j<NumberOfTypes; j++) + { + T * myValue = myValues[j] ; + int NumberOf = NumberOfValues[j] ; + int offset = NumberOf*i ; + for (int k=0 ; k<NumberOf; k++) { + //ValuesT[Count]=myValue[k+offset] ; + aValues->setIJ(Count,i+1,myValue[k+offset]); + Count++; + } + } + } + } + } + + // PAL16681. If NumberOfTypes == 1 then myValues[0] is used in field value + if ( NumberOfTypes != 1 ) + for (int j=0; j<NumberOfTypes; j++) + delete[] myValues[j] ; delete[] myValues ; delete[] NumberOfValues ; if (MED_FIELD_DRIVER<T>::_ptrField->_value != NULL) delete MED_FIELD_DRIVER<T>::_ptrField->_value; - if ( MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) - { - // dynamic_cast inutile - MED_FIELD_DRIVER<T>::_ptrField->_value=dynamic_cast<ArrayFull *>(ArrayConvert(*Values)); - delete Values; - } + if ( NumberOfTypes != 1 && // PAL16681 + isFullInterlace ) + { + // Convert MED_NO_INTERLACE -> MED_FULL_INTERLACE + if (Values->getGaussPresence()) + MED_FIELD_DRIVER<T>::_ptrField->_value=ArrayConvert(*static_cast<ArrayNoWg*>(Values)); + else + MED_FIELD_DRIVER<T>::_ptrField->_value=ArrayConvert(*static_cast<ArrayNo* >(Values)); + delete Values; + } else + { MED_FIELD_DRIVER<T>::_ptrField->_value=Values; - + } MED_FIELD_DRIVER<T>::_ptrField->_isRead = true ; MED_FIELD_DRIVER<T>::_ptrField->_support=mySupport; //PrĂ©venir l'utilisateur ? + + // check support entity and isOnAllElements + if ( haveSupport && mySupport->getEntity() != MED_EN::MED_NODE ) { + // check if support geometry corresponds to support entity in mesh + MESH* mesh = mySupport->getMesh(); + const MED_EN::medGeometryElement *meshGeoms, *endGeom, *foundGeom; + meshGeoms = mesh->getTypesWithPoly( mySupport->getEntity() ); + endGeom = meshGeoms + mesh->getNumberOfTypesWithPoly( mySupport->getEntity() ); + foundGeom = std::find( meshGeoms, endGeom, mySupport->getTypes()[ 0 ]); + bool geomFound = ( foundGeom != endGeom ); + if ( !geomFound ) // support geom type is missing in types of the entity in mesh + { // find entity corresponding to support geom type in the mesh + MED_EN::MESH_ENTITIES::const_iterator ent_geoms = MED_EN::meshEntities.begin(); + for ( ; ent_geoms != MED_EN::meshEntities.end(); ++ent_geoms ) { + if ( ent_geoms->first == mySupport->getEntity() ) + continue; + if ( mesh->getNumberOfElementsWithPoly( ent_geoms->first, MED_EN::MED_ALL_ELEMENTS)) { + meshGeoms = mesh->getTypesWithPoly( ent_geoms->first ); + endGeom = meshGeoms + mesh->getNumberOfTypesWithPoly( ent_geoms->first ); + foundGeom = std::find( meshGeoms, endGeom, mySupport->getTypes()[ 0 ]); + if ( foundGeom != endGeom ) { // geom type found + mySupport->setEntity( ent_geoms->first ); + break; + } + } + } + } + if ( !mySupport->isOnAllElements() ) { + // recheck isAll + meshGeoType = vector<MED_EN::medGeometryElement>(meshGeoms, endGeom); + bool isAll = ( meshGeoType == supGeoType ); + for ( int i = 0; ( isAll && i < supGeoType.size()); ++i ) + isAll = ( supNbOfElOfType[ i ] == + mesh->getNumberOfElementsWithPoly( mySupport->getEntity(), supGeoType[ i ])); + mySupport->setAll( isAll ); + } + if ( !geomFound ) { // initial entity was wrong + // update support name + string supportName; + if ( mySupport->isOnAllElements() ) + supportName = "SupportOnAll_" + MED_EN::entNames[ mySupport->getEntity() ]; + else + supportName = MED_FIELD_DRIVER<T>::_fieldName + "_Support"; + mySupport->setName( supportName ); + } + } - END_OF(LOC); + // END_OF(LOC); } template <class T> void MED_FIELD_RDONLY_DRIVER21<T>::write( void ) const @@ -965,7 +1163,10 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array ArrayNo; typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface<T,NoInterlaceByType,NoGauss>::Array ArrayNoByType; + //if (MED_FIELD_DRIVER<T>::_status==MED_OPENED && + // MED_FIELD_DRIVER<T>::_ptrField->_isRead ) if (MED_FIELD_DRIVER<T>::_status==MED_OPENED) { int err ; @@ -975,7 +1176,11 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const string component_unit(component_count*MED_TAILLE_PNOM21,' ') ; const string * listcomponent_name=MED_FIELD_DRIVER<T>::_ptrField->getComponentsNames() ; - const string * listcomponent_unit=MED_FIELD_DRIVER<T>::_ptrField->getMEDComponentsUnits() ; + const string * listcomponent_unit=MED_FIELD_DRIVER<T>::_ptrField->getMEDComponentsUnits(); + if ( ! listcomponent_name || ! listcomponent_unit ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" Udefined components of FIELD : " + << MED_FIELD_DRIVER<T>::_ptrField->getName() << ".")); + int length ; for (int i=0; i < component_count ; i++) { length = min(MED_TAILLE_PNOM21,(int)listcomponent_name[i].size()); @@ -1073,8 +1278,17 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const const T * value = NULL; ArrayFull * myArray = NULL; - if ( MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) + + med_2_1::med_mode_switch modswt = med_2_1::MED_FULL_INTERLACE; + MED_EN::medModeSwitch interlacingType = MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType(); + + if ( interlacingType == MED_EN::MED_FULL_INTERLACE ) { myArray = MED_FIELD_DRIVER<T>::_ptrField->getArrayNoGauss(); + } + else if ( interlacingType == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { //PAL17011 + // no need to convert, that is what this improvement is needed for + modswt = med_2_1::MED_NO_INTERLACE; + } else { // En attendant la convertion de FIELD, on utilise le ArrayConvert // ( les infos _ptrField-> sont les mĂªmes ) @@ -1083,15 +1297,18 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const )) ); } - for (int i=0;i<NumberOfType;i++) { int NumberOfElements = mySupport->getNumberOfElements(Types[i]) ; - int NumberOfGaussPoints = MED_FIELD_DRIVER<T>::_ptrField->getNumberOfGaussPoints(Types[i]) ; + int NumberOfGaussPoints = MED_FIELD_DRIVER<T>::_ptrField->getNumberOfGaussPoints(Types[i]) ; // const T * value = MED_FIELD_DRIVER<T>::_ptrField->getValueI(MED_EN::MED_FULL_INTERLACE,Index) ; - value = myArray->getRow(Index) ; - + if ( interlacingType == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { //PAL17011 + value = MED_FIELD_DRIVER<T>::_ptrField->getValueByType(i+1); + } + else { + value = myArray->getRow(Index) ; + } MESSAGE("MED_FIELD_DRIVER21<T>::_medIdt : "<<MED_FIELD_DRIVER21<T>::_medIdt); MESSAGE("MeshName.c_str() : "<<MeshName.c_str()); MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getName() : "<<MED_FIELD_DRIVER<T>::_ptrField->getName()); @@ -1123,10 +1340,10 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const cout<<"==================> nom unit lu = "<<chaunit<<endl; cout<<"==================> valeur de med_2_1::MED_REEL64 = "<<med_2_1::MED_REEL64<<endl; */ -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - if(_ptrField->getValueType()==MED_EN::MED_INT32) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) || defined(PCLINUX64_32) + if(MED_FIELD_DRIVER<T>::_ptrField->getValueType()==MED_EN::MED_INT32) { - int lgth2=_ptrField->getNumberOfValues(); + int lgth2=MED_FIELD_DRIVER<T>::_ptrField->getNumberOfValues(); med_2_1::med_int *temp=new med_2_1::med_int[lgth2]; for(int i2=0;i2<lgth2;i2++) temp[i2]=(int)(value[i2]); @@ -1134,7 +1351,7 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const const_cast <char*> ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str()) const_cast <char*> ( (MED_FIELD_DRIVER<T>::_ptrField->getName()).c_str()), (unsigned char*)temp, - med_2_1::MED_FULL_INTERLACE, + modswt /*med_2_1::MED_FULL_INTERLACE*/, //PAL17011 NumberOfElements, NumberOfGaussPoints, MED_ALL, @@ -1155,7 +1372,7 @@ template <class T> void MED_FIELD_WRONLY_DRIVER21<T>::write(void) const const_cast <char*> ( MeshName.c_str()) , //( string(mesh_name).resize(MED_TAILLE_NOM).c_str()) const_cast <char*> ( (MED_FIELD_DRIVER<T>::_ptrField->getName()).c_str()), (unsigned char*)value, - med_2_1::MED_FULL_INTERLACE, + modswt /*med_2_1::MED_FULL_INTERLACE*/, //PAL17011 NumberOfElements, NumberOfGaussPoints, MED_ALL, diff --git a/src/MEDMEM/MEDMEM_MedFieldDriver22.hxx b/src/MEDMEM/MEDMEM_MedFieldDriver22.hxx index 02aa8b49a..59942c7e3 100644 --- a/src/MEDMEM/MEDMEM_MedFieldDriver22.hxx +++ b/src/MEDMEM/MEDMEM_MedFieldDriver22.hxx @@ -38,11 +38,6 @@ #include "MEDMEM_Support.hxx" #include "MEDMEM_GaussLocalization.hxx" -//includes temporaires (attente release med fichier 2.3.1) -#include "MEDMEM_MEDMEMgaussEcr.hxx" -#include "MEDMEM_MEDMEMprofilEcr.hxx" -#include "MEDMEM_MEDMEMchampLire.hxx" - namespace MEDMEM { /*! @@ -57,12 +52,12 @@ template <class T> class MED_FIELD_DRIVER22 : public virtual MED_FIELD_DRIVER<T> { protected: - med_2_2::med_idt _medIdt; + med_2_3::med_idt _medIdt; - bool createFieldSupportPart1(med_2_2::med_idt id, + bool createFieldSupportPart1(med_2_3::med_idt id, const string & fieldName, - med_2_2::med_int ndt, - med_2_2::med_int od, + med_2_3::med_int ndt, + med_2_3::med_int od, SUPPORT & support, string & meshName, vector<int> & numberOfElementsOfTypeC, @@ -70,7 +65,7 @@ protected: int & totalNumberOfElWg ) const throw (MEDEXCEPTION); - void getMeshGeometricTypeFromFile(med_2_2::med_idt id, + void getMeshGeometricTypeFromFile(med_2_3::med_idt id, string & meshName, MED_EN::medEntityMesh entite, vector<MED_EN::medGeometryElement> & geoType, @@ -129,7 +124,7 @@ public : ); MESSAGE(LOC<<"_fileName.c_str : "<< MED_FIELD_DRIVER<T>::_fileName.c_str()<<",mode : "<< MED_FIELD_DRIVER<T>::_accessMode); - MED_FIELD_DRIVER22<T>::_medIdt = med_2_2::MEDouvrir( (const_cast <char *> (MED_FIELD_DRIVER<T>::_fileName.c_str())),(med_2_2::med_mode_acces) MED_FIELD_DRIVER<T>::_accessMode); + MED_FIELD_DRIVER22<T>::_medIdt = med_2_3::MEDouvrir( (const_cast <char *> (MED_FIELD_DRIVER<T>::_fileName.c_str())),(med_2_3::med_mode_acces) MED_FIELD_DRIVER<T>::_accessMode); MESSAGE(LOC<<"_medIdt : "<< MED_FIELD_DRIVER22<T>::_medIdt ); if (MED_FIELD_DRIVER22<T>::_medIdt > 0) MED_FIELD_DRIVER<T>::_status=MED_OPENED; @@ -148,9 +143,9 @@ public : void close() { BEGIN_OF("MED_FIELD_DRIVER22::close()"); - med_2_2::med_int err = 0; + med_2_3::med_int err = 0; if (MED_FIELD_DRIVER<T>::_status == MED_OPENED) { - err=med_2_2::MEDfermer(MED_FIELD_DRIVER22<T>::_medIdt); + err=med_2_3::MEDfermer(MED_FIELD_DRIVER22<T>::_medIdt); //H5close(); // If we call H5close() all the files are closed. MED_FIELD_DRIVER<T>::_status = MED_CLOSED; MED_FIELD_DRIVER22<T>::_medIdt = MED_INVALID; @@ -383,10 +378,10 @@ private: */ template <class T> bool -MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id, +MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_3::med_idt id, const string & fieldName, - med_2_2::med_int ndt, - med_2_2::med_int od, + med_2_3::med_int ndt, + med_2_3::med_int od, SUPPORT & support, string & meshName, vector<int> & numberOfElementsOfTypeC, @@ -419,12 +414,12 @@ MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id, numberOfElementsOfTypeC.resize(MED_NBR_GEOMETRIE_MAILLE+1); numberOfGaussPoint.resize(MED_NBR_GEOMETRIE_MAILLE+1); - med_2_2::med_int nmaa=0, ngauss=0, numdt=-1, numo=-1, nbPdtIt=0, nbPdtIt1=0, nbPdtIt2=0; + med_2_3::med_int nmaa=0, ngauss=0, numdt=-1, numo=-1, nbPdtIt=0, nbPdtIt1=0, nbPdtIt2=0; char dtunit[MED_TAILLE_PNOM22+1]; char maa[MED_TAILLE_NOM+1]; - med_2_2::med_float dt=-1.0; - med_2_2::med_booleen local; - med_2_2::med_err ret=1; + med_2_3::med_float dt=-1.0; + med_2_3::med_booleen local; + med_2_3::med_err ret=1; numberOfElementsOfTypeC[0] = 1; numberOfGaussPoint[0] = 1; totalNumberOfElWg = 0; @@ -444,16 +439,17 @@ MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id, entityCurrent = MED_EN::MED_EDGE; if (geometryCurrent == MED_EN::MED_TRIA3 || geometryCurrent == MED_EN::MED_QUAD4 || - geometryCurrent == MED_EN::MED_TRIA6 || geometryCurrent == MED_EN::MED_QUAD8) + geometryCurrent == MED_EN::MED_TRIA6 || geometryCurrent == MED_EN::MED_QUAD8 || + geometryCurrent == MED_EN::MED_POLYGON) entityCurrent = MED_EN::MED_FACE; - nbPdtIt1 = med_2_2::MEDnPasdetemps(id, const_cast <char*> ( fieldName.c_str() ), - (med_2_2::med_entite_maillage) (*currentEntity).first, - (med_2_2::med_geometrie_element) *currentGeometry ); + nbPdtIt1 = med_2_3::MEDnPasdetemps(id, const_cast <char*> ( fieldName.c_str() ), + (med_2_3::med_entite_maillage) (*currentEntity).first, + (med_2_3::med_geometrie_element) *currentGeometry ); - nbPdtIt2 = med_2_2::MEDnPasdetemps(id, const_cast <char*> ( fieldName.c_str() ), - (med_2_2::med_entite_maillage) entityCurrent, - (med_2_2::med_geometrie_element) geometryCurrent ); + nbPdtIt2 = med_2_3::MEDnPasdetemps(id, const_cast <char*> ( fieldName.c_str() ), + (med_2_3::med_entite_maillage) entityCurrent, + (med_2_3::med_geometrie_element) geometryCurrent ); if (nbPdtIt2 < nbPdtIt1) entityCurrent = (*currentEntity).first ; @@ -482,21 +478,23 @@ MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id, /* Cherche le champ pour le <ndt>,<ot> demandĂ© et dĂ©termine le nombre de points de Gauss*/ ret = 0; alreadyFoundPdtIt = false; ngauss =0; - for ( med_2_2::med_int j=1; j <= nbPdtIt; j++ ) { + for ( med_2_3::med_int j=1; j <= nbPdtIt; j++ ) { // Search how many <ngauss> (<fieldName>,<ndt>,<ot>) has (NB) - //ret += med_2_2::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ), - // (med_2_2::med_entite_maillage) (*currentEntity).first, - // (med_2_2::med_geometrie_element) *currentGeometry, + //ret += med_2_3::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ), + // (med_2_3::med_entite_maillage) (*currentEntity).first, + // (med_2_3::med_geometrie_element) *currentGeometry, // j, &ngauss, &numdt, &numo, dtunit, &dt, // maa, &local, &nmaa); - ret += med_2_2::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ), - (med_2_2::med_entite_maillage) entityCurrent, - (med_2_2::med_geometrie_element) *currentGeometry, + ret += med_2_3::MEDpasdetempsInfo(id, const_cast <char*> ( fieldName.c_str() ), + (med_2_3::med_entite_maillage) entityCurrent, + (med_2_3::med_geometrie_element) *currentGeometry, j, &ngauss, &numdt, &numo, dtunit, &dt, maa, &local, &nmaa); - + + MED_FIELD_DRIVER<T>::_ptrField->setTime(dt); // PAL12664 + if ( ndt == numdt && numo == od ) { alreadyFoundPdtIt = true; @@ -550,10 +548,10 @@ MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id, << MED_EN::entNames[entityCurrent] << "," << MED_EN::geoNames[*currentGeometry] << ")" )); ; - if ( (numberOfElements = med_2_2::MEDnVal(id, const_cast <char*> ( fieldName.c_str() ), - (med_2_2::med_entite_maillage) entityCurrent, - (med_2_2::med_geometrie_element) *currentGeometry, - numdt, numo, maa, med_2_2::MED_COMPACT)) <= 0 ) + if ( (numberOfElements = med_2_3::MEDnVal(id, const_cast <char*> ( fieldName.c_str() ), + (med_2_3::med_entite_maillage) entityCurrent, + (med_2_3::med_geometrie_element) *currentGeometry, + numdt, numo, maa, med_2_3::MED_COMPACT)) <= 0 ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Error in MEDnVal for Field |" << fieldName << "| with (ndt,or) = (" << ndt << "," << od << ") for (entityType,geometricType)=(" @@ -605,65 +603,119 @@ MED_FIELD_DRIVER22<T>::createFieldSupportPart1(med_2_2::med_idt id, */ template <class T> void -MED_FIELD_DRIVER22<T>::getMeshGeometricTypeFromFile(med_2_2::med_idt id, - string & meshName, - MED_EN::medEntityMesh entity, - vector<MED_EN::medGeometryElement> & geoType, - vector<int> &nbOfElOfType, - vector<int> &nbOfElOfTypeC - ) const throw(MEDEXCEPTION) +MED_FIELD_DRIVER22<T>::getMeshGeometricTypeFromFile(med_2_3::med_idt id, + string & meshName, + MED_EN::medEntityMesh entity, + vector<MED_EN::medGeometryElement> & geoType, + vector<int> &nbOfElOfType, + vector<int> &nbOfElOfTypeC + ) const throw(MEDEXCEPTION) { - const char LOC[] = "MED_FIELD_DRIVER<T>::getMeshGeometricTypeFromFile(...)"; + BEGIN_OF("MED_FIELD_DRIVER<T>::getMeshGeometricTypeFromFile(...)"); int numberOfGeometricType=0; MED_EN::medGeometryElement geometricType[MED_NBR_GEOMETRIE_MAILLE]; int numberOfElementsOfType [MED_NBR_GEOMETRIE_MAILLE]; int numberOfElementsOfTypeC[MED_NBR_GEOMETRIE_MAILLE+1]; - med_2_2::med_int numberOfElements=0; - med_2_2::med_table quoi; - if (entity == MED_EN::MED_CELL) quoi=med_2_2::MED_CONN; + med_2_3::med_int numberOfElements=0; + med_2_3::med_table quoi; + + /*in MED file, all entities are regarded as MED_CELL + (except for those related to descending connectivities), + whereas in MEDMEM the distinction between MED_CELL, MED_FACE and MED_EDGE exists + it is therefore necessary to distinguish the MED-file entity + that will be used for the call to MED-file + and the MEDMEM entity*/ + MED_EN::medEntityMesh medfile_entity; + if (entity==MED_EN::MED_NODE) + { + medfile_entity=MED_EN::MED_NODE; + quoi=med_2_3::MED_COOR; + } else - if (entity == MED_EN::MED_NODE) quoi=med_2_2::MED_COOR; - else - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Support Creation from Mesh |" << meshName - << "| on entity " << MED_EN::entNames[entity] - << "| is impossible, must be on MED_NODE or MED_CELL" )); + { + medfile_entity=MED_EN::MED_CELL; + quoi=med_2_3::MED_CONN; + } list<MED_EN::medGeometryElement>::const_iterator currentGeometry; bool alreadyFoundAnEntity = false; numberOfElementsOfTypeC[0]=0; for (currentGeometry = (MED_EN::meshEntities[entity]).begin(); - currentGeometry != (MED_EN::meshEntities[entity]).end(); currentGeometry++) { - - - if ( (numberOfElements = - med_2_2::MEDnEntMaa(id, - const_cast<char*> (meshName.c_str()), - quoi, - (med_2_2::med_entite_maillage) entity, - (med_2_2::med_geometrie_element) *currentGeometry, - med_2_2::MED_NOD) ) <= 0) + currentGeometry != (MED_EN::meshEntities[entity]).end(); currentGeometry++) + { + numberOfElements = + med_2_3::MEDnEntMaa(id, + const_cast<char*> (meshName.c_str()), + quoi, + (med_2_3::med_entite_maillage) medfile_entity, + (med_2_3::med_geometrie_element) *currentGeometry, + med_2_3::MED_NOD); + if (numberOfElements <= 0) continue; alreadyFoundAnEntity = true; numberOfElementsOfType[numberOfGeometricType] = numberOfElements; numberOfElementsOfTypeC[numberOfGeometricType+1] = numberOfElementsOfTypeC[numberOfGeometricType]+numberOfElements; - geometricType[numberOfGeometricType] = *currentGeometry; + MED_EN::medGeometryElement geomType; + + //MED_FILE uses MED_NONE as a geometricType to describe MED_NODE + //MEDMEM uses MED_POINT1 + if ( *currentGeometry==MED_NONE) + geomType=MED_POINT1; + else + geomType=*currentGeometry; + geometricType[numberOfGeometricType] = geomType; + numberOfGeometricType++; + } + + //Because MEDFILE and MEDMEM differ on the definition of MED_CELL + //it is necessary to remove the cells that do not + //have maximum cell dimension in the range covered by geometricType + int maxdim=0; + for (int i=0; i<numberOfGeometricType; i++) + { + CELLMODEL model(geometricType[i]); + int dim = model.getDimension(); + if (dim>maxdim) maxdim=dim; + } + nbOfElOfTypeC.push_back(0); + for (int i=0; i<numberOfGeometricType; i++) + { + CELLMODEL model(geometricType[i]); + int dim = model.getDimension(); + if (dim==maxdim || entity != MED_CELL) + { + geoType.push_back(geometricType[i]); + int nbelems = numberOfElementsOfType[i]; + nbOfElOfType.push_back(nbelems); + nbOfElOfTypeC.push_back(nbOfElOfTypeC[nbOfElOfTypeC.size()-1]+nbelems); + } } - geoType = vector<MED_EN::medGeometryElement>(geometricType,geometricType+numberOfGeometricType); - nbOfElOfType = vector<int> (numberOfElementsOfType,numberOfElementsOfType+numberOfGeometricType); - nbOfElOfTypeC = vector<int> (numberOfElementsOfTypeC,numberOfElementsOfTypeC+numberOfGeometricType+1); + // geoType = vector<MED_EN::medGeometryElement>(geometricType,geometricType+numberOfGeometricType); + // nbOfElOfType = vector<int> (numberOfElementsOfType,numberOfElementsOfType+numberOfGeometricType); + // nbOfElOfTypeC = vector<int> (numberOfElementsOfTypeC,numberOfElementsOfTypeC+numberOfGeometricType+1); // for (int j =0 ; j<= numberOfGeometricType;++j) // cout << "nbOfElOfTypeC["<<j<<"]="<<nbOfElOfTypeC[j]<<endl; + END_OF("MED_FIELD_DRIVER<T>::getMeshGeometricTypeFromFile(...)"); } +/*! +reads the MESH object in order to retrieve the list of geometric types for a given entity +\param[in] meshPtr pointer to MESH +\param[in] entity entity for which the geom types are required +\param[out] geoType list of geom types +\param[out] nbOfElOfType vector containing the number of elements per type (size : ntype) +\param[out] nbOfElOfTypeC accumulated version of nbOfElType (size : ntype+1) + */ + template <class T> void MED_FIELD_DRIVER22<T>::getMeshGeometricTypeFromMESH( MESH * meshPtr, MED_EN::medEntityMesh entity, @@ -680,8 +732,7 @@ MED_FIELD_DRIVER22<T>::getMeshGeometricTypeFromMESH( MESH * meshPtr, // Il est plus pratique de crĂ©er un support "onAll" // pour calculer les tableaux du nombre d'entitĂ©s cumulĂ©es - SUPPORT mySupportFromMesh = SUPPORT(meshPtr,"Temporary Support From Associated Mesh", - entity); + SUPPORT mySupportFromMesh (meshPtr, "Temporary Support From Associated Mesh", entity); geoType = vector<MED_EN::medGeometryElement>(mySupportFromMesh.getTypes(), mySupportFromMesh.getTypes()+mySupportFromMesh.getNumberOfTypes()); nbOfElOfType.resize(mySupportFromMesh.getNumberOfTypes()); @@ -709,10 +760,12 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) const char * LOC = " MED_FIELD_RDONLY_DRIVER22::read() " ; BEGIN_OF(LOC); - typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array ArrayNo; - typedef typename MEDMEM_ArrayInterface<T,NoInterlace,Gauss>::Array ArrayNoWg; - typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array ArrayFull; - typedef typename MEDMEM_ArrayInterface<T,FullInterlace,Gauss>::Array ArrayFullWg; + typedef typename MEDMEM_ArrayInterface<T,NoInterlace,NoGauss>::Array ArrayNo; + typedef typename MEDMEM_ArrayInterface<T,NoInterlace,Gauss>::Array ArrayNoWg; + typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array ArrayFull; + typedef typename MEDMEM_ArrayInterface<T,FullInterlace,Gauss>::Array ArrayFullWg; + typedef typename MEDMEM_ArrayInterface<T,NoInterlaceByType,NoGauss>::Array ArrayByType; + typedef typename MEDMEM_ArrayInterface<T,NoInterlaceByType,Gauss>::Array ArrayByTypeWg; if (MED_FIELD_DRIVER<T>::_status!=MED_OPENED) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": Method open must be called before method read.")) ; @@ -741,7 +794,8 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) const string & fieldName = MED_FIELD_DRIVER<T>::_fieldName; MED_EN::medModeSwitch interlacingType = MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType(); - bool isFullInterlace = ( interlacingType == MED_EN::MED_FULL_INTERLACE ); + bool isFullInterlace = ( interlacingType == MED_EN::MED_FULL_INTERLACE ); + bool isNoInterlaceByType = ( interlacingType == MED_EN::MED_NO_INTERLACE_BY_TYPE );//PAL17011 MESSAGE("###### "<<LOC<<" fieldNameDRIVER : "<< fieldName << " fieldName : "<< MED_FIELD_DRIVER<T>::_ptrField->_name); @@ -775,8 +829,8 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) int numberOfComponents = 0; char * componentName = (char *) MED_NULL; char * unitName = (char *) MED_NULL; - med_2_2::med_type_champ type ; - med_2_2::med_idt id = MED_FIELD_DRIVER22<T>::_medIdt; + med_2_3::med_type_champ type ; + med_2_3::med_idt id = MED_FIELD_DRIVER22<T>::_medIdt; bool needConversionToDouble = false,needConversionToInt64 = false; // we search for the "field med number" of <fieldName> @@ -784,13 +838,13 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) // <componentName>, <unitname>, <type> and attribute <_fieldNum> are set. if (MED_FIELD_DRIVER<T>::_fieldNum==MED_INVALID) { - int numberOfFields = med_2_2::MEDnChamp(id,0) ; + int numberOfFields = med_2_3::MEDnChamp(id,0) ; if ( numberOfFields <= 0 ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": There is no field found in the file !")); for (int i=1;i<=numberOfFields;i++) { - numberOfComponents = med_2_2::MEDnChamp(id,i) ; + numberOfComponents = med_2_3::MEDnChamp(id,i) ; if ( numberOfComponents <= 0 ) MESSAGE(LOC<<"Be careful there is no compound for field n°"<<i<<"in file |"<<MED_FIELD_DRIVER<T>::_fileName<<"| !"); @@ -798,7 +852,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) componentName = new char[numberOfComponents*MED_TAILLE_PNOM22+1] ; unitName = new char[numberOfComponents*MED_TAILLE_PNOM22+1] ; - err = med_2_2::MEDchampInfo(id, i, tmpFieldName, &type, componentName, + err = med_2_3::MEDchampInfo(id, i, tmpFieldName, &type, componentName, unitName, numberOfComponents) ; MESSAGE("Field "<<i<<" : #" << tmpFieldName <<"# et recherche #"<<fieldName.c_str()<<"#"); @@ -830,23 +884,23 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) } // Verifie que l'on essaye pas de lire un champ double dans un FIELD<int> - switch ( (med_2_2::med_type_champ) MED_FIELD_DRIVER<T>::_ptrField->_valueType ) { - case med_2_2::MED_INT : - case med_2_2::MED_INT32 : - case med_2_2::MED_INT64 : - if ( type == ( med_2_2::MED_FLOAT64 ) ) { + switch ( (med_2_3::med_type_champ) MED_FIELD_DRIVER<T>::_ptrField->_valueType ) { + case med_2_3::MED_INT : + case med_2_3::MED_INT32 : + case med_2_3::MED_INT64 : + if ( type == ( med_2_3::MED_FLOAT64 ) ) { delete[] componentName; delete[] unitName; throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Field Type in file (" << type <<") differs from FIELD object type (" << MED_FIELD_DRIVER<T>::_ptrField->_valueType << ")" )) ; } -#if defined(IRIX64) || defined(OSF1) ||defined(VPP5000) - if (_ptrField->_valueType==MED_EN::MED_INT32 ) +#if defined(IRIX64) || defined(OSF1) ||defined(VPP5000) || defined(PCLINUX64) + if (MED_FIELD_DRIVER<T>::_ptrField->_valueType==MED_EN::MED_INT32 ) needConversionToInt64=true; #endif break; - case med_2_2::MED_FLOAT64 : - if (type != med_2_2::MED_FLOAT64) + case med_2_3::MED_FLOAT64 : + if (type != med_2_3::MED_FLOAT64) needConversionToDouble=true; break; default: @@ -892,7 +946,6 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) << meshName << "|" )); } - MED_EN::medEntityMesh entityType = mySupport->getEntity(); //Si un SUPPORT Ă©tait donnĂ©, rĂ©cupère son nom, sa description et // le pointeur du maillage associĂ© @@ -926,7 +979,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) this->getMeshGeometricTypeFromMESH(ptrMesh,entityType,MESHgeoType, MESHnbOfElOfType,MESHnbOfElOfTypeC); - int fileHasMesh = ( med_2_2::MEDdimLire(id, const_cast<char *>(meshName.c_str())) > 0); + int fileHasMesh = ( med_2_3::MEDdimLire(id, const_cast<char *>(meshName.c_str())) > 0); vector< MED_EN::medGeometryElement > meshGeoType; vector< int > meshNbOfElOfType; vector< int > meshNbOfElOfTypeC; @@ -1003,7 +1056,6 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) meshNbOfElOfType = MESHnbOfElOfType; } - // Test si le Support du Champ repose ou non sur toutes les entitĂ©s gĂ©omĂ©triques // du maillage associĂ© et positionne ou non l'attribut onAll du SUPPORT. // Il ne s'agit pas de la gestion des profils @@ -1021,7 +1073,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) // l'attribut SUPPORT->_number est censĂ© Ăªtre positionnĂ© quand mĂªme ! Que faire ? // Si on veut Ăªtre compatible avec la signification première de onAll, // il faudrait crĂ©er des profils contenant toutes les entitĂ©s pour chaque type gĂ©omĂ©trique - // du SUPPORT mais d'une part c'est dommage d'un point de vue de l'emcombrement mĂ©moire + // du SUPPORT mais d'une part c'est dommage d'un point de vue de l'encombrement mĂ©moire // et d'autre part, Ă  la rĂ©Ă©criture du fichier MED on stockera des profils // alors qu'il n'y en avait pas Ă  l'origine (fichier MED diffĂ©rent après lecture/Ă©criture) ! // Si on laisse setAll Ă  vrai il faut Ăªtre sĂ»r que les utilisateurs prennent les @@ -1043,10 +1095,10 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) MED_FIELD_DRIVER<T>::_ptrField->_componentsDescriptions = new string[numberOfComponents] ; MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits = new string[numberOfComponents] ; for (int i=0; i<numberOfComponents; i++) { - MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes[i] = 1 ; - MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i] = string(componentName,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ; + MED_FIELD_DRIVER<T>::_ptrField->_componentsTypes[i] = 1 ; + MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i] = string(componentName+i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ; + MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i] = string(unitName+i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ; SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_componentsNames[i]); - MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i] = string(unitName,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ; SCRUTE(MED_FIELD_DRIVER<T>::_ptrField->_MEDComponentsUnits[i]); } delete[] componentName; @@ -1064,14 +1116,22 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) // du SUPPORT est false il faut positionner un profil pour tous les types gĂ©omĂ©triques // du SUPPORT int profilSizeC = 0; - vector < int > profilSize (NumberOfTypes,0); - vector < vector<int> > profilList (NumberOfTypes); - vector < string > profilNameList(NumberOfTypes); - char * profilName = new char[MED_TAILLE_NOM+1]; + vector < int > profilSize (NumberOfTypes,0); + vector < string > profilNameList(NumberOfTypes); + vector < vector<med_2_3::med_int> > profilList (NumberOfTypes); // IPAL13481 + vector < vector<med_2_3::med_int> > profilListFromFile (NumberOfTypes); // IPAL13481 + char * profilName = new char[MED_TAILLE_NOM+1]; MESSAGE ("NumberOfTypes : "<< NumberOfTypes); MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues=0 ; + // PAL16681 (Read no interlace field from file) -> + // use medModeSwitch of a field in MEDMEMchampLire() if there is one geometric type + // to exclude array conversion + med_2_3::med_mode_switch modswt = med_2_3::MED_FULL_INTERLACE; + // NOTE: field can be either of 3 medModeSwitch'es, MED_NO_INTERLACE_BY_TYPE added (PAL17011) + if ( NumberOfTypes == 1 && !isFullInterlace || isNoInterlaceByType ) + modswt = med_2_3::MED_NO_INTERLACE; for (int typeNo=0; typeNo<NumberOfTypes; typeNo++) { @@ -1084,40 +1144,41 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) MESSAGE ("MED_GEOM : "<< MED_EN::geoNames[types[typeNo]]); MESSAGE ("Iteration : "<< MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber()); MESSAGE ("Order : "<< MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber()); + MESSAGE ("Time : "<< MED_FIELD_DRIVER<T>::_ptrField->getTime()); MESSAGE ("NumberOfElements : "<< nbOfElOfType[typeNo]); MESSAGE ("NumberOfComponents : "<< numberOfComponents); MESSAGE ("NumberOfGaussPts : "<< numberOfGaussPoint[typeNo+1]); MESSAGE ("NumberOfValuesWg : "<< nbOfElOfType[typeNo]*numberOfGaussPoint[typeNo+1]); MESSAGE ("NumberOfValuesWgWc : "<< numberOfValuesWc); MESSAGE ("Index : "<< index); - med_2_2::med_err ret=-1; + med_2_3::med_err ret=-1; - med_2_2::med_int * myValuesTmp=0; + med_2_3::med_int * myValuesTmp=0; unsigned char* ptrTmp=0; if (needConversionToDouble || needConversionToInt64 ) { - myValuesTmp = new med_2_2::med_int[numberOfValuesWc]; + myValuesTmp = new med_2_3::med_int[numberOfValuesWc]; ptrTmp = (unsigned char*) myValuesTmp; } else ptrTmp = (unsigned char*) &myValues[index]; //VERIFIER LE NBRE - ret=med_2_2::MEDMEMchampLire(id,const_cast <char*> (meshName.c_str() ), - const_cast <char*> (fieldName.c_str()), - (unsigned char*) ptrTmp, - med_2_2::MED_FULL_INTERLACE, - MED_ALL, - gaussModelName, - profilName, - med_2_2::MED_COMPACT, - (med_2_2::med_entite_maillage) entityType, - (med_2_2::med_geometrie_element)types[typeNo], - MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(), - MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber() - ); + ret=med_2_3::MEDchampLire(id,const_cast <char*> (meshName.c_str() ), + const_cast <char*> (fieldName.c_str()), + (unsigned char*) ptrTmp, + modswt /*med_2_3::MED_FULL_INTERLACE*/, // PAL16681,17011 + MED_ALL, + gaussModelName, + profilName, + med_2_3::MED_COMPACT, + (med_2_3::med_entite_maillage) entityType, + (med_2_3::med_geometrie_element)types[typeNo], + MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(), + MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber() + ); if (needConversionToDouble || needConversionToInt64 ) { - if (needConversionToInt64 ) //utiliser un trait + if (needConversionToInt64 ) //utiliser un trait for(int i=0;i<numberOfValuesWc;++i) myValues[index+i]=(int)(myValuesTmp[i]); else @@ -1148,6 +1209,7 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) MED_FIELD_DRIVER<T>::_fieldNum = MED_INVALID ; // we have not found right field, so reset the field number throw MEDEXCEPTION( LOCALIZED( STRING(LOC) <<": ERROR while reading values")) ; } + index += numberOfValuesWc; // Le support prend en compte le nombre de valeurs liĂ© aux profils MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues+= @@ -1161,12 +1223,11 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) int t1 = (type_geo%100)*(type_geo/100); int ngauss = numberOfGaussPoint[typeNo+1]; int t2 = ngauss*(type_geo/100); - med_2_2::med_float * refcoo = new med_2_2::med_float[t1]; - med_2_2::med_float * gscoo = new med_2_2::med_float[t2]; - med_2_2::med_float * wg = new med_2_2::med_float[ngauss]; + med_2_3::med_float * refcoo = new med_2_3::med_float[t1]; + med_2_3::med_float * gscoo = new med_2_3::med_float[t2]; + med_2_3::med_float * wg = new med_2_3::med_float[ngauss]; - if (MEDgaussLire(id, refcoo, gscoo, wg, (med_2_2::med_mode_switch) interlacingType, - gaussModelName ) < 0) + if (MEDgaussLire(id, refcoo, gscoo, wg, modswt, gaussModelName ) < 0) throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error while reading Gauss Model |" << gaussModelName << "| for FIELD "<< fieldName << " on geometric type " << MED_EN::geoNames[types[typeNo]] @@ -1183,47 +1244,54 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) } // cout << *MED_FIELD_DRIVER<T>::_ptrField->_gaussModel[types[typeNo]] << endl; delete [] refcoo;delete [] gscoo; delete [] wg; + } delete[] gaussModelName ; if ( strcmp(profilName,MED_NOPFL) ) { anyProfil = true; - pflSize = med_2_2::MEDnValProfil(id,profilName); + pflSize = med_2_3::MEDnValProfil(id,profilName); if ( pflSize <= 0) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Error while reading the profil size of |" << profilName << "|" )); profilSize[typeNo]=pflSize; profilList[typeNo].resize(pflSize); - ret = med_2_2::MEDprofilLire(id,&profilList[typeNo][0],profilName); // cf item 16 Effective STL + profilListFromFile[typeNo].resize(pflSize); + ret = med_2_3::MEDprofilLire(id,&profilList[typeNo][0],profilName); // cf item 16 Effective STL // IPAL13481 + profilListFromFile[typeNo] = profilList[typeNo]; profilNameList[typeNo]=string(profilName); } } - delete[] profilName ; + delete[] profilName; //MESSAGE ("Index : "<< index); assert(index == totalNumberOfElWg*numberOfComponents); assert(MED_FIELD_DRIVER<T>::_ptrField->_numberOfValues == mySupport->getNumberOfElements(MED_ALL_ELEMENTS)); - if (anyProfil) { - - for (int typeNo=0; typeNo < NumberOfTypes; typeNo++) { + if (anyProfil) + { + for (int typeNo=0; typeNo < NumberOfTypes; typeNo++) + { + //MED_FILE uses MED_NONE as a geometricType to describe MED_NODE + //MEDMEM uses MED_POINT1 + MED_EN::medGeometryElement geomType = types[typeNo]; + if (geomType == MED_EN::MED_NONE) + geomType = MED_EN::MED_POINT1; // Trouve l'index du type gĂ©omĂ©trique dans la liste des types gĂ©omĂ©triques du maillage // correspondant au type gĂ©omĂ©trique du champ traitĂ© vector<MED_EN::medGeometryElement>::iterator meshTypeNoIt = - find(meshGeoType.begin(),meshGeoType.end(),types[typeNo]); //GĂ©rer l'exception - if ( meshTypeNoIt == meshGeoType.end() ) - throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Can't find "<< MED_EN::geoNames[types[typeNo]] - << " on entity " << MED_EN::entNames[entityType] - << " in geometric type list of mesh " << meshName - ) - ); - int meshTypeNo = meshTypeNoIt - meshGeoType.begin(); - - if (! profilList[typeNo].empty() ) { - + find(meshGeoType.begin(),meshGeoType.end(),geomType); //GĂ©rer l'exception + if (meshTypeNoIt == meshGeoType.end()) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<": Can't find "<< MED_EN::geoNames[geomType] + << " on entity " << MED_EN::entNames[entityType] + << " in geometric type list of mesh " << meshName)); + int meshTypeNo = meshTypeNoIt - meshGeoType.begin(); + + if (! profilList[typeNo].empty() ) + { // for (int j =0 ; j< meshGeoType.size();++j) // cout << "--MeshTypeNo : "<<meshTypeNo<<"-> meshNbOfElOfTypeC["<<j<<"]="<<meshNbOfElOfTypeC[j]<<endl; // cout << "--typeNo--" << typeNo << endl; @@ -1267,11 +1335,27 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) for( int typeNo=0; typeNo < NumberOfTypes; typeNo++ ) index[typeNo+1]=index[typeNo]+profilSize[typeNo]; skyLine->setIndex(&index[0]); - for (int i=1; i <= profilList.size() ; i++) - skyLine->setI(i,&profilList[i-1][0]); + for (int i=1; i <= profilList.size() ; i++) { + vector<int> aTmp(profilList[i-1].size()); // IPAL13481 + for (int j=0; j < profilList[i-1].size(); j++) + aTmp[j] = (int) profilList[i-1][j]; + skyLine->setI(i,&aTmp[0]); + //skyLine->setI(i,&profilList[i-1][0]); + } + + MEDSKYLINEARRAY * skyLineFromFile = new MEDSKYLINEARRAY(profilListFromFile.size(), profilSizeC ); + skyLineFromFile->setIndex(&index[0]); + for (int i=1; i <= profilListFromFile.size() ; i++) { + vector<int> aTmp(profilListFromFile[i-1].size()); // IPAL13481 + for (int j=0; j < profilListFromFile[i-1].size(); j++) + aTmp[j] = (int) profilListFromFile[i-1][j]; + skyLineFromFile->setI(i,&aTmp[0]); + //skyLineFromFile->setI(i,&profilListFromFile[i-1][0]); + } mySupport->setAll(false); mySupport->setpartial(skyLine,true); + mySupport->setpartial_fromfile(skyLineFromFile,true); mySupport->setProfilNames(profilNameList); // cout << "Valeurs du skyline du SUPPORT partiel crĂ©e : " << *skyLine << endl; } @@ -1286,40 +1370,73 @@ template <class T> void MED_FIELD_RDONLY_DRIVER22<T>::read(void) SCRUTE(NumberOfTypes); SCRUTE(numberOfElementsOfTypeC[NumberOfTypes]-1); assert(mySupport->getNumberOfElements(MED_ALL_ELEMENTS) == (numberOfElementsOfTypeC[NumberOfTypes]-1) ); - Values = new ArrayFullWg(myValues, - numberOfComponents, - numberOfElementsOfTypeC[NumberOfTypes]-1, - // Up : Prend en compte les profils et - // Ne prend pas en compte le nbre de composantes et - // le nombre de points de Gauss - NumberOfTypes, - &numberOfElementsOfTypeC[0], - &numberOfGaussPoint[0], - true,true); + // PAL16681. If NumberOfTypes == 1 then myValues is what should be + // in a field value, inspite of InterlacingType + if ( NumberOfTypes == 1 && modswt == med_2_3::MED_NO_INTERLACE ) + Values = new ArrayNoWg(myValues, + numberOfComponents, + numberOfElementsOfTypeC[NumberOfTypes]-1, + NumberOfTypes, + &numberOfElementsOfTypeC[0], + &numberOfGaussPoint[0], + true,true); + else if ( isNoInterlaceByType ) // PAL17011 (MEDMEM : no_interlace_by_type fields) + Values = new ArrayByTypeWg(myValues, + numberOfComponents, + numberOfElementsOfTypeC[NumberOfTypes]-1, + NumberOfTypes, + &numberOfElementsOfTypeC[0], + &numberOfGaussPoint[0], + true,true); + else + Values = new ArrayFullWg(myValues, + numberOfComponents, + numberOfElementsOfTypeC[NumberOfTypes]-1, + // Up : Prend en compte les profils et + // Ne prend pas en compte le nbre de composantes et + // le nombre de points de Gauss + NumberOfTypes, + &numberOfElementsOfTypeC[0], + &numberOfGaussPoint[0], + true,true); // cout << "Valeurs du ArrayFullWg crĂ©e : " << endl << // *(static_cast<ArrayFullWg*>(Values)) << endl; - } else - Values = new ArrayFull(myValues,numberOfComponents,totalNumberOfElWg, - true,true); + } + else { + // PAL16681. If NumberOfTypes == 1 then myValues is what should be + // in a field value, inspite of InterlacingType + if ( NumberOfTypes == 1 && interlacingType == MED_EN::MED_NO_INTERLACE ) + Values = new ArrayNo(myValues,numberOfComponents,totalNumberOfElWg, + true,true); + else if ( isNoInterlaceByType ) // PAL17011 (MEDMEM : no_interlace_by_type fields) + Values = new ArrayByType(myValues,numberOfComponents,totalNumberOfElWg, + NumberOfTypes, &numberOfElementsOfTypeC[0], true,true); + else + Values = new ArrayFull(myValues,numberOfComponents,totalNumberOfElWg, + true,true); + } if (MED_FIELD_DRIVER<T>::_ptrField->_value != NULL) delete MED_FIELD_DRIVER<T>::_ptrField->_value; - if ( MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) - { - if (Values->getGaussPresence()) - MED_FIELD_DRIVER<T>::_ptrField->_value=ArrayConvert(*static_cast<ArrayFullWg*>(Values)); - else - MED_FIELD_DRIVER<T>::_ptrField->_value=ArrayConvert(*static_cast<ArrayNo* >(Values)); - delete Values; - } + if ( NumberOfTypes != 1 && // PAL16681 + interlacingType == MED_EN::MED_NO_INTERLACE ) + { + // Convert MED_FULL_INTERLACE -> MED_NO_INTERLACE + if (Values->getGaussPresence()) + MED_FIELD_DRIVER<T>::_ptrField->_value=ArrayConvert(*static_cast<ArrayFullWg*>(Values)); + else + MED_FIELD_DRIVER<T>::_ptrField->_value=ArrayConvert(*static_cast<ArrayFull* >(Values)); + delete Values; + } else + { MED_FIELD_DRIVER<T>::_ptrField->_value=Values; + } MED_FIELD_DRIVER<T>::_ptrField->_isRead = true ; MED_FIELD_DRIVER<T>::_ptrField->_support=mySupport; //PrĂ©venir l'utilisateur ? - END_OF(LOC); } @@ -1356,10 +1473,10 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const typedef map<MED_EN::medGeometryElement,GAUSS_LOCALIZATION<NoInterlace>*> locMapNo; typedef map<MED_EN::medGeometryElement,GAUSS_LOCALIZATION_*> locMap; - med_2_2::med_idt id = MED_FIELD_DRIVER22<T>::_medIdt; + med_2_3::med_idt id = MED_FIELD_DRIVER22<T>::_medIdt; if (MED_FIELD_DRIVER<T>::_status!=MED_OPENED) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": Method open must be called before method read.")) ; + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": Method open must be called before method write.")) ; string fieldName; if ( ( MED_FIELD_DRIVER<T>::_fieldName.empty() ) && @@ -1370,10 +1487,14 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const // If _fieldName is not set in driver, try to use _ptrfield->_fieldName if ( ( MED_FIELD_DRIVER<T>::_fieldName.empty() ) && ( !MED_FIELD_DRIVER<T>::_ptrField->_name.empty() ) ) - fieldName=MED_FIELD_DRIVER<T>::_ptrField->_name; + fieldName = MED_FIELD_DRIVER<T>::_ptrField->_name; else fieldName = MED_FIELD_DRIVER<T>::_fieldName; + //if ( ! MED_FIELD_DRIVER<T>::_ptrField->_isRead ) + // throw MEDEXCEPTION(LOCALIZED(STRING(LOC) + // <<" FIELD |"<<fieldName<<"| was not read but is being written")); + SCRUTE(fieldName); if ( fieldName.size() > MED_TAILLE_NOM ) { fieldName.substr(0,MED_TAILLE_NOM); @@ -1407,6 +1528,9 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const const string * listcomponent_name=MED_FIELD_DRIVER<T>::_ptrField->getComponentsNames() ; const string * listcomponent_unit=MED_FIELD_DRIVER<T>::_ptrField->getMEDComponentsUnits() ; + if ( ! listcomponent_name || ! listcomponent_unit ) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" Udefined components of FIELD : " + << fieldName << ".")); int length ; for (int i=0; i < component_count ; i++) { length = min(MED_TAILLE_PNOM22,(int)listcomponent_name[i].size()); @@ -1427,15 +1551,15 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const // VĂ©rifier si le champ existe dĂ©jĂ  char champName[MED_TAILLE_NOM+1]; char * compName, * compUnit ; - med_2_2::med_type_champ type ; + med_2_3::med_type_champ type ; bool Find = false ; - int n = med_2_2::MEDnChamp(id,0); + int n = med_2_3::MEDnChamp(id,0); int nbComp = 0; for (int i=1; i<=n; i++) { - nbComp = med_2_2::MEDnChamp(id,i); + nbComp = med_2_3::MEDnChamp(id,i); compName = new char[MED_TAILLE_PNOM22*nbComp+1]; compUnit = new char[MED_TAILLE_PNOM22*nbComp+1]; - err = med_2_2::MEDchampInfo(id,i,champName,&type,compName,compUnit,nbComp); + err = med_2_3::MEDchampInfo(id,i,champName,&type,compName,compUnit,nbComp); if (err == 0) if (!strcmp(champName,fieldName.c_str()) ) { Find = true ; @@ -1469,13 +1593,13 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const string dataGroupName = "/CHA/"; dataGroupName += fieldName; MESSAGE(LOC << "|" << dataGroupName << "|" ); - med_2_2::med_idt gid = H5Gopen(id, dataGroupName.c_str() ); + med_2_3::med_idt gid = H5Gopen(id, dataGroupName.c_str() ); if ( gid < 0 ) { // create field : - err=med_2_2::MEDchampCr(id, + err=med_2_3::MEDchampCr(id, const_cast <char*> (fieldName.c_str()), - (med_2_2::med_type_champ) ValueType, + (med_2_3::med_type_champ) ValueType, const_cast <char*> ( component_name.c_str() ), const_cast <char*> ( component_unit.c_str() ), component_count); @@ -1495,13 +1619,21 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const // de doubler l'utilisation de la taille mĂ©moire si le champ n'est pas dans // le bon mode. FIELD<T,FullInterlace> * myField = 0; - if ( MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) - myField = MED_FIELD_DRIVER<T>::_ptrField; - else - myField = FieldConvert( *( dynamic_cast< FIELD<T,NoInterlace> * > (MED_FIELD_DRIVER<T>::_ptrField ) - ) - ); + MED_EN::medModeSwitch interlacingType = MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType(); + bool isFullInterlace = ( interlacingType == MED_EN::MED_FULL_INTERLACE ); + bool isNoInterlaceByType = ( interlacingType == MED_EN::MED_NO_INTERLACE_BY_TYPE );//PAL17011 + med_2_3::med_mode_switch modswt = med_2_3::MED_FULL_INTERLACE; + if ( isFullInterlace ) { + myField = MED_FIELD_DRIVER<T>::_ptrField; + } + else if ( isNoInterlaceByType ) { + // PAL17011, no need to convert, that is what this improvement is needed for + modswt = med_2_3::MED_NO_INTERLACE; + } + else { + myField = FieldConvert( *((FIELD<T,NoInterlace>*) MED_FIELD_DRIVER<T>::_ptrField )); + } // Il est necessaire de calculer le tableau // du nombre d'entitĂ©s cumulĂ©es de chaque type gĂ©omĂ©trique du maillage @@ -1521,7 +1653,7 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const vector<MED_EN::medGeometryElement> fileMeshGeoType; vector<int> fileMeshNbOfElOfType; vector<int> fileMeshNbOfElOfTypeC; - med_2_2::med_int fileHasMesh=0; + med_2_3::med_int fileHasMesh=0; if (!onAll) { @@ -1529,7 +1661,7 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const numberIndex = mySupport->getNumberIndex(); profilNameList=mySupport->getProfilNames(); - fileHasMesh = ( med_2_2::MEDdimLire(id, const_cast<char *>(meshName.c_str())) > 0); + fileHasMesh = ( med_2_3::MEDdimLire(id, const_cast<char *>(meshName.c_str())) > 0); MESH * meshPtr = mySupport->getMesh(); if (fileHasMesh) @@ -1592,32 +1724,55 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const // rem 2 : Afin de respecter la norme MEDFICHIER, les indices contenus dans les // profils doivent Ăªtre croissant if (onAll) { - value = myField->getRow(index); + + if ( isNoInterlaceByType ) { //PAL17011 + value = MED_FIELD_DRIVER<T>::_ptrField->getValueByType(typeNo+1); + //((ArrayNoByType *)MED_FIELD_DRIVER<T>::_ptrField->getArray())->getValueByType(i+1); + } + else { + value = myField->getRow(index); + } profilName=MED_NOPFL; numberOfElForMED = numberOfElements; + } else { - value = myField->getRow(number[index-1]); - profilName = profilNameList[typeNo].substr(0,MED_TAILLE_NOM); + + if ( isNoInterlaceByType ) { //PAL17011 + value = MED_FIELD_DRIVER<T>::_ptrField->getValueByType(typeNo+1); + } + else { + value = myField->getRow(number[index-1]); + } + // PAL16854(Partial support on nodes) -> + //profilName = (profilNameList.size()>typeNo) ? profilNameList[typeNo].substr(0,MED_TAILLE_NOM) : MED_NOPFL; + if (profilNameList[typeNo].size()>MED_TAILLE_NOM) + profilName = profilNameList[typeNo].substr(0,MED_TAILLE_NOM); + else + profilName= profilNameList[typeNo]; + // Rem : Si le SUPPORT n'est pas onAll mais que pour un type gĂ©omĂ©trique donnĂ© le nom // du profil associĂ© est MED_NOPFL alors le profil n'est pas Ă©crit dans le fichier MED. // Car en MEDMEMOIRE si le champ repose sur des Ă©lĂ©ments de deux types gĂ©omĂ©triques // diffĂ©rents et est dĂ©fini sur tous les Ă©lĂ©ments d'un type gĂ©omĂ©trique // mais pas de l'autre, il existe tout de mĂªme des profils sur les deux types gĂ©omĂ©triques. // Ce n'est pas le cas en MEDFICHIER. - vector<int> profil(&number[index-1],&(number[index-1])+numberOfElements); + vector<med_2_3::med_int> profil(&number[index-1],&(number[index-1])+numberOfElements); - // Trouve l'index du type gĂ©omĂ©trique dans la liste des types gĂ©omĂ©triques du maillage - // correspondant au type gĂ©omĂ©trique du champ en cours de traitement - vector<MED_EN::medGeometryElement>::iterator meshTypeNoIt = - find(meshGeoType.begin(),meshGeoType.end(),types[typeNo]); - if ( meshTypeNoIt == meshGeoType.end() ) - throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Can't find "<< MED_EN::geoNames[types[typeNo]] - << " on entity " << MED_EN::entNames[entityType] - << " in geometric type list of mesh " << meshName - ) - ); - - int meshTypeNo = meshTypeNoIt - meshGeoType.begin(); + int meshTypeNo=0; + if ( entityType != MED_EN::MED_NODE ) // PAL16854(Partial support on nodes) + { + // Trouve l'index du type gĂ©omĂ©trique dans la liste des types gĂ©omĂ©triques du maillage + // correspondant au type gĂ©omĂ©trique du champ en cours de traitement + vector<MED_EN::medGeometryElement>::iterator meshTypeNoIt = + find(meshGeoType.begin(),meshGeoType.end(),types[typeNo]); + if ( meshTypeNoIt == meshGeoType.end() ) + throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Can't find "<< MED_EN::geoNames[types[typeNo]] + << " on entity " << MED_EN::entNames[entityType] + << " in geometric type list of mesh " << meshName + ) + ); + meshTypeNo = meshTypeNoIt - meshGeoType.begin(); + } if ( profilName == MED_NOPFL && profil.size() != meshNbOfElOfType[meshTypeNo] ) throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error while creating profil for FIELD "<< fieldName @@ -1657,7 +1812,7 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const ) ); - if ( med_2_2::MEDMEMprofilEcr(id, + if ( med_2_3::MEDprofilEcr(id, &profil[0], numberOfElements, const_cast<char *>(profilName.c_str())) < 0) @@ -1668,9 +1823,9 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const ); } - + bool anyGauss = MED_FIELD_DRIVER<T>::_ptrField->getGaussPresence(); string locName=MED_NOGAUSS; - if (myField->getGaussPresence()) { + if ( anyGauss ) { // cout << endl << "Nombre de points de Gauss Ă  l'Ă©criture de " << fieldName // << " pour le type gĂ©omĂ©trique : " << MED_EN::geoNames[types[typeNo]] // << " : " << myField->getNumberOfGaussPoints(types[typeNo]) << endl; @@ -1696,26 +1851,26 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const const GAUSS_LOCALIZATION<FullInterlace> & loc=*(static_cast<const GAUSS_LOCALIZATION<FullInterlace> * >(locPtr)); ngauss = loc.getNbGauss(); locName=loc.getName(); - err=med_2_2::MEDMEMgaussEcr(id, - (med_2_2::med_geometrie_element) loc.getType(), - (med_2_2::med_float *) loc.getRefCoo().getPtr(), - med_2_2::MED_FULL_INTERLACE, - (med_2_2::med_int) ngauss, - (med_2_2::med_float *) loc.getGsCoo().getPtr(), - (med_2_2::med_float *) (&loc.getWeight()[0]), + err=med_2_3::MEDgaussEcr(id, + (med_2_3::med_geometrie_element) loc.getType(), + (med_2_3::med_float *) loc.getRefCoo().getPtr(), + med_2_3::MED_FULL_INTERLACE, + (med_2_3::med_int) ngauss, + (med_2_3::med_float *) loc.getGsCoo().getPtr(), + (med_2_3::med_float *) (&loc.getWeight()[0]), const_cast<char *> (locName.c_str()) ); } else { const GAUSS_LOCALIZATION<NoInterlace> & loc=*(static_cast<const GAUSS_LOCALIZATION<NoInterlace> * >(locPtr)); ngauss = loc.getNbGauss(); locName=loc.getName(); - err=med_2_2::MEDMEMgaussEcr(id, - (med_2_2::med_geometrie_element) loc.getType(), - (med_2_2::med_float *) loc.getRefCoo().getPtr(), - med_2_2::MED_NO_INTERLACE, - (med_2_2::med_int) ngauss, - (med_2_2::med_float *) loc.getGsCoo().getPtr(), - (med_2_2::med_float *) (&loc.getWeight()[0]), + err=med_2_3::MEDgaussEcr(id, + (med_2_3::med_geometrie_element) loc.getType(), + (med_2_3::med_float *) loc.getRefCoo().getPtr(), + med_2_3::MED_NO_INTERLACE, + (med_2_3::med_int) ngauss, + (med_2_3::med_float *) loc.getGsCoo().getPtr(), + (med_2_3::med_float *) (&loc.getWeight()[0]), const_cast<char *> (locName.c_str()) ); @@ -1741,25 +1896,26 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const MESSAGE("numberOfElForMED : "<<numberOfElForMED); MESSAGE("entityType : "<<MED_EN::entNames[entityType]); MESSAGE("types[i] : "<<MED_EN::geoNames[types[typeNo]]); - MESSAGE("NumberOfGaussPoint[i] : "<<myField->getNumberOfGaussPoints(types[typeNo])); + if (myField) //myField may be NULL (PAL17011) + MESSAGE("NumberOfGaussPoint[i] : "<<myField->getNumberOfGaussPoints(types[typeNo])); MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber() : "<<MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber()); MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getTime() : "<<MED_FIELD_DRIVER<T>::_ptrField->getTime()); MESSAGE("MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber() : "<<MED_FIELD_DRIVER<T>::_ptrField->getOrderNumber()); // Rem 1 : le nombre d'Ă©lĂ©ments passĂ© Ă  MEDchampEcr ne doit pas tenir compte de la taille // des profils : c'est la taille du champ sans profil. - err=med_2_2::MEDchampEcr(id, + err=med_2_3::MEDchampEcr(id, const_cast <char*> ( meshName.c_str()) , const_cast <char*> ( fieldName.c_str()), - (unsigned char*)value, med_2_2::MED_FULL_INTERLACE, + (unsigned char*)value, modswt,//med_2_3::MED_FULL_INTERLACE,- PAL17011 numberOfElForMED, //UP : prend en compte le nombre de points de Gauss mais // pas le nombre de composantes const_cast <char*> ( locName.c_str()), MED_ALL, - const_cast <char *> (profilName.c_str()), med_2_2::MED_COMPACT, - (med_2_2::med_entite_maillage)entityType, - (med_2_2::med_geometrie_element)types[typeNo], + const_cast <char *> (profilName.c_str()), med_2_3::MED_COMPACT, + (med_2_3::med_entite_maillage)entityType, + (med_2_3::med_geometrie_element)types[typeNo], MED_FIELD_DRIVER<T>::_ptrField->getIterationNumber(), " ", // A FAIRE : IMPLEMENTER L'UNITE DU PAS DE TEMPS! MED_FIELD_DRIVER<T>::_ptrField->getTime(), @@ -1767,23 +1923,25 @@ template <class T> void MED_FIELD_WRONLY_DRIVER22<T>::write(void) const ); if (err < MED_VALID ) { - if ( MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) delete myField; - throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error while writing "<< numberOfElements << " values for FIELD "<< fieldName - << " on entity " << MED_EN::entNames[entityType] - << " and geometric type " << MED_EN::geoNames[types[typeNo]] - << " with (it,or) = (" - << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << "," - << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << "), with profilName " - << profilName << " on mesh " << meshName - ) - ); + if ( !isFullInterlace ) + delete myField; + throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<": Error while writing "<< numberOfElements + << " values for FIELD "<< fieldName + << " on entity " << MED_EN::entNames[entityType] + << " and geometric type " << MED_EN::geoNames[types[typeNo]] + << " with (it,or) = (" + << MED_FIELD_DRIVER<T>::_ptrField->_iterationNumber << "," + << MED_FIELD_DRIVER<T>::_ptrField->_orderNumber << "), with profilName " + << profilName << " on mesh " << meshName + ) + ); } index += numberOfElements ; //Ne doit pas prendre en compte le nombre de points de GAUSS //ni les composantes. } - if ( MED_FIELD_DRIVER<T>::_ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) delete myField; + if ( !isFullInterlace ) delete myField; END_OF(LOC); diff --git a/src/MEDMEM/MEDMEM_MedMedDriver.cxx b/src/MEDMEM/MEDMEM_MedMedDriver.cxx index 046ace5c7..b85952ebf 100644 --- a/src/MEDMEM/MEDMEM_MedMedDriver.cxx +++ b/src/MEDMEM/MEDMEM_MedMedDriver.cxx @@ -64,18 +64,18 @@ MED_MED_DRIVER::~MED_MED_DRIVER() // ------------- Read Only Part -------------- -IMED_MED_RDONLY_DRIVER::IMED_MED_RDONLY_DRIVER():MED_MED_DRIVER() +IMED_MED_RDONLY_DRIVER::IMED_MED_RDONLY_DRIVER():MED_MED_DRIVER(),_fileStructIsRead(false) { } IMED_MED_RDONLY_DRIVER::IMED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed): - MED_MED_DRIVER(fileName,ptrMed,MED_EN::MED_RDONLY) + MED_MED_DRIVER(fileName,ptrMed,MED_EN::MED_RDONLY),_fileStructIsRead(false) { MESSAGE("MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed) Constructeur read only"); } IMED_MED_RDONLY_DRIVER::IMED_MED_RDONLY_DRIVER(const IMED_MED_RDONLY_DRIVER & driver): - MED_MED_DRIVER(driver) + MED_MED_DRIVER(driver),_fileStructIsRead(false) { } @@ -150,7 +150,7 @@ MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER() _concreteMedDrv = new MED_MED_RDONLY_DRIVER21(); } -MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed) +MED_MED_RDONLY_DRIVER::MED_MED_RDONLY_DRIVER(const string & fileName, MED * const ptrMed):IMED_MED_RDONLY_DRIVER(fileName,ptrMed),MED_MED_DRIVER(fileName,ptrMed,MED_LECT) { _concreteMedDrv = DRIVERFACTORY::buildMedDriverFromFile(fileName,ptrMed,MED_LECT); } @@ -204,7 +204,7 @@ MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER() _concreteMedDrv = new MED_MED_WRONLY_DRIVER21(); } -MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName, MED * const ptrMed) +MED_MED_WRONLY_DRIVER::MED_MED_WRONLY_DRIVER(const string & fileName, MED * const ptrMed):IMED_MED_WRONLY_DRIVER(fileName,ptrMed),MED_MED_DRIVER(fileName,ptrMed,MED_ECRI) { _concreteMedDrv = DRIVERFACTORY::buildMedDriverFromFile(fileName,ptrMed,MED_ECRI); } @@ -258,7 +258,7 @@ MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER() _concreteMedDrv = new MED_MED_RDWR_DRIVER21(); } -MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName, MED * const ptrMed) +MED_MED_RDWR_DRIVER::MED_MED_RDWR_DRIVER(const string & fileName, MED * const ptrMed):IMED_MED_RDWR_DRIVER(fileName,ptrMed),MED_MED_DRIVER(fileName,ptrMed,MED_REMP) { _concreteMedDrv = DRIVERFACTORY::buildMedDriverFromFile(fileName,ptrMed,MED_REMP); } diff --git a/src/MEDMEM/MEDMEM_MedMedDriver.hxx b/src/MEDMEM/MEDMEM_MedMedDriver.hxx index 859941536..007d1fa91 100644 --- a/src/MEDMEM/MEDMEM_MedMedDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedMedDriver.hxx @@ -20,6 +20,8 @@ #ifndef MED_MED_DRIVER_HXX #define MED_MED_DRIVER_HXX +#include "MEDMEM.hxx" + #include <string> #include "MEDMEM_STRING.hxx" #include "MEDMEM_Utilities.hxx" @@ -41,7 +43,7 @@ class MESH; class FIELD_; class MED; -class MED_MED_DRIVER : public GENDRIVER +class MEDMEM_EXPORT MED_MED_DRIVER : public GENDRIVER { protected: @@ -97,7 +99,7 @@ protected: */ -class IMED_MED_RDONLY_DRIVER : public virtual MED_MED_DRIVER +class MEDMEM_EXPORT IMED_MED_RDONLY_DRIVER : public virtual MED_MED_DRIVER { public : /*! @@ -126,6 +128,10 @@ public : Return a MEDEXCEPTION : it is the read-only driver. */ void writeFrom ( void ) const throw (MEDEXCEPTION) ; + +protected: + // PAL14192: to allow painless repeated readFileStruct() calls + bool _fileStructIsRead; }; /*! @@ -136,7 +142,7 @@ public : */ -class IMED_MED_WRONLY_DRIVER : public virtual MED_MED_DRIVER +class MEDMEM_EXPORT IMED_MED_WRONLY_DRIVER : public virtual MED_MED_DRIVER { public : @@ -177,7 +183,7 @@ public : */ -class IMED_MED_RDWR_DRIVER : public virtual IMED_MED_RDONLY_DRIVER, +class MEDMEM_EXPORT IMED_MED_RDWR_DRIVER : public virtual IMED_MED_RDONLY_DRIVER, public virtual IMED_MED_WRONLY_DRIVER { @@ -202,7 +208,7 @@ public : }; -class MED_MED_RDONLY_DRIVER : public virtual IMED_MED_RDONLY_DRIVER +class MEDMEM_EXPORT MED_MED_RDONLY_DRIVER : public virtual IMED_MED_RDONLY_DRIVER { public : MED_MED_RDONLY_DRIVER(); @@ -219,7 +225,7 @@ private: GENDRIVER * copy ( void ) const; }; -class MED_MED_WRONLY_DRIVER : public virtual IMED_MED_WRONLY_DRIVER +class MEDMEM_EXPORT MED_MED_WRONLY_DRIVER : public virtual IMED_MED_WRONLY_DRIVER { public : @@ -237,7 +243,7 @@ private: GENDRIVER * copy ( void ) const; }; -class MED_MED_RDWR_DRIVER : public IMED_MED_RDWR_DRIVER +class MEDMEM_EXPORT MED_MED_RDWR_DRIVER : public IMED_MED_RDWR_DRIVER { public : diff --git a/src/MEDMEM/MEDMEM_MedMedDriver21.cxx b/src/MEDMEM/MEDMEM_MedMedDriver21.cxx index 33877cb56..4ec9be490 100644 --- a/src/MEDMEM/MEDMEM_MedMedDriver21.cxx +++ b/src/MEDMEM/MEDMEM_MedMedDriver21.cxx @@ -107,9 +107,9 @@ void MED_MED_DRIVER21::open() << "_fileName is |\"\"|, please set a correct fileName before calling open()" ) ); - - MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); - _medIdt = med_2_1::MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_1::med_mode_acces) _accessMode); + int accessMode = getMedAccessMode( _accessMode, MED_EN::V21 ); + MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode); + _medIdt = med_2_1::MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_1::med_mode_acces) accessMode); MESSAGE(LOC<<" _medIdt = "<<_medIdt); if (_medIdt > 0) @@ -205,6 +205,12 @@ void MED_MED_RDONLY_DRIVER21::readFileStruct( void ) const char * LOC = "MED_MED_DRIVER21::readFileStruct() : "; int err,i,j; + // PAL12192 + if ( IMED_MED_RDONLY_DRIVER::_fileStructIsRead ) + return; + else + IMED_MED_RDONLY_DRIVER::_fileStructIsRead = true; + BEGIN_OF(LOC); if ( _medIdt == MED_INVALID ) @@ -291,6 +297,9 @@ void MED_MED_RDONLY_DRIVER21::readFileStruct( void ) ptrMesh->setName(meshName); + // add by B. Secher for filter module + ptrMesh->setMeshDimension(meshDim); + SCRUTE(ptrMesh); MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName()); @@ -352,7 +361,8 @@ void MED_MED_RDONLY_DRIVER21::readFileStruct( void ) { int numberOfFields = 0; //MED_INVALID // char fieldName[MED_TAILLE_NOM+1] = ""; - char fieldName[MED_TAILLE_NOM+1] ; + // char fieldName[MED_TAILLE_NOM+1] ; + char fieldName[MED_TAILLE_LNOM+1] ; //SRN: to avoid a crash if the field name is longer than MED_TAILLE_NOM int numberOfComponents = 0; char * componentName = (char *) MED_NULL; char * unitName = (char *) MED_NULL; @@ -388,9 +398,9 @@ void MED_MED_RDONLY_DRIVER21::readFileStruct( void ) numberOfComponents = med_2_1::MEDnChamp(_medIdt,i) ; if ( numberOfComponents <= 0 ) if (err != MED_VALID) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Be careful there is no compound for field n°" + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Be careful there is no compound for field n°" << i << "in file |"<<_fileName<<"| !")); - + componentName = new char[numberOfComponents*MED_TAILLE_PNOM21+1] ; unitName = new char[numberOfComponents*MED_TAILLE_PNOM21+1] ; @@ -473,8 +483,8 @@ void MED_MED_RDONLY_DRIVER21::readFileStruct( void ) ptrMesh = _meshes[meshName]; ptrSupport = support[meshName][(MED_EN::medEntityMesh) (*currentEntity).first]; - if (NbOfGaussPts != 1) - throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ; +// if (NbOfGaussPts != 1) +// throw MEDEXCEPTION(LOCALIZED( STRING(LOC) <<"Number of Gauss Point must be equal to 1 for instance")) ; // init to null to prevent some error if not correctly allocated ! ptrField = (FIELD_*)NULL ; @@ -614,6 +624,11 @@ void MED_MED_RDONLY_DRIVER21::read( void ) BEGIN_OF(LOC); + // For PAL12192: assure that file structure is already read + this->open(); + this->readFileStruct(); + this->close(); + const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); map<MESH_NAME_,MESH*>::const_iterator currentMesh; @@ -688,7 +703,7 @@ void MED_MED_WRONLY_DRIVER21::writeFrom( void) const (*currentMesh).second->write(*this); // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id } - catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) { + catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) { continue; } } @@ -697,7 +712,7 @@ void MED_MED_WRONLY_DRIVER21::writeFrom( void) const try { (*currentField).first->write(*this); } - catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) { + catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) { continue; } } diff --git a/src/MEDMEM/MEDMEM_MedMedDriver22.cxx b/src/MEDMEM/MEDMEM_MedMedDriver22.cxx index 1f245754a..c039eeaf6 100644 --- a/src/MEDMEM/MEDMEM_MedMedDriver22.cxx +++ b/src/MEDMEM/MEDMEM_MedMedDriver22.cxx @@ -112,9 +112,10 @@ void MED_MED_DRIVER22::open() ) ); - MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); + int accessMode = getMedAccessMode( _accessMode, MED_EN::V22 ); + MESSAGE(LOC<<"_fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode); - _medIdt = med_2_2::MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_2::med_mode_acces) _accessMode); + _medIdt = med_2_3::MEDouvrir( (const_cast <char *> (_fileName.c_str())), (med_2_3::med_mode_acces) accessMode); MESSAGE(LOC<<" _medIdt = "<<_medIdt); if (_medIdt > 0) @@ -135,7 +136,7 @@ void MED_MED_DRIVER22::open() void MED_MED_DRIVER22::close() { - med_2_2::med_int err = 0; + med_2_3::med_int err = 0; const char * LOC = "MED_MED_DRIVER22::close() : "; @@ -152,7 +153,7 @@ void MED_MED_DRIVER22::close() // ); if ( _medIdt != MED_INVALID ) - err=med_2_2::MEDfermer(_medIdt); + err=med_2_3::MEDfermer(_medIdt); // if (err != MED_VALID) // throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "the file |" @@ -209,7 +210,13 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) { const char * LOC = "MED_MED_DRIVER22::readFileStruct() : "; int err,i,j; - + + // PAL12192 + if ( IMED_MED_RDONLY_DRIVER::_fileStructIsRead ) + return; + else + IMED_MED_RDONLY_DRIVER::_fileStructIsRead = true; + BEGIN_OF(LOC); if ( _medIdt == MED_INVALID ) @@ -224,13 +231,13 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) char meshName[MED_TAILLE_NOM+1]=""; char meshDescription[MED_TAILLE_DESC+1]=""; //CCRT int meshDim; - med_2_2::med_int meshDim; - med_2_2::med_maillage meshType; + med_2_3::med_int meshDim; + med_2_3::med_maillage meshType; MESH * ptrMesh; // MED_MESH_RDWR_DRIVER * ptrDriver; !! UNUSED VARIABLE !! - numberOfMeshes = med_2_2::MEDnMaa(_medIdt) ; + numberOfMeshes = med_2_3::MEDnMaa(_medIdt) ; if ( numberOfMeshes <= 0 ) MESSAGE(LOC << "Be careful there is no mesh in file |"<<_fileName<<"| !"); @@ -247,10 +254,10 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) switch (meshType) { - case med_2_2::MED_STRUCTURE: + case med_2_3::MED_STRUCTURE: MESSAGE(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is structured"); - med_2_2::med_type_grille type; + med_2_3::med_type_grille type; err = MEDnatureGrilleLire(_medIdt, meshName, &type); @@ -259,7 +266,7 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) ptrMesh = new GRID((MED_EN::med_grid_type) type); break; - case med_2_2::MED_NON_STRUCTURE: + case med_2_3::MED_NON_STRUCTURE: MESSAGE(LOC<<": Mesh n°"<< i <<" nammed "<< meshName << " with the description " << meshDescription << " is not structured"); ptrMesh = new MESH(); @@ -307,6 +314,9 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) ptrMesh->setDescription(meshDescription); + // add by B. Secher for filter module + ptrMesh->setMeshDimension(meshDim); + SCRUTE(ptrMesh); MESSAGE(LOC<<"is" << (isAGrid ? "" : " NOT") << " a GRID and its name is "<<ptrMesh->getName()); @@ -374,13 +384,13 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) { int numberOfFields = 0; //MED_INVALID // char fieldName[MED_TAILLE_NOM+1] = ""; - char fieldName[MED_TAILLE_NOM+1] ; + char fieldName[MED_TAILLE_LNOM+1] ; // to avoid a crash if the field name is longer than MED_TAILLE_NOM int numberOfComponents = 0; char * componentName = (char *) MED_NULL; char * unitName = (char *) MED_NULL; // char meshName[MED_TAILLE_NOM+1] = ""; char meshName[MED_TAILLE_NOM+1] ; - med_2_2::med_type_champ type; + med_2_3::med_type_champ type; MESH * ptrMesh = (MESH *) MED_NULL; FIELD_ * ptrField = (FIELD_ *) MED_NULL; //MED_FIELD_RDWR_DRIVER * ptrDriver = (MED_FIELD_RDWR_DRIVER * ) MED_NULL; @@ -388,30 +398,30 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) SUPPORT * ptrSupport = (SUPPORT * ) MED_NULL; MESH_ENTITIES::const_iterator currentEntity; list<MED_EN::medGeometryElement>::const_iterator currentGeometry; - med_2_2::med_int NbOfGaussPts = 0; + med_2_3::med_int NbOfGaussPts = 0; int numberOfTimeSteps = -1; - med_2_2::med_int timeStepNumber = -1; + med_2_3::med_int timeStepNumber = -1; // char timeStepUnit[MED_TAILLE_PNOM]= ""; char timeStepUnit[MED_TAILLE_PNOM22+1] ; double timeStep = 0.0; //CCRT int orderNumber = -1; //???init????? - med_2_2::med_int orderNumber = -1; //???init????? + med_2_3::med_int orderNumber = -1; //???init????? //CCRT int numberOfRefMesh = 0; - med_2_2::med_int numberOfRefMesh = 0; - med_2_2::med_booleen meshLink; + med_2_3::med_int numberOfRefMesh = 0; + med_2_3::med_booleen meshLink; map<MESH_NAME_,MESH*> & _meshes = _ptrMed->_meshes; map<FIELD_NAME_,MAP_DT_IT_> & _fields = _ptrMed->_fields; map<FIELD_ *, MESH_NAME_> & _meshName = _ptrMed->_meshName; map<MESH_NAME_, map<MED_EN::medEntityMesh,SUPPORT *> > & support = _ptrMed->_support; - numberOfFields = med_2_2::MEDnChamp(_medIdt,0) ; + numberOfFields = med_2_3::MEDnChamp(_medIdt,0) ; if ( numberOfFields <= 0 ) MESSAGE(LOC << "Be careful there is no field in file |"<< _fileName<<"| !"); for (i=1;i<=numberOfFields;i++) { - numberOfComponents = med_2_2::MEDnChamp(_medIdt,i) ; + numberOfComponents = med_2_3::MEDnChamp(_medIdt,i) ; if ( numberOfComponents <= 0 ) if (err != MED_VALID) @@ -423,6 +433,10 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) err = MEDchampInfo(_medIdt, i, fieldName, &type, componentName, unitName, numberOfComponents) ; + MESSAGE("Field n°" << i << " nammed " << fieldName << endl + << "Name real length = " << strlen(fieldName) + << ", while reserved " << MED_TAILLE_NOM); + if (err != MED_VALID) throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get information about the field n°" << i <<" of the file |" << _fileName << "| !")); @@ -449,8 +463,8 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) numberOfTimeSteps = MEDnPasdetemps(_medIdt, fieldName, - (med_2_2::med_entite_maillage)(*currentEntity).first, - (med_2_2::med_geometrie_element) (*currentGeometry) ); + (med_2_3::med_entite_maillage)(*currentEntity).first, + (med_2_3::med_geometrie_element) (*currentGeometry) ); MESSAGE("Field information 2 : NumberOfTimeStep :"<< numberOfTimeSteps); @@ -473,15 +487,15 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) MESSAGE("Field information 4 : time step j = "<<j); // err = MEDpasdetempsInfo( _medIdt, fieldName, - // (med_2_2::med_entite_maillage) (*currentEntity).first, + // (med_2_3::med_entite_maillage) (*currentEntity).first, // (*currentGeometry),j, meshName, // &NbOfGaussPts, &timeStepNumber, // timeStepUnit, &timeStep, &orderNumber); err = MEDpasdetempsInfo(_medIdt, fieldName, - (med_2_2::med_entite_maillage) + (med_2_3::med_entite_maillage) (*currentEntity).first, - (med_2_2::med_geometrie_element) + (med_2_3::med_geometrie_element) (*currentGeometry),j, &NbOfGaussPts, &timeStepNumber, &orderNumber, timeStepUnit, @@ -497,7 +511,7 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) if (timeStepNumber<0) timeStepNumber=-1 ; if ((numberOfRefMesh != 1) || - (meshLink != med_2_2::MED_VRAI) || + (meshLink != med_2_3::MED_VRAI) || (NbOfGaussPts != 1)) { NbOfGaussPts = 1; @@ -525,7 +539,7 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) "|, but |" << meshName << "| is referenced by field |" << fieldName <<"|, entity : |" << - entNames[ (med_2_2::med_entite_maillage) + entNames[ (med_2_3::med_entite_maillage) (*currentEntity).first] << "|, geometric element of type |" << geoNames [(*currentGeometry)] <<"|"); @@ -546,11 +560,11 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) ptrDriver = (GENDRIVER*)NULL ; switch ( type) { - case med_2_2::MED_INT64 : - if ( sizeof(med_2_2::med_int) != 8 ) - throw MED_EXCEPTION(LOCALIZED(STRING(LOC) <<" The Field type of |" << fieldName <<"|, entity : |" << entNames[(med_2_2::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(*currentGeometry)] << "| is MED_INT64 but size of med_int is not equal to 8 bytes !")); + case med_2_3::MED_INT64 : + if ( sizeof(med_2_3::med_int) != 8 ) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) <<" The Field type of |" << fieldName <<"|, entity : |" << entNames[(med_2_3::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(*currentGeometry)] << "| is MED_INT64 but size of med_int is not equal to 8 bytes !")); break; - case med_2_2::MED_INT32 : { + case med_2_3::MED_INT32 : { ptrField = new FIELD<int> ( ); // Les valeurs du champ ne doivent pas ĂƒÂªtre lue // pour l'instant @@ -638,7 +652,7 @@ void MED_MED_RDONLY_DRIVER22::readFileStruct( void ) } default : { if ( numberOfTimeSteps > 1) - throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << " The Field type of |" << fieldName <<"|, entity : |" << entNames[(med_2_2::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(*currentGeometry)] <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !")); + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << " The Field type of |" << fieldName <<"|, entity : |" << entNames[(med_2_3::med_entite_maillage) (*currentEntity).first] <<"|, geometric element of type |" << geoNames [(*currentGeometry)] <<"| is neither MED_INT, MED_INT32, MED_INT64 nor MED_REEL64 !")); break ; } } @@ -693,6 +707,11 @@ void MED_MED_RDONLY_DRIVER22::read( void ) BEGIN_OF(LOC); + // For PAL12192: assure that file structure is already read + this->open(); + this->readFileStruct(); + this->close(); + const map<MESH_NAME_, MESH*> & _meshes = const_cast<const map<MESH_NAME_, MESH*>& > (_ptrMed->_meshes); map<MESH_NAME_,MESH*>::const_iterator currentMesh; @@ -769,7 +788,7 @@ void MED_MED_WRONLY_DRIVER22::writeFrom( void) const (*currentMesh).second->write(*this); // On utilise pour les objects MESH ET FIELD le write(GENDRIVER *) et le == ds GENDRIVER avec eventuellement 1 id } - catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) { + catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) { continue; } } @@ -778,7 +797,7 @@ void MED_MED_WRONLY_DRIVER22::writeFrom( void) const try { (*currentField).first->write(*this); } - catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ex ) { + catch ( const MED_DRIVER_NOT_FOUND_EXCEPTION & ) { continue; } } diff --git a/src/MEDMEM/MEDMEM_MedMedDriver22.hxx b/src/MEDMEM/MEDMEM_MedMedDriver22.hxx index 7bcf7d184..f8fa0e400 100644 --- a/src/MEDMEM/MEDMEM_MedMedDriver22.hxx +++ b/src/MEDMEM/MEDMEM_MedMedDriver22.hxx @@ -45,7 +45,7 @@ class MED_MED_DRIVER22 : public virtual MED_MED_DRIVER { protected: - med_2_2::med_idt _medIdt; // The _medIdt used to write/read Meshes to ::_filename + med_2_3::med_idt _medIdt; // The _medIdt used to write/read Meshes to ::_filename //private: // MED_MED_DRIVER(); diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx index a8c1d312f..983798b92 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx @@ -175,8 +175,9 @@ IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER() } IMED_MESH_WRONLY_DRIVER::IMED_MESH_WRONLY_DRIVER(const string & fileName, - MESH * ptrMesh): - MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY) + MESH * ptrMesh, + MED_EN::med_mode_acces access): + MED_MESH_DRIVER(fileName,ptrMesh,access) { MESSAGE("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created"); } @@ -226,7 +227,8 @@ MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER() _concreteMeshDrv = new MED_MESH_RDONLY_DRIVER21(); } -MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) +MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh): + IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_LECT) { _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_LECT); } @@ -246,6 +248,20 @@ void MED_MESH_RDONLY_DRIVER::write( void ) const _concreteMeshDrv->write(); } +void MED_MESH_RDONLY_DRIVER::activateFacesComputation() +{ + IMED_MESH_RDONLY_DRIVER *drvC=dynamic_cast<IMED_MESH_RDONLY_DRIVER *>(_concreteMeshDrv); + if(drvC) + drvC->activateFacesComputation(); +} + +void MED_MESH_RDONLY_DRIVER::desactivateFacesComputation() +{ + IMED_MESH_RDONLY_DRIVER *drvC=dynamic_cast<IMED_MESH_RDONLY_DRIVER *>(_concreteMeshDrv); + if(drvC) + drvC->desactivateFacesComputation(); +} + void MED_MESH_RDONLY_DRIVER::read ( void ) { _concreteMeshDrv->read(); @@ -268,7 +284,7 @@ void MED_MESH_RDONLY_DRIVER::setMeshName(const string & meshName) string MED_MESH_RDONLY_DRIVER::getMeshName() const { - return MED_MESH_DRIVER::getMeshName(); + return _concreteMeshDrv->getMeshName(); } GENDRIVER * MED_MESH_RDONLY_DRIVER::copy ( void ) const @@ -322,9 +338,10 @@ MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER() _concreteMeshDrv = new MED_MESH_WRONLY_DRIVER21(); } -MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) +MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces access): + IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,access) { - _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_ECRI); + _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,access); } MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver):MED_MESH_DRIVER(driver) @@ -354,7 +371,7 @@ void MED_MESH_WRONLY_DRIVER::setMeshName(const string & meshName) string MED_MESH_WRONLY_DRIVER::getMeshName() const { - return MED_MESH_DRIVER::getMeshName(); + return _concreteMeshDrv->getMeshName(); } GENDRIVER * MED_MESH_WRONLY_DRIVER::copy ( void ) const @@ -362,12 +379,12 @@ GENDRIVER * MED_MESH_WRONLY_DRIVER::copy ( void ) const return new MED_MESH_WRONLY_DRIVER(*this); } -void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::read ( void ) +void MED_MESH_WRONLY_DRIVER::read () { _concreteMeshDrv->read(); } -void MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER::write( void ) const +void MED_MESH_WRONLY_DRIVER::write( void ) const { _concreteMeshDrv->write(); } @@ -402,7 +419,8 @@ MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER() _concreteMeshDrv=new MED_MESH_RDWR_DRIVER21(); } -MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) +MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh): + IMED_MESH_RDWR_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_REMP) { _concreteMeshDrv = DRIVERFACTORY::buildMeshDriverFromFile(fileName,ptrMesh,MED_REMP); } @@ -427,6 +445,20 @@ void MED_MESH_RDWR_DRIVER::write( void ) const _concreteMeshDrv->write(); } +void MED_MESH_RDWR_DRIVER::activateFacesComputation() +{ + IMED_MESH_RDONLY_DRIVER *drvC=dynamic_cast<IMED_MESH_RDONLY_DRIVER *>(_concreteMeshDrv); + if(drvC) + drvC->activateFacesComputation(); +} + +void MED_MESH_RDWR_DRIVER::desactivateFacesComputation() +{ + IMED_MESH_RDONLY_DRIVER *drvC=dynamic_cast<IMED_MESH_RDONLY_DRIVER *>(_concreteMeshDrv); + if(drvC) + drvC->desactivateFacesComputation(); +} + void MED_MESH_RDWR_DRIVER::open() { _concreteMeshDrv->open(); @@ -509,7 +541,7 @@ void MED_MESH_RDWR_DRIVER::setMeshName(const string & meshName) string MED_MESH_RDWR_DRIVER::getMeshName() const { - return MED_MESH_DRIVER::getMeshName(); + return _concreteMeshDrv->getMeshName(); } GENDRIVER * MED_MESH_RDWR_DRIVER::copy ( void ) const diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver.hxx b/src/MEDMEM/MEDMEM_MedMeshDriver.hxx index 757082dc0..3bdc41744 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver.hxx @@ -20,6 +20,8 @@ #ifndef MED_MESH_DRIVER_HXX #define MED_MESH_DRIVER_HXX +#include <MEDMEM.hxx> + #include <string> #include <vector> #include "MEDMEM_define.hxx" @@ -42,7 +44,7 @@ class MESH; class FAMILY; class GROUP; class CONNECTIVITY; -class MED_MESH_DRIVER : public GENDRIVER +class MEDMEM_EXPORT MED_MESH_DRIVER : public GENDRIVER { protected: @@ -103,7 +105,7 @@ public: */ - class IMED_MESH_RDONLY_DRIVER : public virtual MED_MESH_DRIVER +class MEDMEM_EXPORT IMED_MESH_RDONLY_DRIVER : public virtual MED_MESH_DRIVER { public : @@ -126,6 +128,8 @@ public : Return a MEDEXCEPTION : it is the read-only driver. */ void write( void ) const; + virtual void activateFacesComputation() = 0; + virtual void desactivateFacesComputation() = 0; protected: // virtual int getCOORDINATE() = 0 ; @@ -151,7 +155,7 @@ protected: */ -class IMED_MESH_WRONLY_DRIVER : public virtual MED_MESH_DRIVER { +class MEDMEM_EXPORT IMED_MESH_WRONLY_DRIVER : public virtual MED_MESH_DRIVER { public : @@ -162,7 +166,7 @@ public : /*! Constructor. */ - IMED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) ; + IMED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces access=MED_EN::MED_WRONLY) ; /*! Copy constructor. */ @@ -197,7 +201,7 @@ public : */ -class IMED_MESH_RDWR_DRIVER : public virtual IMED_MESH_RDONLY_DRIVER, public virtual IMED_MESH_WRONLY_DRIVER { +class MEDMEM_EXPORT IMED_MESH_RDWR_DRIVER : public virtual IMED_MESH_RDONLY_DRIVER, public virtual IMED_MESH_WRONLY_DRIVER { public : @@ -223,7 +227,7 @@ public : }; -class MED_MESH_RDONLY_DRIVER : public virtual IMED_MESH_RDONLY_DRIVER +class MEDMEM_EXPORT MED_MESH_RDONLY_DRIVER : public virtual IMED_MESH_RDONLY_DRIVER { public: MED_MESH_RDONLY_DRIVER(); @@ -233,6 +237,8 @@ public: void setMeshName(const string & meshName); string getMeshName() const; void write( void ) const; + void activateFacesComputation(); + void desactivateFacesComputation(); void read ( void ); void open(); void close(); @@ -249,10 +255,10 @@ protected: GENDRIVER * copy ( void ) const; }; -class MED_MESH_WRONLY_DRIVER : public virtual IMED_MESH_WRONLY_DRIVER { +class MEDMEM_EXPORT MED_MESH_WRONLY_DRIVER : public virtual IMED_MESH_WRONLY_DRIVER { public : MED_MESH_WRONLY_DRIVER(); - MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh); + MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces access=MED_EN::MED_ECRI); MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver); ~MED_MESH_WRONLY_DRIVER(); void setMeshName(const string & meshName); @@ -271,7 +277,7 @@ protected: GENDRIVER * copy ( void ) const; }; -class MED_MESH_RDWR_DRIVER : public IMED_MESH_RDWR_DRIVER { +class MEDMEM_EXPORT MED_MESH_RDWR_DRIVER : public IMED_MESH_RDWR_DRIVER { public : MED_MESH_RDWR_DRIVER(); MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh); @@ -281,6 +287,8 @@ public : string getMeshName() const; void read ( void ); void write( void ) const; + void activateFacesComputation(); + void desactivateFacesComputation(); void open(); void close(); protected: diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver21.cxx b/src/MEDMEM/MEDMEM_MedMeshDriver21.cxx index ece84c82a..ea6624017 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver21.cxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver21.cxx @@ -28,6 +28,7 @@ #include "MEDMEM_Mesh.hxx" #include "MEDMEM_CellModel.hxx" #include "MEDMEM_Grid.hxx" +#include "MEDMEM_MedVersion.hxx" using namespace std; @@ -67,8 +68,9 @@ void MED_MESH_DRIVER21::open() { const char * LOC = "MED_MESH_DRIVER21::open()" ; BEGIN_OF(LOC); - MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); - _medIdt = med_2_1::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_1::med_mode_acces) _accessMode); + int accessMode = getMedAccessMode( _accessMode, MED_EN::V21 ); + MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode); + _medIdt = med_2_1::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_1::med_mode_acces) accessMode); MESSAGE(LOC<<" _medIdt : "<< _medIdt ); if (_medIdt > 0) _status = MED_OPENED; @@ -117,19 +119,25 @@ const char * const MED_MESH_DRIVER21::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILL //---------------------------------- RDONLY PART ------------------------------------------------------------- -MED_MESH_RDONLY_DRIVER21::MED_MESH_RDONLY_DRIVER21() +MED_MESH_RDONLY_DRIVER21::MED_MESH_RDONLY_DRIVER21():_computeFaces(true) { } MED_MESH_RDONLY_DRIVER21::MED_MESH_RDONLY_DRIVER21(const string & fileName, MESH * ptrMesh): - IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER21(fileName,ptrMesh,MED_RDONLY),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY) + IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh), + MED_MESH_DRIVER21(fileName,ptrMesh,MED_RDONLY), + MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY), + _computeFaces(true) { MESSAGE("MED_MESH_RDONLY_DRIVER21::MED_MESH_RDONLY_DRIVER21(const string & fileName, MESH * ptrMesh) has been created"); } MED_MESH_RDONLY_DRIVER21::MED_MESH_RDONLY_DRIVER21(const MED_MESH_RDONLY_DRIVER21 & driver): - IMED_MESH_RDONLY_DRIVER(driver),MED_MESH_DRIVER21(driver),MED_MESH_DRIVER(driver) + IMED_MESH_RDONLY_DRIVER(driver), + MED_MESH_DRIVER21(driver), + MED_MESH_DRIVER(driver), + _computeFaces(driver._computeFaces) { } @@ -157,17 +165,7 @@ void MED_MESH_RDONLY_DRIVER21::read(void) if (_ptrMesh->getIsAGrid()) { getGRID( ); - - // always call getFAMILY : families are requiered !!!! - -// int nbFam = MEDnFam(_medIdt, -// const_cast <char *> (_meshName.c_str()), -// 0, -// med_2_1::MED_FAMILLE); -// if (nbFam > 0) { -// getFAMILY(); - if (getFAMILY()!=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ; @@ -177,6 +175,27 @@ void MED_MESH_RDONLY_DRIVER21::read(void) END_OF(LOC); return; } + else // check that the mesh is really unstructured (PAL14113) + { + char meshName[MED_TAILLE_NOM+1]=""; + char meshDescription[MED_TAILLE_DESC+1]=""; + med_2_3::med_int meshDim; + med_2_3::med_maillage meshType; + int numberOfMeshes = med_2_3::MEDnMaa(_medIdt); + for (int i=1;i<=numberOfMeshes;i++) + { + MEDmaaInfo(_medIdt, i ,meshName, &meshDim, &meshType, meshDescription); + if (_meshName == string(meshName)) { + if ( meshType == med_2_3::MED_STRUCTURE ) { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << + "class GRID must be used for a structured mesh")); + } + else { + break; + } + } + } + } if (getCOORDINATE()!=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" )) ; @@ -186,8 +205,9 @@ void MED_MESH_RDONLY_DRIVER21::read(void) if (getFAMILY()!=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY" )) ; - - updateFamily(); + + if (_computeFaces) + updateFamily(); // we build all groups // on node @@ -198,7 +218,8 @@ void MED_MESH_RDONLY_DRIVER21::read(void) if (_ptrMesh->_meshDimension == 3) // on face buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ; - else if (_ptrMesh->_meshDimension == 2) +// else if (_ptrMesh->_meshDimension == 2) -- PAL13414 + if (_ptrMesh->_meshDimension > 1) // on edge buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ; @@ -517,7 +538,7 @@ int MED_MESH_RDONLY_DRIVER21::getCOORDINATE() // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !"); _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) for(med_2_1::med_int i2=0;i2<NumberOfNodes;i2++) _ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]); #else @@ -1288,7 +1309,7 @@ int MED_MESH_RDONLY_DRIVER21::getFAMILY() // node int NumberOfNodes = _ptrMesh->getNumberOfNodes() ; MEDArrayNodeFamily = new int[ NumberOfNodes ]; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) med_2_1::med_int* MEDArrayNodeFamily2 = new med_2_1::med_int[ NumberOfNodes ]; err = med_2_1::MEDfamGridLire (_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), @@ -1327,11 +1348,11 @@ int MED_MESH_RDONLY_DRIVER21::getFAMILY() for (int i=0;i<NumberOfFamilies;i++) { - med_2_1::med_int NumberOfAttributes = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,med_2_1::MED_ATTR) ; + med_2_1::med_int NumberOfAttributes = med_2_1::MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,med_2_1::MED_ATTR) ; if (NumberOfAttributes < 0) throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER21::getFAMILY() : NumberOfAttributes" ); - med_2_1::med_int NumberOfGroups = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,med_2_1::MED_GROUPE) ; + med_2_1::med_int NumberOfGroups = med_2_1::MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,med_2_1::MED_GROUPE) ; if (NumberOfGroups < 0) throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER21::getFAMILY() : NumberOfGroups" ); @@ -1341,7 +1362,7 @@ int MED_MESH_RDONLY_DRIVER21::getFAMILY() int * AttributesValues = new int[NumberOfAttributes] ; string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ; string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) med_2_1::med_int tmp_NumberOfAttributes=NumberOfAttributes; med_2_1::med_int * AttributesIdentifier2 = new med_2_1::med_int[NumberOfAttributes] ; med_2_1::med_int * AttributesValues2 = new med_2_1::med_int[NumberOfAttributes] ; @@ -1458,7 +1479,7 @@ int MED_MESH_RDONLY_DRIVER21::getNodesFamiliesNumber(int * MEDArrayNodeFamily) BEGIN_OF(LOC); if (_status==MED_OPENED) { int err = 0 ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=_ptrMesh->getNumberOfNodes(); med_2_1::med_int *temp=new med_2_1::med_int[lgth]; err = MEDfamLire(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())), @@ -1496,7 +1517,7 @@ int MED_MESH_RDONLY_DRIVER21::getCellsFamiliesNumber(int **MEDArrayFamily, int i, err = 0 ; for (i=0;i<Connectivity->_numberOfTypes;i++) { int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) const medGeometryElement * myTypes = _ptrMesh->getTypes(entity); int lgthI=_ptrMesh->getNumberOfElements(entity,myTypes[i]); med_2_1::med_int *temp=new med_2_1::med_int[lgthI]; @@ -1517,7 +1538,7 @@ int MED_MESH_RDONLY_DRIVER21::getCellsFamiliesNumber(int **MEDArrayFamily, // provisoire : si les faces ou les aretes sont des mailles !!! if (err != MED_VALID) { MESSAGE(LOC<<"search face/edge family on cell !!!"); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgthI=_ptrMesh->getNumberOfElements(entity,myTypes[i]); med_2_1::med_int *temp=new med_2_1::med_int[lgthI]; err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), @@ -1737,7 +1758,7 @@ int MED_MESH_WRONLY_DRIVER21::writeGRID() const med_2_1::med_int * MEDArrayNodeFamily = new med_2_1::med_int[_ptrMesh->_numberOfNodes] ; err = MEDbodyFittedEcr (_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), + const_cast <char *> (_meshName.c_str()), _ptrMesh->_spaceDimension, coo, ArrayLen, @@ -1765,7 +1786,7 @@ int MED_MESH_WRONLY_DRIVER21::writeGRID() const for (idim = 0; idim < _ptrMesh->_spaceDimension; ++idim) { err = med_2_1::MEDgridEcr (_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), + const_cast <char *> (_meshName.c_str()), _ptrMesh->_spaceDimension, Array [idim], ArrayLen [idim], @@ -1781,7 +1802,7 @@ int MED_MESH_WRONLY_DRIVER21::writeGRID() const } // err = MEDfamGridEcr(_medIdt, -// const_cast <char *> (_ptrMesh->_name.c_str()), +// const_cast <char *> (_meshName.c_str()), // _ptrMesh->_MEDArrayNodeFamily, // _ptrMesh->_numberOfNodes, // med_2_1::MED_REMP, @@ -1881,7 +1902,7 @@ int MED_MESH_WRONLY_DRIVER21::writeCoordinates() const { if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=_ptrMesh->_coordinate->getNumberOfNodes(); med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -1982,7 +2003,7 @@ int MED_MESH_WRONLY_DRIVER21::writeConnectivities(medEntityMesh entity) const { // } ////////////////////////////////////////////////////////////////////////////////////// -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=numberOfElements*(numberOfNodes+multi); med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -2019,7 +2040,7 @@ int MED_MESH_WRONLY_DRIVER21::writeConnectivities(medEntityMesh entity) const { const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); // Pour l'instant la class utilise le multi..... -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=_ptrMesh->getConnectivityLength(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -2111,7 +2132,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { SCRUTE(MEDArrayNodeFamily[j]); } if ( !_ptrMesh->getIsAGrid() ){ -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=NumberOfNodes; med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -2129,7 +2150,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { #endif } else{ -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=NumberOfNodes; med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -2141,7 +2162,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { delete [] temp; #else err = MEDfamGridEcr(_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), + const_cast <char *> (_meshName.c_str()), MEDArrayNodeFamily, NumberOfNodes, med_2_1::MED_REMP, @@ -2205,14 +2226,14 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { } const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=NumberOfElements; med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) temp[i2]=(med_2_1::med_int) (MEDArrayFamily[i2]); #endif for (int i=0; i<numberOfTypes; i++) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), temp+typeCount[i]-1,typeCount[i+1]-typeCount[i], med_2_1::MED_REMP , @@ -2233,7 +2254,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { << "| cells of geometric type |" << geoNames[ types[i]] <<"|in mesh |" << _ptrMesh->_name.c_str() << "|" )); } -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) delete [] temp; #endif delete[] MEDArrayFamily ; @@ -2291,7 +2312,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { } const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=numberOfElements; med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -2300,7 +2321,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { for (int i=0; i<numberOfTypes; i++) { int typeNumberOfElements = typeCount[i+1] - typeCount[i] ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), temp+typeCount[i]-1, typeNumberOfElements, med_2_1::MED_REMP , @@ -2318,7 +2339,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |" << _ptrMesh->_name.c_str() << "|" )); } -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) delete [] temp; #endif delete[] familyArray ; @@ -2376,7 +2397,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { } const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=numberOfElements; med_2_1::med_int *temp=new med_2_1::med_int[lgth]; for(int i2=0;i2<lgth;i2++) @@ -2385,7 +2406,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { for (int i=0; i<numberOfTypes; i++) { int typeNumberOfElements = typeCount[i+1] - typeCount[i] ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), temp+typeCount[i]-1, typeNumberOfElements, med_2_1::MED_REMP , @@ -2403,7 +2424,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilyNumbers() const { << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |" << _ptrMesh->_name.c_str() << "|" )); } -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) delete [] temp; #endif delete[] familyArray ; @@ -2489,7 +2510,7 @@ int MED_MESH_WRONLY_DRIVER21::writeFamilies(vector<FAMILY*> & families ) const { MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str()); MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups); MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str()); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=families[i]->getNumberOfAttributes(); med_2_1::med_int * AttributesIdentifier2 = new med_2_1::med_int[lgth] ; med_2_1::med_int * AttributesValues2 = new med_2_1::med_int[lgth] ; @@ -2563,7 +2584,7 @@ MED_MESH_RDWR_DRIVER21::MED_MESH_RDWR_DRIVER21(const string & fileName, MESSAGE("MED_MESH_RDWR_DRIVER21::MED_MESH_RDWR_DRIVER21(const string & fileName, MESH * ptrMesh) has been created"); } -MED_MESH_RDWR_DRIVER21::MED_MESH_RDWR_DRIVER21(const MED_MESH_RDWR_DRIVER21 & driver): +MED_MESH_RDWR_DRIVER21::MED_MESH_RDWR_DRIVER21(const MED_MESH_RDWR_DRIVER21 & driver): MED_MESH_DRIVER(driver), IMED_MESH_RDONLY_DRIVER(driver), IMED_MESH_WRONLY_DRIVER(driver), @@ -2576,8 +2597,8 @@ MED_MESH_RDWR_DRIVER21::MED_MESH_RDWR_DRIVER21(const MED_MESH_RDWR_DRIVER21 & dr MED_MESH_RDWR_DRIVER21::~MED_MESH_RDWR_DRIVER21() { //MESSAGE("MED_MESH_RDWR_DRIVER21::MED_MESH_RDWR_DRIVER21(const string & fileName, MESH * ptrMesh) has been destroyed"); -} - +} + GENDRIVER * MED_MESH_RDWR_DRIVER21::copy(void) const { return new MED_MESH_RDWR_DRIVER21(*this); @@ -2591,4 +2612,3 @@ void MED_MESH_RDWR_DRIVER21::read (void) { MED_MESH_RDONLY_DRIVER21::read(); } - diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver21.hxx b/src/MEDMEM/MEDMEM_MedMeshDriver21.hxx index 6d858bdc3..0bc7b6787 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver21.hxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver21.hxx @@ -20,6 +20,8 @@ #ifndef MED_MESH_DRIVER21_HXX #define MED_MESH_DRIVER21_HXX +#include "MEDMEM.hxx" + #include "MEDMEM_MedMeshDriver.hxx" #include "MEDMEM_define.hxx" #include "MEDMEM_Compatibility21_22.hxx" @@ -38,12 +40,12 @@ class FAMILY; class GROUP; class CONNECTIVITY; -class MED_MESH_DRIVER21 : public virtual MED_MESH_DRIVER +class MEDMEM_EXPORT MED_MESH_DRIVER21 : public virtual MED_MESH_DRIVER { protected: med_2_1::med_idt _medIdt; - + public : // all MED cell type @@ -58,8 +60,8 @@ public : /*! Constructor. */ - MED_MESH_DRIVER21(const string & fileName, - MESH * ptrMesh, + MED_MESH_DRIVER21(const string & fileName, + MESH * ptrMesh, MED_EN::med_mode_acces accessMode) ; /*! Copy constructor. @@ -83,11 +85,11 @@ public : */ - class MED_MESH_RDONLY_DRIVER21 : public virtual IMED_MESH_RDONLY_DRIVER , public virtual MED_MESH_DRIVER21 +class MEDMEM_EXPORT MED_MESH_RDONLY_DRIVER21 : public virtual IMED_MESH_RDONLY_DRIVER, + public virtual MED_MESH_DRIVER21 { - -public : - +public: + /*! Constructor. */ @@ -106,6 +108,9 @@ public : */ virtual ~MED_MESH_RDONLY_DRIVER21() ; void read(void); + void activateFacesComputation() { _computeFaces=true; } + void desactivateFacesComputation() { _computeFaces=false; } + private: int getCOORDINATE(); int getCONNECTIVITY(); @@ -117,6 +122,8 @@ private: GENDRIVER * copy ( void ) const ; +private: + bool _computeFaces; }; /*! @@ -127,7 +134,7 @@ private: */ -class MED_MESH_WRONLY_DRIVER21 : public virtual IMED_MESH_WRONLY_DRIVER, public virtual MED_MESH_DRIVER21 { +class MEDMEM_EXPORT MED_MESH_WRONLY_DRIVER21 : public virtual IMED_MESH_WRONLY_DRIVER, public virtual MED_MESH_DRIVER21 { public : @@ -173,7 +180,7 @@ private: */ -class MED_MESH_RDWR_DRIVER21 : public IMED_MESH_RDWR_DRIVER, public MED_MESH_RDONLY_DRIVER21, public MED_MESH_WRONLY_DRIVER21 { +class MEDMEM_EXPORT MED_MESH_RDWR_DRIVER21 : public IMED_MESH_RDWR_DRIVER, public MED_MESH_RDONLY_DRIVER21, public MED_MESH_WRONLY_DRIVER21 { public : diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver22.cxx b/src/MEDMEM/MEDMEM_MedMeshDriver22.cxx index 09f171d38..44a38366e 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver22.cxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver22.cxx @@ -28,19 +28,20 @@ #include "MEDMEM_Mesh.hxx" #include "MEDMEM_CellModel.hxx" #include "MEDMEM_Grid.hxx" +#include "MEDMEM_MedVersion.hxx" using namespace std; using namespace MED_EN; using namespace MEDMEM; -namespace med_2_2 { +namespace med_2_3 { extern "C" { extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom); extern med_err _MEDdatagroupFermer(med_idt id); } } -// Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor +// Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor MED_MESH_DRIVER22::MED_MESH_DRIVER22(): _medIdt(MED_INVALID) { @@ -48,11 +49,11 @@ MED_MESH_DRIVER22::MED_MESH_DRIVER22(): _medIdt(MED_INVALID) MED_MESH_DRIVER22::MED_MESH_DRIVER22(const string & fileName, MESH * ptrMesh, - MED_EN::med_mode_acces accessMode): + MED_EN::med_mode_acces accessMode): _medIdt(MED_INVALID), MED_MESH_DRIVER(fileName,ptrMesh,accessMode) { } - + MED_MESH_DRIVER22::MED_MESH_DRIVER22(const MED_MESH_DRIVER22 & driver): MED_MESH_DRIVER(driver),_medIdt(driver._medIdt) { @@ -67,8 +68,9 @@ void MED_MESH_DRIVER22::open() const char * LOC = "MED_MESH_DRIVER22::open()" ; BEGIN_OF(LOC); - MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode); - _medIdt = med_2_2::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_2::med_mode_acces) _accessMode); + int accessMode = getMedAccessMode( _accessMode, MED_EN::V22 ); + MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode); + _medIdt = med_2_3::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_3::med_mode_acces) accessMode); MESSAGE(LOC<<" _medIdt : "<< _medIdt ); if (_medIdt > 0) _status = MED_OPENED; @@ -87,7 +89,7 @@ void MED_MESH_DRIVER22::close() BEGIN_OF(LOC); int err = 0; if ( _status == MED_OPENED) { - err = med_2_2::MEDfermer(_medIdt); + err = med_2_3::MEDfermer(_medIdt); // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs() // method during study saving process. MEDfermer() seems sufficient for closing a file. //H5close(); // If we call H5close() all the files are closed. @@ -105,10 +107,10 @@ void MED_MESH_DRIVER22::close() } //A FAIRE UTILISER LES MAPS... -const med_2_2::med_geometrie_element MED_MESH_DRIVER22::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]= - { med_2_2::MED_POINT1,med_2_2::MED_SEG2,med_2_2::MED_SEG3,med_2_2::MED_TRIA3,med_2_2::MED_QUAD4,med_2_2::MED_TRIA6,med_2_2::MED_QUAD8, - med_2_2::MED_TETRA4,med_2_2::MED_PYRA5,med_2_2::MED_PENTA6,med_2_2::MED_HEXA8,med_2_2::MED_TETRA10,med_2_2::MED_PYRA13, - med_2_2::MED_PENTA15, med_2_2::MED_HEXA20}; +const med_2_3::med_geometrie_element MED_MESH_DRIVER22::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]= + { med_2_3::MED_POINT1,med_2_3::MED_SEG2,med_2_3::MED_SEG3,med_2_3::MED_TRIA3,med_2_3::MED_QUAD4,med_2_3::MED_TRIA6,med_2_3::MED_QUAD8, + med_2_3::MED_TETRA4,med_2_3::MED_PYRA5,med_2_3::MED_PENTA6,med_2_3::MED_HEXA8,med_2_3::MED_TETRA10,med_2_3::MED_PYRA13, + med_2_3::MED_PENTA15, med_2_3::MED_HEXA20}; const char * const MED_MESH_DRIVER22::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]= { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8", @@ -118,19 +120,25 @@ const char * const MED_MESH_DRIVER22::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILL //---------------------------------- RDONLY PART ------------------------------------------------------------- -MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22() +MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22():_computeFaces(true) { } MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh): - IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER22(fileName,ptrMesh,MED_RDONLY),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY) + IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh), + MED_MESH_DRIVER22(fileName,ptrMesh,MED_RDONLY), + MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY), + _computeFaces(true) { MESSAGE("MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created"); } MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const MED_MESH_RDONLY_DRIVER22 & driver): - IMED_MESH_RDONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver) + IMED_MESH_RDONLY_DRIVER(driver), + MED_MESH_DRIVER22(driver), + MED_MESH_DRIVER(driver), + _computeFaces(driver._computeFaces) { } @@ -169,28 +177,37 @@ void MED_MESH_RDONLY_DRIVER22::read(void) SCRUTE(_ptrMesh->getIsAGrid()); if (_ptrMesh->getIsAGrid()) + { + getGRID( ); { - getGRID( ); - - // always call getFAMILY : families are requiered !!!! - -// int nbFam = MEDnFam(_medIdt, -// const_cast <char *> (_meshName.c_str()), -// 0, -// MED_FR::MED_FAMILLE); -// if (nbFam > 0) - { -// getFAMILY(); - - if (getFAMILY()!=MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ; - - buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ; - } - - END_OF(LOC); - return; + if (getFAMILY()!=MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ; + buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ; } + END_OF(LOC); + return; + } + else // check that the mesh is really unstructured (PAL14113) + { + char meshName[MED_TAILLE_NOM+1]=""; + char meshDescription[MED_TAILLE_DESC+1]=""; + med_2_3::med_int meshDim; + med_2_3::med_maillage meshType; + int numberOfMeshes = med_2_3::MEDnMaa(_medIdt); + for (int i=1;i<=numberOfMeshes;i++) + { + MEDmaaInfo(_medIdt, i ,meshName, &meshDim, &meshType, meshDescription); + if (_meshName == string(meshName)) { + if ( meshType == med_2_3::MED_STRUCTURE ) { + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << + "class GRID must be used for a structured mesh")); + } + else { + break; + } + } + } + } if (getCOORDINATE()!=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" )) ; @@ -201,7 +218,8 @@ void MED_MESH_RDONLY_DRIVER22::read(void) if (getFAMILY()!=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY" )) ; - updateFamily(); + if (_computeFaces) + updateFamily(); // we build all groups // on node @@ -212,7 +230,8 @@ void MED_MESH_RDONLY_DRIVER22::read(void) if (_ptrMesh->_meshDimension == 3) // on face buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ; - else if (_ptrMesh->_meshDimension == 2) +// else if (_ptrMesh->_meshDimension == 2) -- PAL13414 + if (_ptrMesh->_meshDimension > 1) // on edge buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ; @@ -246,7 +265,7 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() int err, i; - int numberOfMeshesInFile = med_2_2::MEDnMaa(_medIdt); + int numberOfMeshesInFile = med_2_3::MEDnMaa(_medIdt); if (numberOfMeshesInFile == MED_INVALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored")); @@ -256,10 +275,10 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() char meshName[MED_TAILLE_NOM+1]=""; char meshDescription[MED_TAILLE_DESC+1]=""; //CCRT int meshDim; - med_2_2::med_int meshDim; - med_2_2::med_maillage meshType; + med_2_3::med_int meshDim; + med_2_3::med_maillage meshType; - err = med_2_2::MEDmaaInfo(_medIdt, (index+1),meshName, &meshDim, + err = med_2_3::MEDmaaInfo(_medIdt, (index+1),meshName, &meshDim, &meshType, meshDescription) ; MESSAGE(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured"); @@ -272,11 +291,23 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() } MED_EN::med_grid_type gridType = ptrGrid->getGridType(); + if ( ptrGrid->_is_default_gridType ) + { + med_2_3::med_type_grille type; + err = med_2_3::MEDnatureGrilleLire(_medIdt, + const_cast <char *>(_meshName.c_str()), + &type); + if (err != MED_VALID) + throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get the nature of the grid which is the mesh n°" << i << " of the file |" << _fileName << "| !")); + + gridType = ptrGrid->_gridType = (MED_EN::med_grid_type) type; + ptrGrid->_is_default_gridType = false; + } MESSAGE(LOC<<": Mesh processed is nammed "<< _ptrMesh->_name << " with the description " << _ptrMesh->_description << " is structured with the type " << gridType); // Read the dimension of the mesh <_meshName> - int MeshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *> + int MeshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str())) ; if (MeshDimension == MED_INVALID) @@ -289,7 +320,7 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() // Read or get the dimension of the space for the mesh <_meshName> int SpaceDimension = MeshDimension; - int SpaceDimensionRead = med_2_2::MEDdimEspaceLire(_medIdt, + int SpaceDimensionRead = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *> (_meshName.c_str())) ; @@ -297,7 +328,7 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() _ptrMesh->_spaceDimension = SpaceDimension; - med_2_2::med_repere rep ; + med_2_3::med_repere rep ; string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' '); string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' '); char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ; @@ -316,9 +347,9 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() if (gridType == MED_EN::MED_BODY_FITTED) { //CCRT int * structure = new int[MeshDimension]; - med_int * structure = new med_int[MeshDimension]; + med_2_3::med_int * structure = new med_2_3::med_int[MeshDimension]; - err = med_2_2::MEDstructureCoordLire(_medIdt, + err = med_2_3::MEDstructureCoordLire(_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), MeshDimension,structure); @@ -363,7 +394,7 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() _ptrMesh->_spaceDimension, //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), - med_2_2::MED_FULL_INTERLACE, + med_2_3::MED_FULL_INTERLACE, MED_ALL, // we read all the coordinates NULL, // we don't use a profile 0, // so the profile's size is 0 @@ -388,16 +419,16 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim) { - med_2_2::med_table table; - if (idim == 0) table = med_2_2::MED_COOR_IND1; - else if (idim == 1) table = med_2_2::MED_COOR_IND2; - else if (idim == 2) table = med_2_2::MED_COOR_IND3; + med_2_3::med_table table; + if (idim == 0) table = med_2_3::MED_COOR_IND1; + else if (idim == 1) table = med_2_3::MED_COOR_IND2; + else if (idim == 2) table = med_2_3::MED_COOR_IND3; - int length = med_2_2::MEDnEntMaa(_medIdt, + int length = med_2_3::MEDnEntMaa(_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), - table,med_2_2::MED_NOEUD, - med_2_2::MED_NONE, - med_2_2::MED_NOD); + table,med_2_3::MED_NOEUD, + med_2_3::MED_NONE, + med_2_3::MED_NOD); if ( length <= MED_VALID ) throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << length << "| seems to be incorrect " @@ -408,7 +439,7 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() Array [idim] = new double [ length ]; - err = med_2_2::MEDindicesCoordLire(_medIdt, const_cast <char *> + err = med_2_3::MEDindicesCoordLire(_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), _ptrMesh->_meshDimension, Array [idim], length, (idim+1), @@ -432,11 +463,11 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() MED_EN::MED_FULL_INTERLACE); if (gridType == MED_EN::MED_CARTESIAN) - rep = med_2_2::MED_CART; + rep = med_2_3::MED_CART; else if (gridType == MED_EN::MED_POLAR) { - if (SpaceDimension == 2) rep = med_2_2::MED_CYL; - else if (SpaceDimension == 3) rep = med_2_2::MED_SPHER; + if (SpaceDimension == 2) rep = med_2_3::MED_CYL; + else if (SpaceDimension == 3) rep = med_2_3::MED_SPHER; } } else @@ -459,9 +490,9 @@ void MED_MESH_RDONLY_DRIVER22::getGRID() string coordinateSystem = "UNDEFINED"; - if( rep == med_2_2::MED_CART) coordinateSystem = "CARTESIAN"; - else if ( rep == med_2_2::MED_CYL) coordinateSystem = "CYLINDRICAL"; - else if ( rep == med_2_2::MED_SPHER) coordinateSystem = "SPHERICAL"; + if( rep == med_2_3::MED_CART) coordinateSystem = "CARTESIAN"; + else if ( rep == med_2_3::MED_CYL) coordinateSystem = "CYLINDRICAL"; + else if ( rep == med_2_3::MED_SPHER) coordinateSystem = "SPHERICAL"; _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem); @@ -482,7 +513,7 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() { int err ; - int numberOfMeshesInFile = med_2_2::MEDnMaa(_medIdt); + int numberOfMeshesInFile = med_2_3::MEDnMaa(_medIdt); if (numberOfMeshesInFile == MED_INVALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored")); @@ -492,10 +523,10 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() char meshName[MED_TAILLE_NOM+1]=""; char meshDescription[MED_TAILLE_DESC+1]=""; //CCRT int meshDim; - med_2_2::med_int meshDim; - med_2_2::med_maillage meshType; + med_2_3::med_int meshDim; + med_2_3::med_maillage meshType; - err = med_2_2::MEDmaaInfo(_medIdt, (index+1), meshName, &meshDim, + err = med_2_3::MEDmaaInfo(_medIdt, (index+1), meshName, &meshDim, &meshType, meshDescription) ; MESSAGE(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured"); @@ -508,7 +539,7 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() // Read the dimension of the mesh <_meshName> - int MeshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *> + int MeshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str())) ; if ( MeshDimension == MED_INVALID ) @@ -522,7 +553,7 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() // Read or get the dimension of the space for the mesh <_meshName> int SpaceDimension = MeshDimension; - int SpaceDimensionRead = med_2_2::MEDdimEspaceLire(_medIdt, + int SpaceDimensionRead = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *> (_meshName.c_str())) ; @@ -535,19 +566,21 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() // to be able to create a COORDINATE object int NumberOfNodes=MEDnEntMaa(_medIdt, const_cast <char *> (_meshName.c_str()), - med_2_2::MED_COOR, - med_2_2::MED_NOEUD, - (med_2_2::med_geometrie_element) MED_NONE, - (med_2_2::med_connectivite) MED_NONE); + med_2_3::MED_COOR, + med_2_3::MED_NOEUD, + (med_2_3::med_geometrie_element) MED_NONE, + (med_2_3::med_connectivite) MED_NONE); if ( NumberOfNodes <= MED_VALID ) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << "| seems to be incorrect " << "for the mesh : |" << _meshName << "|" )) ; _ptrMesh->_numberOfNodes = NumberOfNodes ; // create a COORDINATE object + if (_ptrMesh->_coordinate) + delete _ptrMesh->_coordinate; _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE); - med_2_2::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON? + med_2_3::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON? string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0'); string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0'); char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ; @@ -558,7 +591,7 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() _ptrMesh->_spaceDimension, //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), - med_2_2::MED_FULL_INTERLACE, + med_2_3::MED_FULL_INTERLACE, MED_ALL, // we read all the coordinates NULL, // we don't use a profile 0, // so the profile's size is 0 @@ -588,17 +621,17 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() // Pourquoi le stocker sous forme de chaĂƒÂ®ne ? switch (rep) { - case med_2_2::MED_CART : + case med_2_3::MED_CART : { _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN"; break ; } - case med_2_2::MED_CYL : + case med_2_3::MED_CYL : { _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL"; break ; } - case med_2_2::MED_SPHER : + case med_2_3::MED_SPHER : { _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL"; break ; @@ -614,25 +647,25 @@ int MED_MESH_RDONLY_DRIVER22::getCOORDINATE() char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM22+1]; tmp_node_name[NumberOfNodes]='\0' ; err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()), - tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM22,med_2_2::MED_NOEUD, - (med_2_2::med_geometrie_element) MED_NONE); + tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM22,med_2_3::MED_NOEUD, + (med_2_3::med_geometrie_element) MED_NONE); if (err == MED_VALID) MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !"); delete[] tmp_node_name ; // ??? Read the unused optional node Numbers ??? - med_2_2::med_int * tmp_node_number = new med_2_2::med_int[NumberOfNodes] ; + med_2_3::med_int * tmp_node_number = new med_2_3::med_int[NumberOfNodes] ; err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()), - tmp_node_number,NumberOfNodes,med_2_2::MED_NOEUD,(med_2_2::med_geometrie_element)0); + tmp_node_number,NumberOfNodes,med_2_3::MED_NOEUD,(med_2_3::med_geometrie_element)0); if (err == MED_VALID) { // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); // INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !"); // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"); MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !"); _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - for(med_2_2::med_int i2=0;i2<NumberOfNodes;i2++) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + for(med_2_3::med_int i2=0;i2<NumberOfNodes;i2++) _ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]); #else memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ; @@ -738,7 +771,8 @@ int MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY() MESSAGE(LOC<<"No FACE defined.") ; } else { MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" ); - Connectivity->_constituent=ConnectivityFace ; + delete Connectivity->_constituent; + Connectivity->_constituent=ConnectivityFace; } } @@ -777,6 +811,8 @@ int MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY() } } } + if (_ptrMesh->_connectivity) + delete _ptrMesh->_connectivity; _ptrMesh->_connectivity = Connectivity ; // all right ! @@ -812,38 +848,61 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) int spaceDimension = _ptrMesh->_spaceDimension; // Get the type of entity to work on (previously set in the Connectivity Object) - med_2_2::med_entite_maillage Entity = (med_2_2::med_entite_maillage) Connectivity->getEntity(); + med_2_3::med_entite_maillage Entity = (med_2_3::med_entite_maillage) Connectivity->getEntity(); // Get the number of cells of each type & store it in <tmp_cells_count>. int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ; int i; for (i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) - { // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS - tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())), - med_2_2::MED_CONN,(med_2_2::med_entite_maillage) Entity, - all_cell_type[i],med_2_2::MED_NOD); - - - // Get the greatest dimension of the cells : Connectivity->_entityDimension - // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!! - // In version prior to 2.2.x, it is possible - if (tmp_cells_count[i]>0) - { - Connectivity->_entityDimension=all_cell_type[i]/100; - Connectivity->_numberOfTypes++; - } - } + { // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS + tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())), + med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity, + all_cell_type[i],med_2_3::MED_NOD); + + + // Get the greatest dimension of the cells : Connectivity->_entityDimension + // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!! + // In version prior to 2.2.x, it is possible + if (tmp_cells_count[i]>0) + { + Connectivity->_entityDimension=all_cell_type[i]/100; + Connectivity->_numberOfTypes++; + } + } - + { + // VBD fix to be able reading polygons and polyhedrons + // "in the case when the space dimension is 3 and the mesh dimension 2" + + //checking for the number of polygons/polyhedra to get an appropriate mesh dimension + int nbpolygons=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())), + med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity, + med_2_3::MED_POLYGONE,med_2_3::MED_NOD); + if (nbpolygons>0) + { + if (Connectivity->_entityDimension<2) + Connectivity->_entityDimension=2; + } + int nbpolyhedra=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())), + med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity, + med_2_3::MED_POLYEDRE,med_2_3::MED_NOD); + if (nbpolyhedra>0) + Connectivity->_entityDimension=3; + + //setting a correct mesh dimension as being the dimnsion corresponding to + // the highest dimension element + if (Entity==med_2_3::MED_MAILLE) + _ptrMesh->_meshDimension = Connectivity->_entityDimension; + } // begin classic geometric types if (Connectivity->_numberOfTypes > 0) { // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge ! - med_int major, minor, release; + med_2_3::med_int major, minor, release; - if ( med_2_2::MEDversionLire(_medIdt, &major, &minor, &release) != 0 ) + if ( med_2_3::MEDversionLire(_medIdt, &major, &minor, &release) != 0 ) { // error : we suppose we have not a good med file ! delete[] tmp_cells_count ; @@ -896,7 +955,7 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) // } // } - if (Entity==med_2_2::MED_MAILLE) + if (Entity==med_2_3::MED_MAILLE) { Connectivity->_numberOfTypes=0; @@ -980,7 +1039,7 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) for ( i=0;i<Connectivity->_numberOfTypes;i++) { int multi = 0 ; - med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) Connectivity->_type[i].getType() ; + med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) Connectivity->_type[i].getType() ; // if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension) // if (Connectivity->_entity == MED_CELL) // if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension) @@ -995,14 +1054,14 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ; //CCRT int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells]; - med_2_2::med_int * tmp_ConnectivityArray = new med_2_2::med_int[(NumberOfNodeByCell+multi)*tmp_numberOfCells]; + med_2_3::med_int * tmp_ConnectivityArray = new med_2_3::med_int[(NumberOfNodeByCell+multi)*tmp_numberOfCells]; // int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), // Connectivity->_entityDimension,tmp_ConnectivityArray, // MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD); int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), spaceDimension,tmp_ConnectivityArray, - med_2_2::MED_FULL_INTERLACE,NULL,0,Entity,med_type,med_2_2::MED_NOD); + med_2_3::MED_FULL_INTERLACE,NULL,0,Entity,med_type,med_2_3::MED_NOD); if ( err != MED_VALID) { @@ -1105,7 +1164,7 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) // Fill the MEDSKYLINEARRAY by reading the MED file. for ( i=0; i<constituent->_numberOfTypes; i++) { - med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) constituent->_type[i].getType() ; + med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) constituent->_type[i].getType() ; int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ; @@ -1117,23 +1176,23 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) // Il faut ajouter 1 pour le zero a la lecture !!! // ATTENTION UNIQUEMENT POUR MED < 2.2.x //CCRT int * tmp_constituentArray = NULL; - med_2_2::med_int * tmp_constituentArray = NULL; + med_2_3::med_int * tmp_constituentArray = NULL; MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release); if ((major == 2) && (minor <= 1)) //CCRT tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ; - tmp_constituentArray = new med_2_2::med_int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ; + tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ; else if ((major == 2) && (minor >= 2)) { //CCRT tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ; - tmp_constituentArray = new med_2_2::med_int[NumberOfNodeByFace*tmp_numberOfFaces] ; + tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByFace*tmp_numberOfFaces] ; MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ; } int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), Connectivity->_entityDimension,tmp_constituentArray, - med_2_2::MED_FULL_INTERLACE,NULL,0,med_2_2::MED_MAILLE,med_type,med_2_2::MED_NOD); + med_2_3::MED_FULL_INTERLACE,NULL,0,med_2_3::MED_MAILLE,med_type,med_2_3::MED_NOD); if ( err != MED_VALID) { @@ -1239,7 +1298,7 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) // Fill the MEDSKYLINEARRAY by reading the MED file. for ( i=0; i<constituent->_numberOfTypes; i++) { - med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) constituent->_type[i].getType() ; + med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) constituent->_type[i].getType() ; int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ; @@ -1252,23 +1311,23 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) // ATTENTION UNIQUEMENT POUR MED < 2.2.x //CCRT int * tmp_constituentArray = NULL; - med_2_2::med_int * tmp_constituentArray = NULL; + med_2_3::med_int * tmp_constituentArray = NULL; MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release); if ((major == 2) && (minor <= 1)) //CCRT tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ; - tmp_constituentArray = new med_2_2::med_int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ; + tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ; else if ((major == 2) && (minor >= 2)) { //CCRT tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ; - tmp_constituentArray = new med_2_2::med_int[NumberOfNodeByEdge*tmp_numberOfEdges] ; + tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByEdge*tmp_numberOfEdges] ; MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ; } int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), spaceDimension,tmp_constituentArray, - med_2_2::MED_FULL_INTERLACE,NULL,0,med_2_2::MED_MAILLE,med_type,med_2_2::MED_NOD); + med_2_3::MED_FULL_INTERLACE,NULL,0,med_2_3::MED_MAILLE,med_type,med_2_3::MED_NOD); if ( err != MED_VALID) { MESSAGE(LOC<<": MEDconnLire returns "<<err) ; @@ -1338,109 +1397,128 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) } // end classic geometric types + else + {//Polyg/Polh only... + delete [] Connectivity->_count; + Connectivity->_count=new int[1]; + Connectivity->_count[0]=1; + } delete[] tmp_cells_count; - - - // Lecture des polygones MED_CELL + // Lecture des polygones MED_CELL int NumberOfPolygons = MEDnEntMaa(_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), - med_2_2::MED_CONN, - Entity, - med_2_2::MED_POLYGONE, - med_2_2::MED_NOD); + const_cast <char *> (_ptrMesh->_name.c_str()), + med_2_3::MED_CONN, + med_2_3::MED_MAILLE, + med_2_3::MED_POLYGONE, + med_2_3::MED_NOD); + + // Correction to permit the loading of mesh dimensionned at 2 even + // if it has only MED_POLYGON elements + + if (NumberOfPolygons > 0) + { + if (Connectivity->_entityDimension < 2) Connectivity->_entityDimension = 2; + } - // Correction to permit the loading of mesh dimensionned at 2 even - // if it has only MED_POLYGON elements + if (NumberOfPolygons > 0) + { + // By consequence this exception will never occur + if (Connectivity->_entityDimension == 1) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 2D mesh, polygons need at least one 2D cell of a classic geometric type !")); + med_2_3::med_int ConnectivitySize; + med_2_3::med_err err1 = MEDpolygoneInfo(_medIdt, + const_cast <char *> (_ptrMesh->_name.c_str()), + med_2_3::MED_MAILLE, + med_2_3::MED_NOD, + &ConnectivitySize); + if (err1 != MED_VALID) + { + MESSAGE(LOC<<": MEDpolygoneInfo returns "<<err1); + return MED_ERROR; + } - if (NumberOfPolygons > 0) - { - if (Connectivity->_entityDimension < 2) Connectivity->_entityDimension = 2; - } + med_2_3::med_int* PolygonsConnectivity = new med_2_3::med_int[ConnectivitySize]; + med_2_3::med_int* PolygonsConnectivityIndex = new med_2_3::med_int[NumberOfPolygons+1]; + + med_2_3::med_err err2 = MEDpolygoneConnLire(_medIdt, + const_cast <char *> (_ptrMesh->_name.c_str()), + PolygonsConnectivityIndex, + NumberOfPolygons+1, + PolygonsConnectivity, + med_2_3::MED_MAILLE, + med_2_3::MED_NOD); + if (err2 != MED_VALID) + { + MESSAGE(LOC<<": MEDpolygoneConnLire returns "<<err2); + return MED_ERROR; + } - if (NumberOfPolygons > 0) - { - // By consequence this exception will never occur - if (Connectivity->_entityDimension == 1) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 2D mesh, polygons need at least one 2D cell of a classic geometric type !")); - med_int ConnectivitySize; - med_err err1 = MEDpolygoneInfo(_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), - Entity, - med_2_2::MED_NOD, - &ConnectivitySize); - if (err1 != MED_VALID) - { - MESSAGE(LOC<<": MEDpolygoneInfo returns "<<err1); - return MED_ERROR; - } - - med_int* PolygonsConnectivity = new med_int[ConnectivitySize]; - med_int* PolygonsConnectivityIndex = new med_int[NumberOfPolygons+1]; - - med_err err2 = MEDpolygoneConnLire(_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), - PolygonsConnectivityIndex, - NumberOfPolygons+1, - PolygonsConnectivity, - Entity, - med_2_2::MED_NOD); - if (err2 != MED_VALID) - { - MESSAGE(LOC<<": MEDpolygoneConnLire returns "<<err2); - return MED_ERROR; - } - - if (Connectivity->_entityDimension == 2) {// 2D mesh : polygons in Connectivity + if (Connectivity->_entityDimension == 2) // 2D mesh : polygons in Connectivity + { //CCRT -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - int* tmp_PolygonsConnectivity = new int[ConnectivitySize]; +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int* tmp_PolygonsConnectivity = new int[ConnectivitySize]; int i ; for ( i = 0 ; i < ConnectivitySize ; i++ ) - tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ; - int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1]; + tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ; + + int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1]; for ( i = 0 ; i < NumberOfPolygons+1 ; i++ ) - tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ; - Connectivity->setPolygonsConnectivity(MED_NODAL,(medEntityMesh) Entity,tmp_PolygonsConnectivity,tmp_PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons); + tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ; + + Connectivity->setPolygonsConnectivity + (MED_NODAL, (medEntityMesh) Entity, tmp_PolygonsConnectivity, + tmp_PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons); + delete [] tmp_PolygonsConnectivity ; delete [] tmp_PolygonsConnectivityIndex ; #else - Connectivity->setPolygonsConnectivity(MED_NODAL,(medEntityMesh) Entity,PolygonsConnectivity,PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons); + Connectivity->setPolygonsConnectivity + (MED_NODAL, (medEntityMesh) Entity, PolygonsConnectivity, + PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons); #endif } - else if (Connectivity->_entityDimension == 3) - { - if (Connectivity->_constituent == NULL) // 3D mesh : polygons in Connectivity->_constituent - Connectivity->_constituent = new CONNECTIVITY(MED_FACE); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - int* tmp_PolygonsConnectivity = new int[ConnectivitySize]; - int i ; - for ( i = 0 ; i < ConnectivitySize ; i++ ) - tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ; - int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1]; - for ( i = 0 ; i < NumberOfPolygons+1 ; i++ ) - tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ; - Connectivity->_constituent->setPolygonsConnectivity(MED_NODAL,MED_FACE,tmp_PolygonsConnectivity,tmp_PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons); - delete [] tmp_PolygonsConnectivity ; - delete [] tmp_PolygonsConnectivityIndex ; + else if (Connectivity->_entityDimension == 3) + { + if (Connectivity->_constituent == NULL) // 3D mesh : polygons in Connectivity->_constituent + Connectivity->_constituent = new CONNECTIVITY(MED_FACE); +//CCRT +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int* tmp_PolygonsConnectivity = new int[ConnectivitySize]; + int i ; + for ( i = 0 ; i < ConnectivitySize ; i++ ) + tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ; + + int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1]; + for ( i = 0 ; i < NumberOfPolygons+1 ; i++ ) + tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ; + + Connectivity->_constituent->setPolygonsConnectivity + (MED_NODAL, MED_FACE, tmp_PolygonsConnectivity, + tmp_PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons); + + delete [] tmp_PolygonsConnectivity ; + delete [] tmp_PolygonsConnectivityIndex ; #else - Connectivity->_constituent->setPolygonsConnectivity(MED_NODAL,MED_FACE,PolygonsConnectivity,PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons); + Connectivity->_constituent->setPolygonsConnectivity + (MED_NODAL, MED_FACE, PolygonsConnectivity, + PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons); #endif - } - - delete[] PolygonsConnectivity; - delete[] PolygonsConnectivityIndex; - } // end polygons - + } + + delete[] PolygonsConnectivity; + delete[] PolygonsConnectivityIndex; + } // end polygons // Lecture des polyedres MED_CELL med_int NumberOfPolyhedron = MEDnEntMaa(_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), - med_2_2::MED_CONN, + med_2_3::MED_CONN, Entity, - med_2_2::MED_POLYEDRE, - med_2_2::MED_NOD); + med_2_3::MED_POLYEDRE, + med_2_3::MED_NOD); // Correction to permit the loading of mesh dimensionned at 3 even // if it has only MED_POLYEDRE elements @@ -1455,12 +1533,12 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) // By consequence this exception will never occur if (Connectivity->_entityDimension == 2 || Connectivity->_entityDimension == 1) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 3D mesh, polyhedron need at least one 3D cell of a classic geometric type !")); - med_int FacesIndexSize, NumberOfNodes, NumberOfFaces; - med_err err3 = MEDpolyedreInfo(_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), - med_2_2::MED_NOD, - &FacesIndexSize, - &NumberOfNodes); + med_2_3::med_int FacesIndexSize, NumberOfNodes, NumberOfFaces; + med_2_3::med_err err3 = MEDpolyedreInfo(_medIdt, + const_cast <char *> (_ptrMesh->_name.c_str()), + med_2_3::MED_NOD, + &FacesIndexSize, + &NumberOfNodes); NumberOfFaces = FacesIndexSize-1; if (err3 != MED_VALID) { @@ -1468,18 +1546,18 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) return MED_ERROR; } - med_int* Nodes = new med_int[NumberOfNodes]; - med_int* FacesIndex = new med_int[NumberOfFaces+1]; - med_int* PolyhedronIndex = new med_int[NumberOfPolyhedron+1]; + med_2_3::med_int* Nodes = new med_2_3::med_int[NumberOfNodes]; + med_2_3::med_int* FacesIndex = new med_2_3::med_int[NumberOfFaces+1]; + med_2_3::med_int* PolyhedronIndex = new med_2_3::med_int[NumberOfPolyhedron+1]; - med_err err4 = MEDpolyedreConnLire(_medIdt, - const_cast <char *> (_ptrMesh->_name.c_str()), - PolyhedronIndex, - NumberOfPolyhedron+1, - FacesIndex, - NumberOfFaces+1, - Nodes, - med_2_2::MED_NOD); + med_2_3::med_err err4 = MEDpolyedreConnLire(_medIdt, + const_cast <char *> (_ptrMesh->_name.c_str()), + PolyhedronIndex, + NumberOfPolyhedron+1, + FacesIndex, + NumberOfFaces+1, + Nodes, + med_2_3::MED_NOD); if (err4 != MED_VALID) { MESSAGE(LOC<<": MEDpolyedreConnLire returns "<<err4); @@ -1487,7 +1565,7 @@ int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity) } //CCRT -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int* tmp_Nodes = new int[NumberOfNodes]; int i ; for ( i = 0 ; i < NumberOfNodes ; i++ ) @@ -1554,6 +1632,9 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() MEDArrayCellFamily[i] = new int[_ptrMesh->getNumberOfElementsWithPoly(MED_CELL,myTypes[i])] ; + // assure connectivety exists in case of GRID + _ptrMesh->getConnectivityptr(); //PAL14113 + err = getCellsFamiliesNumber(MEDArrayCellFamily, _ptrMesh->_connectivity,MED_CELL) ; delete [] myTypes; @@ -1617,7 +1698,7 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() } } - int NumberOfFamilies = med_2_2::MEDnFam(_medIdt, const_cast <char *> + int NumberOfFamilies = med_2_3::MEDnFam(_medIdt, const_cast <char *> (_meshName.c_str())) ; if ( NumberOfFamilies < 1 ) // at least family 0 must exist @@ -1637,14 +1718,13 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() for (int i=0;i<NumberOfFamilies;i++) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_int tmp_NumberOfAttributes = med_2_2::MEDnAttribut(_medIdt, - const_cast <char *> - (_meshName.c_str()), - (i+1)); - int NumberOfAttributes = tmp_NumberOfAttributes ; +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + med_2_3::med_int tmp_NumberOfAttributes = med_2_3::MEDnAttribut(_medIdt, + const_cast <char *>(_meshName.c_str()), + (i+1)); + med_2_3::med_int NumberOfAttributes = tmp_NumberOfAttributes ; #else - int NumberOfAttributes = med_2_2::MEDnAttribut(_medIdt, + int NumberOfAttributes = med_2_3::MEDnAttribut(_medIdt, const_cast <char *> (_meshName.c_str()), (i+1)); @@ -1653,13 +1733,15 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() if (NumberOfAttributes < 0) throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfAttributes" ); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_int tmp_NumberOfGroups = med_2_2::MEDnGroupe(_medIdt, const_cast <char *> - (_meshName.c_str()),(i+1)) ; - int NumberOfGroups = tmp_NumberOfGroups ; +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + med_2_3::med_int tmp_NumberOfGroups = med_2_3::MEDnGroupe(_medIdt, + const_cast <char *>(_meshName.c_str()), + (i+1)) ; + int NumberOfGroups = tmp_NumberOfGroups ; #else - int NumberOfGroups = med_2_2::MEDnGroupe(_medIdt, const_cast <char *> - (_meshName.c_str()),(i+1)) ; + int NumberOfGroups = med_2_3::MEDnGroupe(_medIdt, + const_cast <char *>(_meshName.c_str()), + (i+1)) ; #endif if (NumberOfGroups < 0) @@ -1671,19 +1753,21 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() int * AttributesValues = new int[NumberOfAttributes] ; string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ; string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_int tmp_FamilyIdentifier ; - med_int * tmp_AttributesIdentifier = new med_int[NumberOfAttributes] ; - med_int * tmp_AttributesValues = new med_int[NumberOfAttributes] ; - err = med_2_2::MEDfamInfo(_medIdt,const_cast <char *> - (_meshName.c_str()), - (i+1),const_cast <char *> - (FamilyName.c_str()), &tmp_FamilyIdentifier, - tmp_AttributesIdentifier,tmp_AttributesValues, - const_cast <char *> - (AttributesDescription.c_str()), - &tmp_NumberOfAttributes, const_cast <char *> - (GroupsNames.c_str()),&tmp_NumberOfGroups); +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + med_2_3::med_int tmp_FamilyIdentifier ; + med_2_3::med_int * tmp_AttributesIdentifier = new med_2_3::med_int[NumberOfAttributes] ; + med_2_3::med_int * tmp_AttributesValues = new med_2_3::med_int[NumberOfAttributes] ; + err = med_2_3::MEDfamInfo(_medIdt, + const_cast <char *>(_meshName.c_str()), + (i+1), + const_cast <char *>(FamilyName.c_str()), + &tmp_FamilyIdentifier, + tmp_AttributesIdentifier, + tmp_AttributesValues, + const_cast <char *>(AttributesDescription.c_str()), + &tmp_NumberOfAttributes, + const_cast <char *>(GroupsNames.c_str()), + &tmp_NumberOfGroups); FamilyIdentifier = tmp_FamilyIdentifier ; int ii ; for ( ii = 0 ; ii < NumberOfAttributes ; ii++ ) { @@ -1695,7 +1779,7 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() delete [] tmp_AttributesIdentifier ; delete [] tmp_AttributesValues ; #else - err = med_2_2::MEDfamInfo(_medIdt,const_cast <char *> + err = med_2_3::MEDfamInfo(_medIdt,const_cast <char *> (_meshName.c_str()), (i+1),const_cast <char *> (FamilyName.c_str()), &FamilyIdentifier, @@ -1731,6 +1815,10 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() // All good ? // if nothing found, delete Family + /*! \todo TODO : once unit tests are ready, check that there is no side effect + and let the driver read empty families by removing the if case of the + few following lines */ + if (Family->getNumberOfTypes() == 0) { MESSAGE(LOC<<"Nothing found for family "<<FamilyName<< @@ -1769,21 +1857,21 @@ int MED_MESH_RDONLY_DRIVER22::getFAMILY() if (MEDArrayCellFamily != NULL) { - for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++) + for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL); i++) delete[] MEDArrayCellFamily[i] ; delete[] MEDArrayCellFamily ; } if (MEDArrayFaceFamily != NULL) { - for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++) + for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE); i++) delete[] MEDArrayFaceFamily[i] ; delete[] MEDArrayFaceFamily ; } if (MEDArrayEdgeFamily != NULL) { - for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++) + for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_EDGE); i++) delete[] MEDArrayEdgeFamily[i] ; delete[] MEDArrayEdgeFamily ; } @@ -1805,20 +1893,20 @@ int MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber(int * MEDArrayNodeFamily) { int err = 0 ; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_int * tmp_MEDArrayNodeFamily = new med_int[_ptrMesh->getNumberOfNodes()] ; +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + med_2_3::med_int * tmp_MEDArrayNodeFamily = new med_2_3::med_int[_ptrMesh->getNumberOfNodes()] ; err = MEDfamLire(_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), tmp_MEDArrayNodeFamily, - _ptrMesh->getNumberOfNodes(), med_2_2::MED_NOEUD, - (med_2_2::med_geometrie_element) MED_NONE); + _ptrMesh->getNumberOfNodes(), med_2_3::MED_NOEUD, + (med_2_3::med_geometrie_element) MED_NONE); int i ; for ( i = 0 ; i < _ptrMesh->getNumberOfNodes() ; i++ ) MEDArrayNodeFamily[i] = tmp_MEDArrayNodeFamily[i] ; #else err = MEDfamLire(_medIdt, const_cast <char *> (_ptrMesh->_name.c_str()), MEDArrayNodeFamily, - _ptrMesh->getNumberOfNodes(), med_2_2::MED_NOEUD, - (med_2_2::med_geometrie_element) MED_NONE); + _ptrMesh->getNumberOfNodes(), med_2_3::MED_NOEUD, + (med_2_3::med_geometrie_element) MED_NONE); #endif if ( err != MED_VALID) @@ -1846,39 +1934,43 @@ int MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber(int **MEDArrayFamily, for (i=0;i<Connectivity->getNumberOfTypesWithPoly(Connectivity->_entity);i++) { int NumberOfCell=Connectivity->getNumberOfElementsWithPoly(Connectivity->_entity,types[i]); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_2_2::med_int * tmp_MEDArrayFamily = new med_2_2::med_int[NumberOfCell] ; +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + med_2_3::med_int * tmp_MEDArrayFamily = new med_2_3::med_int[NumberOfCell] ; err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), tmp_MEDArrayFamily,NumberOfCell, - (med_2_2::med_entite_maillage) Connectivity->_entity, - (med_2_2::med_geometrie_element)types[i]); + (med_2_3::med_entite_maillage) Connectivity->_entity, + (med_2_3::med_geometrie_element)types[i]); if (err != MED_VALID) { err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), tmp_MEDArrayFamily,NumberOfCell, - med_2_2::MED_MAILLE, - (med_2_2::med_geometrie_element)types[i]); - if (err != MED_VALID) + med_2_3::MED_MAILLE, + (med_2_3::med_geometrie_element)types[i]); + if (err != MED_VALID + && !_ptrMesh->getIsAGrid() ) // (skl for IPAL14260) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<types[i])); } - int ii ; - for ( ii = 0 ; ii < NumberOfCell ; ii++ ) - MEDArrayFamily[i][ii] = tmp_MEDArrayFamily[ii] ; + if (err == MED_VALID) { + int ii ; + for ( ii = 0 ; ii < NumberOfCell ; ii++ ) + MEDArrayFamily[i][ii] = tmp_MEDArrayFamily[ii] ; + } delete [] tmp_MEDArrayFamily ; #else err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), MEDArrayFamily[i],NumberOfCell, - (med_2_2::med_entite_maillage) Connectivity->_entity, - (med_2_2::med_geometrie_element)types[i]); + (med_2_3::med_entite_maillage) Connectivity->_entity, + (med_2_3::med_geometrie_element)types[i]); if (err != MED_VALID) { err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()), MEDArrayFamily[i],NumberOfCell, - med_2_2::MED_MAILLE, - (med_2_2::med_geometrie_element)types[i]); - if (err != MED_VALID) + med_2_3::MED_MAILLE, + (med_2_3::med_geometrie_element)types[i]); + if (err != MED_VALID + && !_ptrMesh->getIsAGrid() ) // it's normal for a grid (PAL14113) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<types[i])); } #endif @@ -1896,8 +1988,9 @@ MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22() } MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, - MESH * ptrMesh): - MED_MESH_DRIVER22(fileName,ptrMesh,MED_WRONLY),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY) + MESH * ptrMesh, + MED_EN::med_mode_acces access): + MED_MESH_DRIVER22(fileName,ptrMesh,access),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,access) { MESSAGE("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created"); } @@ -1910,6 +2003,7 @@ MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const MED_MESH_WRONLY_DRIVER2 MED_MESH_WRONLY_DRIVER22::~MED_MESH_WRONLY_DRIVER22() { //MESSAGE("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed"); + } GENDRIVER * MED_MESH_WRONLY_DRIVER22::copy(void) const @@ -1970,17 +2064,17 @@ void MED_MESH_WRONLY_DRIVER22::write(void) const // test if the family already exists (HDF trick waiting a MED evolution to be replaced) string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_ZERO/"; MESSAGE("|"<<dataGroupFam<<"|"); - err =med_2_2::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ); + err =med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ); if ( err < MED_VALID ) { SCRUTE(err); char familyName[MED_TAILLE_NOM+1]; // strcpy(familyName,"FAMILLE_ZERO"); - err = med_2_2::MEDfamCr( _medIdt, + err = med_2_3::MEDfamCr( _medIdt, const_cast <char *> ( _meshName.c_str() ), familyName, 0, //CCRT (int*)NULL, (int*)NULL, (char*)NULL, 0, - (med_2_2::med_int*)NULL, (med_2_2::med_int*)NULL, (char*)NULL, 0, + (med_2_3::med_int*)NULL, (med_2_3::med_int*)NULL, (char*)NULL, 0, (char*)NULL, 0); SCRUTE(familyName); @@ -1989,7 +2083,7 @@ void MED_MESH_WRONLY_DRIVER22::write(void) const throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_ZERO| with identifier |0| groups names || and attributes descriptions ||")) ; } else - med_2_2::_MEDdatagroupFermer(_medIdt); + med_2_3::_MEDdatagroupFermer(_medIdt); } @@ -2008,7 +2102,7 @@ void MED_MESH_WRONLY_DRIVER22::write(void) const MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyEdge)"); if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)" )) ; - + END_OF(LOC); } @@ -2029,8 +2123,8 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const } GRID * ptrGrid = (GRID*) _ptrMesh; - med_2_2::med_err err = MED_ERROR; - med_2_2::med_repere rep; + med_2_3::med_err err = MED_ERROR; + med_2_3::med_repere rep; string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' '); string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' '); @@ -2040,10 +2134,10 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName> - int spaceDimension = med_2_2::MEDdimEspaceLire(_medIdt, const_cast <char *> + int spaceDimension = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *> (_meshName.c_str()) ); - int meshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *> + int meshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str()) ); @@ -2055,7 +2149,7 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const { err = MEDmaaCr(_medIdt, const_cast <char *> (_meshName.c_str()), - _ptrMesh->_meshDimension,med_2_2::MED_STRUCTURE, + _ptrMesh->_meshDimension,med_2_3::MED_STRUCTURE, const_cast <char *> (_ptrMesh->_description.c_str())); meshDimension = _ptrMesh->_meshDimension; @@ -2077,9 +2171,9 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const MED_EN::med_grid_type gridType = ptrGrid->getGridType(); - err = med_2_2::MEDnatureGrilleEcr(_medIdt, + err = med_2_3::MEDnatureGrilleEcr(_medIdt, const_cast <char *> (_meshName.c_str()), - (med_2_2::med_type_grille) gridType); + (med_2_3::med_type_grille) gridType); if (err != MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to write the type of the Grid")); @@ -2100,20 +2194,20 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const // Pourquoi le stocker sous forme de chaĂƒÂ®ne ? const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem; if (coordinateSystem == "CARTESIAN") - rep = med_2_2::MED_CART; + rep = med_2_3::MED_CART; else if ( coordinateSystem == "CYLINDRICAL") - rep = med_2_2::MED_CYL; + rep = med_2_3::MED_CYL; else if ( coordinateSystem == "SPHERICAL" ) - rep = med_2_2::MED_SPHER; + rep = med_2_3::MED_SPHER; else throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" << _ptrMesh->_coordinate->_coordinateSystem << "|" )) ; - med_2_2::med_int ArrayLen[] = { (med_2_2::med_int) ptrGrid->_iArrayLength, - (med_2_2::med_int) ptrGrid->_jArrayLength, - (med_2_2::med_int) ptrGrid->_kArrayLength }; + med_2_3::med_int ArrayLen[] = { (med_2_3::med_int) ptrGrid->_iArrayLength, + (med_2_3::med_int) ptrGrid->_jArrayLength, + (med_2_3::med_int) ptrGrid->_kArrayLength }; // Write node coordinates for MED_BODY_FITTED grid if (gridType == MED_EN::MED_BODY_FITTED) @@ -2126,7 +2220,7 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const _ptrMesh->_spaceDimension, //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), - med_2_2::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes, + med_2_3::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes rep, const_cast <char *> (tmp_name.c_str()), const_cast <char *> (tmp_unit.c_str())); @@ -2139,13 +2233,13 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const << " |")) ; //CCRT int* structure = new int [meshDimension]; - med_2_2::med_int* structure = new med_2_2::med_int [meshDimension]; + med_2_3::med_int* structure = new med_2_3::med_int [meshDimension]; for (int idim = 0; idim < meshDimension; ++idim) structure[idim] = ArrayLen [idim]; - err = med_2_2::MEDstructureCoordEcr(_medIdt, const_cast <char *> + err = med_2_3::MEDstructureCoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()), meshDimension, structure); @@ -2170,8 +2264,8 @@ int MED_MESH_WRONLY_DRIVER22::writeGRID() const string str_unit = string (tmp_unit,idim*MED_TAILLE_PNOM22, MED_TAILLE_PNOM22); - err = med_2_2::MEDindicesCoordEcr(_medIdt, const_cast <char *> - (_ptrMesh->_name.c_str()), + err = med_2_3::MEDindicesCoordEcr(_medIdt, const_cast <char *> + (_meshName.c_str()), _ptrMesh->_meshDimension, Array[idim], ArrayLen[idim], (idim+1), const_cast <char *> @@ -2200,8 +2294,8 @@ int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const { const char * LOC = "int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const : "; BEGIN_OF(LOC); - med_2_2::med_err err = MED_ERROR; - med_2_2::med_repere rep; + med_2_3::med_err err = MED_ERROR; + med_2_3::med_repere rep; string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' '); string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' '); @@ -2223,10 +2317,10 @@ int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const { // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName> - int spaceDimension = med_2_2::MEDdimEspaceLire(_medIdt, const_cast <char *> + int spaceDimension = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *> (_meshName.c_str())); - int meshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *> + int meshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str()) ); SCRUTE(spaceDimension); @@ -2237,13 +2331,23 @@ int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const { if ((spaceDimension != MED_VALID) && (meshDimension < MED_VALID)) { err = MEDmaaCr(_medIdt, const_cast <char *> (_meshName.c_str()), - _ptrMesh->_meshDimension, med_2_2::MED_NON_STRUCTURE, + _ptrMesh->_meshDimension, med_2_3::MED_NON_STRUCTURE, const_cast <char *> (_ptrMesh->_description.c_str())); if (err < MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|")); else MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !"); + + // PAL14544. Write _spaceDimension if _spaceDimension != _meshDimension + if ( _ptrMesh->_spaceDimension != _ptrMesh->_meshDimension ) + { + err = med_2_3::MEDdimEspaceCr(_medIdt, const_cast <char *> (_meshName.c_str()), + _ptrMesh->_spaceDimension); + if (err < MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write spaceDimension of Mesh : |" + << _meshName << "|")); + } } else if ((spaceDimension != _ptrMesh->_spaceDimension) && (meshDimension != _ptrMesh->_meshDimension)) @@ -2258,11 +2362,11 @@ int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const { // Pourquoi le stocker sous forme de chaĂƒÂ®ne ? const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem; if (coordinateSystem == "CARTESIAN") - rep = med_2_2::MED_CART; + rep = med_2_3::MED_CART; else if ( coordinateSystem == "CYLINDRICAL") - rep = med_2_2::MED_CYL; + rep = med_2_3::MED_CYL; else if ( coordinateSystem == "SPHERICAL" ) - rep = med_2_2::MED_SPHER; + rep = med_2_3::MED_SPHER; else throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" << _ptrMesh->_coordinate->_coordinateSystem @@ -2284,7 +2388,7 @@ int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const { _ptrMesh->_spaceDimension, //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), - med_2_2::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes, + med_2_3::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes rep, const_cast <char *> (tmp_name.c_str()), const_cast <char *> (tmp_unit.c_str())); @@ -2307,22 +2411,22 @@ int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const { if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) const int * NodesNumbers = _ptrMesh->_coordinate->getNodesNumbers() ; - med_2_2::med_int * tmp_NodesNumbers = new med_int[_ptrMesh->_numberOfNodes] ; + med_2_3::med_int * tmp_NodesNumbers = new med_2_3::med_int[_ptrMesh->_numberOfNodes] ; int ii ; for ( ii = 0 ; ii < _ptrMesh->_numberOfNodes ; ii++ ) tmp_NodesNumbers[ii] = NodesNumbers[ii] ; err = MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()), tmp_NodesNumbers , - _ptrMesh->_numberOfNodes, med_2_2::MED_NOEUD, - med_2_2::med_geometrie_element(0) ); + _ptrMesh->_numberOfNodes, med_2_3::MED_NOEUD, + med_2_3::med_geometrie_element(0) ); delete [] tmp_NodesNumbers ; #else err = MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()), const_cast <med_int *> (_ptrMesh->_coordinate->getNodesNumbers() ), - _ptrMesh->_numberOfNodes, med_2_2::MED_NOEUD, - med_2_2::med_geometrie_element(0) ); + _ptrMesh->_numberOfNodes, med_2_3::MED_NOEUD, + med_2_3::med_geometrie_element(0) ); #endif if (err != MED_VALID) @@ -2345,7 +2449,7 @@ int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeConnectivities() const : "; BEGIN_OF(LOC); - med_2_2::med_err err; + med_2_3::med_err err; // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB ! // PG : IMPOSSIBLE : LA METHODE EST PRIVEE ! @@ -2357,92 +2461,95 @@ int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const // Nodal connectivity for classic geometric types - if ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) + if ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) { + int numberOfTypes = _ptrMesh->getNumberOfTypes(entity); + const medGeometryElement * types = _ptrMesh->getTypes(entity); - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - const medGeometryElement * types = _ptrMesh->getTypes (entity) ; - - for (int i=0; i<numberOfTypes; i++) + for (int i=0; i<numberOfTypes; i++) { + int numberOfElements = _ptrMesh->getNumberOfElements(entity,types[i]); + const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, + MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ?? - int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]); - const int * connectivity = _ptrMesh->getConnectivity (MED_EN::MED_FULL_INTERLACE, - MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ?? - // Pour l'instant la class utilise le multi..... - int multi = 0 ; + int multi = 0; // if (entity==MED_EN::MED_CELL) - // if ( (types[i]/ 100) < _ptrMesh->_spaceDimension) - // multi=1 ; - int numberOfNodes = types[i]%100 ; + // if ( (types[i]/ 100) < _ptrMesh->_spaceDimension) + // multi=1; + int numberOfNodes = types[i]%100; //CCRT int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)]; - med_2_2::med_int * connectivityArray = new med_2_2::med_int[numberOfElements*(numberOfNodes+multi)]; - - // version originale sans prise en compte des numĂƒÂ©ros optionnels - // - for (int j=0 ; j<numberOfElements; j++) + med_2_3::med_int * connectivityArray = new med_2_3::med_int[numberOfElements*(numberOfNodes+multi)]; + + // version originale sans prise en compte des numĂƒÂ©ros optionnels + // + for (int j=0 ; j<numberOfElements; j++) { for (int k=0; k<numberOfNodes; k++) - connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ; + connectivityArray[j*(numberOfNodes+multi)+k] = connectivity[j*numberOfNodes+k]; - if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0; + if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes] = 0; } - + ////////////////////////////////////////////////////////////////////////////////////// - /// Modification pour prise en compte de la numĂƒÂ©rotation optionnelle des noeuds /// - ////////////////////////////////////////////////////////////////////////////////////// - /// - /// DĂƒÂ©numĂƒÂ©rote les sommets des mailles pour leur rendre leurs numĂƒÂ©ros optionnels - /// Le traitement est identique ĂƒÂ  la version originelle s'il n'y a pas de numĂƒÂ©rotation optionnelle - - // if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) - // { - // const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers(); - // for (int j=0 ; j<numberOfElements; j++) - // { - // for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=nodesNumbers[connectivity[j*numberOfNodes+k]-1] ; - // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0; - // } - // } - // else - // { - // for (int j=0 ; j<numberOfElements; j++) - // { - // for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ; - // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0; - // } - // } - - ////////////////////////////////////////////////////////////////////////////////////// - - // err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension, - // connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements, - // MED_FR::MED_LECTURE_ECRITURE, - // (MED_FR::med_entite_maillage ) entity, - // (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD ); - - // err = MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()), - // _ptrMesh->_spaceDimension, connectivityArray, - // MED_FR::MED_FULL_INTERLACE , numberOfElements, - // (MED_FR::med_entite_maillage ) entity, - // (MED_FR::med_geometrie_element) types[i], - // med_2_2::MED_NOD); - - err = MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()), - _ptrMesh->_spaceDimension, connectivityArray, - med_2_2::MED_FULL_INTERLACE , numberOfElements, -// (med_2_2::med_entite_maillage ) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage ) MED_CELL, - (med_2_2::med_geometrie_element) types[i], - med_2_2::MED_NOD); - - delete[] connectivityArray ; - - if (err<0) // ETENDRE LES EXPLICATIONS - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )); + /// Modification pour prise en compte de la numĂƒÂ©rotation optionnelle des noeuds /// + ////////////////////////////////////////////////////////////////////////////////////// + /// + /// DĂƒÂ©numĂƒÂ©rote les sommets des mailles pour leur rendre leurs numĂƒÂ©ros optionnels + /// Le traitement est identique ĂƒÂ  la version originelle s'il n'y a pas de numĂƒÂ©rotation optionnelle + + //if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) + //{ + // const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers(); + // for (int j=0 ; j<numberOfElements; j++) + // { + // for (int k=0; k<numberOfNodes; k++) + // connectivityArray[j*(numberOfNodes+multi)+k] = + // nodesNumbers[connectivity[j*numberOfNodes+k]-1]; + // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes] = 0; + // } + //} + //else + //{ + // for (int j=0 ; j<numberOfElements; j++) + // { + // for (int k=0; k<numberOfNodes; k++) + // connectivityArray[j*(numberOfNodes+multi)+k] = connectivity[j*numberOfNodes+k]; + // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0; + // } + //} + + ////////////////////////////////////////////////////////////////////////////////////// + + //err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), + // _ptrMesh->_spaceDimension, connectivityArray, + // MED_FR::MED_FULL_INTERLACE, numberOfElements, + // MED_FR::MED_LECTURE_ECRITURE, + // (MED_FR::med_entite_maillage ) entity, + // (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD); + + //err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), + // _ptrMesh->_spaceDimension, connectivityArray, + // MED_FR::MED_FULL_INTERLACE, numberOfElements, + // (MED_FR::med_entite_maillage ) entity, + // (MED_FR::med_geometrie_element) types[i], med_2_3::MED_NOD); + + err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), + _ptrMesh->_spaceDimension, connectivityArray, + med_2_3::MED_FULL_INTERLACE, numberOfElements, + //(med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage ) MED_CELL, + (med_2_3::med_geometrie_element) types[i], med_2_3::MED_NOD); + err = med_2_3::MEDdimEspaceCr + (_medIdt, const_cast<char *>(_meshName.c_str()), _ptrMesh->_spaceDimension); + + delete[] connectivityArray; + + if (err<0) // ETENDRE LES EXPLICATIONS + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" + << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )); } } @@ -2451,104 +2558,121 @@ int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const // Polygons writing if (_ptrMesh->existPolygonsConnectivity(MED_NODAL,entity)) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_2_2::med_int * tmp_PolygonsConnectivityIndex = new med_2_2::med_int[_ptrMesh->getNumberOfPolygons()+1] ; - const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity) ; - int ii ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolygons()+1 ; ii++ ) - tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii] ; - med_2_2::med_int * tmp_PolygonsConnectivity = new med_2_2::med_int[_ptrMesh->getNumberOfPolygons()+1] ; - const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_NODAL,entity) ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolygons()+1 ; ii++ ) - tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii] ; + int nbPolygons = _ptrMesh->getNumberOfPolygons(entity); + const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity); + const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_NODAL, entity); + +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int ii, polygonsConnectivityLength = _ptrMesh->getPolygonsConnectivityLength(MED_NODAL, entity); + + med_2_3::med_int * tmp_PolygonsConnectivityIndex = new med_2_3::med_int[nbPolygons + 1]; + for (ii = 0; ii < nbPolygons + 1; ii++) + tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii]; + + med_2_3::med_int * tmp_PolygonsConnectivity = new med_2_3::med_int[polygonsConnectivityLength]; + for (ii = 0; ii < polygonsConnectivityLength; ii++) + tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii]; + err = MEDpolygoneConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), tmp_PolygonsConnectivityIndex, - _ptrMesh->getNumberOfPolygons(entity)+1, + nbPolygons + 1, tmp_PolygonsConnectivity, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - med_2_2::MED_NOD); - delete [] tmp_PolygonsConnectivityIndex ; - delete [] tmp_PolygonsConnectivity ; + //(med_2_3::med_entite_maillage) entity, + //because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + med_2_3::MED_NOD); + + delete [] tmp_PolygonsConnectivityIndex; + delete [] tmp_PolygonsConnectivity; #else err = MEDpolygoneConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), - const_cast <med_int*> (_ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity)), - _ptrMesh->getNumberOfPolygons(entity)+1, - const_cast <med_int*> (_ptrMesh->getPolygonsConnectivity(MED_NODAL,entity)), -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - med_2_2::MED_NOD); + const_cast <med_int*> (PolygonsConnectivityIndex), + nbPolygons + 1, + const_cast <med_int*> (PolygonsConnectivity), + //(med_2_3::med_entite_maillage) entity, + //because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + med_2_3::MED_NOD); #endif if (err<0) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )); + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |" + << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )); } // Polyhedron writing if (_ptrMesh->existPolyhedronConnectivity(MED_NODAL,entity)) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_2_2::med_int * tmp_PolyhedronIndex = new med_2_2::med_int[_ptrMesh->getNumberOfPolyhedron()+1] ; - const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_NODAL) ; - int ii ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolyhedron()+1 ; ii++ ) - tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii] ; - med_2_2::med_int * tmp_PolyhedronFacesIndex = new med_2_2::med_int[_ptrMesh->getNumberOfPolyhedronFaces()+1] ; - const int * PolyhedronFacesIndex = _ptrMesh->getPolyhedronFacesIndex() ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolyhedronFaces()+1 ; ii++ ) - tmp_PolyhedronFacesIndex[ii] = PolyhedronFacesIndex[ii] ; - med_2_2::med_int * tmp_PolyhedronConnectivity = new med_2_2::med_int[_ptrMesh->getNumberOfPolyhedronFaces()+1] ; - const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_NODAL) ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolyhedronFaces()+1 ; ii++ ) - tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii] ; + //int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron(entity); + int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron(); + int nbPolyhedronFaces = _ptrMesh->getNumberOfPolyhedronFaces(); + const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_NODAL); + const int * PolyhedronFacesIndex = _ptrMesh->getPolyhedronFacesIndex(); + const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_NODAL); + +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int ii, polyhedronConnectivityLength = _ptrMesh->getPolyhedronConnectivityLength(MED_NODAL); + + med_2_3::med_int * tmp_PolyhedronIndex = new med_2_3::med_int[nbPolyhedron + 1]; + for (ii = 0; ii < nbPolyhedron + 1; ii++) + tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii]; + + med_2_3::med_int * tmp_PolyhedronFacesIndex = new med_2_3::med_int[nbPolyhedronFaces + 1]; + for (ii = 0; ii < nbPolyhedronFaces + 1; ii++) + tmp_PolyhedronFacesIndex[ii] = PolyhedronFacesIndex[ii]; + + med_2_3::med_int * tmp_PolyhedronConnectivity = new med_2_3::med_int[polyhedronConnectivityLength]; + for (ii = 0; ii < polyhedronConnectivityLength; ii++) + tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii]; + err = MEDpolyedreConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), tmp_PolyhedronIndex, - _ptrMesh->getNumberOfPolyhedron()+1, + nbPolyhedron + 1, tmp_PolyhedronFacesIndex, - _ptrMesh->getNumberOfPolyhedronFaces()+1, + nbPolyhedronFaces + 1, tmp_PolyhedronConnectivity, - med_2_2::MED_NOD); - delete [] tmp_PolyhedronIndex ; - delete [] tmp_PolyhedronFacesIndex ; - delete [] tmp_PolyhedronConnectivity ; + med_2_3::MED_NOD); + + delete [] tmp_PolyhedronIndex; + delete [] tmp_PolyhedronFacesIndex; + delete [] tmp_PolyhedronConnectivity; #else err = MEDpolyedreConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), - const_cast <med_int*> (_ptrMesh->getPolyhedronIndex(MED_NODAL)), - _ptrMesh->getNumberOfPolyhedron()+1, - const_cast <med_int*> (_ptrMesh->getPolyhedronFacesIndex()), - _ptrMesh->getNumberOfPolyhedronFaces()+1, - const_cast <med_int*> (_ptrMesh->getPolyhedronConnectivity(MED_NODAL)), - med_2_2::MED_NOD); + const_cast <med_int*> (PolyhedronIndex), + nbPolyhedron + 1, + const_cast <med_int*> (PolyhedronFacesIndex), + nbPolyhedronFaces + 1, + const_cast <med_int*> (PolyhedronConnectivity), + med_2_3::MED_NOD); #endif if (err<0) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )); + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |" + << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )); } // Descending connectivity for classic geometric types - if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) + if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) { - - int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; - const medGeometryElement * types = _ptrMesh->getTypes (entity) ; + int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; + const medGeometryElement * types = _ptrMesh->getTypes (entity) ; for (int i=0; i<numberOfTypes; i++) { - - int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]); + int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]); const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); - // Pour l'instant la class utilise le multi..... + // Pour l'instant la class utilise le multi..... // err = MED_FR::MEDconnEcr( _medIdt, // const_cast <char *> ( _meshName.c_str()), // _ptrMesh->_spaceDimension, @@ -2560,37 +2684,41 @@ int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const // (MED_FR::med_geometrie_element) types[i], // MED_FR::MED_DESC ); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_2_2::med_int * tmp_Connectivity = new med_2_2::med_int[numberOfElements] ; +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int lgth = _ptrMesh->getConnectivityLength(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); + med_2_3::med_int * tmp_Connectivity = new med_2_3::med_int[lgth] ; int ii ; - for ( ii = 0 ; ii < numberOfElements ; ii++ ) + for ( ii = 0 ; ii < lgth ; ii++ ) tmp_Connectivity[ii] = connectivity[ii] ; - err = med_2_2::MEDconnEcr(_medIdt, + err = med_2_3::MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension, tmp_Connectivity, - med_2_2::MED_FULL_INTERLACE, + med_2_3::MED_FULL_INTERLACE, numberOfElements, -// (med_2_2::med_entite_maillage ) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i], - med_2_2::MED_DESC ); + //(med_2_3::med_entite_maillage ) entity, + //because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage ) MED_CELL, + (med_2_3::med_geometrie_element) types[i], + med_2_3::MED_DESC); delete [] tmp_Connectivity ; #else - err = med_2_2::MEDconnEcr(_medIdt, + err = med_2_3::MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension, const_cast <int *> (connectivity), - med_2_2::MED_FULL_INTERLACE, + med_2_3::MED_FULL_INTERLACE, numberOfElements, -// (med_2_2::med_entite_maillage ) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage ) MED_CELL, - (med_2_2::med_geometrie_element) types[i], - med_2_2::MED_DESC ); + //(med_2_3::med_entite_maillage ) entity, + //because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage ) MED_CELL, + (med_2_3::med_geometrie_element) types[i], + med_2_3::MED_DESC); #endif if (err<0) // ETENDRE LES EXPLICATIONS - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" + << _meshName.c_str() << "| in file |" << _fileName << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" )) ; @@ -2601,85 +2729,103 @@ int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const // Polygons writing if (_ptrMesh->existPolygonsConnectivity(MED_DESCENDING,entity)) { -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_2_2::med_int * tmp_PolygonsConnectivityIndex = new med_2_2::med_int[_ptrMesh->getNumberOfPolygons()+1] ; - const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING,entity) ; - int ii ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolygons()+1 ; ii++ ) - tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii] ; - med_2_2::med_int * tmp_PolygonsConnectivity = new med_2_2::med_int[_ptrMesh->getNumberOfPolygons()+1] ; - const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_DESCENDING,entity) ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolygons()+1 ; ii++ ) - tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii] ; + int nbPolygons = _ptrMesh->getNumberOfPolygons(entity); + // ??? //int nbPolygons = _ptrMesh->getNumberOfPolygons(); + const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING, entity); + const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_DESCENDING, entity); + +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int ii, polygonsConnectivityLength = _ptrMesh->getPolygonsConnectivityLength(MED_DESCENDING, entity); + + med_2_3::med_int * tmp_PolygonsConnectivityIndex = new med_2_3::med_int[nbPolygons + 1]; + for (ii = 0; ii < nbPolygons + 1; ii++) + tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii]; + + med_2_3::med_int * tmp_PolygonsConnectivity = new med_2_3::med_int[polygonsConnectivityLength]; + for (ii = 0; ii < polygonsConnectivityLength; ii++) + tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii]; + err = MEDpolygoneConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), tmp_PolygonsConnectivityIndex, - _ptrMesh->getNumberOfPolygons()+1, + nbPolygons + 1, tmp_PolygonsConnectivity, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage ) MED_CELL, - med_2_2::MED_DESC); - delete [] tmp_PolygonsConnectivityIndex ; - delete [] tmp_PolygonsConnectivity ; + //(med_2_3::med_entite_maillage) entity, + //because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + med_2_3::MED_DESC); + + delete [] tmp_PolygonsConnectivityIndex; + delete [] tmp_PolygonsConnectivity; #else err = MEDpolygoneConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), - const_cast <med_int*> (_ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING,entity)), - _ptrMesh->getNumberOfPolygons()+1, - const_cast <med_int*> (_ptrMesh->getPolygonsConnectivity(MED_DESCENDING,entity)), -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage ) MED_CELL, - med_2_2::MED_DESC); + const_cast <med_int*> (PolygonsConnectivityIndex), + nbPolygons + 1, + const_cast <med_int*> (PolygonsConnectivity), + //(med_2_3::med_entite_maillage) entity, + //because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) entity, + med_2_3::MED_DESC); #endif if (err<0) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons descending connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )); + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons descending connectivities of mesh |" + << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )); } // Polyhedron writing - if (_ptrMesh->existPolyhedronConnectivity(MED_DESCENDING,entity)) + if (_ptrMesh->existPolyhedronConnectivity(MED_DESCENDING, entity)) { - med_int NumberOfFaces = _ptrMesh->getPolyhedronIndex(MED_DESCENDING)[_ptrMesh->getNumberOfPolyhedron()]-1; - vector<med_int> FacesGeometricTypes(NumberOfFaces,MED_POLYGON); // by default all polyhedron faces are polygons - -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) - med_2_2::med_int * tmp_PolyhedronIndex = new med_2_2::med_int[_ptrMesh->getNumberOfPolyhedron()+1] ; - const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_DESCENDING) ; - int ii ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolyhedron()+1 ; ii++ ) - tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii] ; - med_2_2::med_int * tmp_PolyhedronConnectivity = new med_2_2::med_int[_ptrMesh->getNumberOfPolyhedronFaces()+1] ; - const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_DESCENDING) ; - for ( ii = 0 ; ii < _ptrMesh->getNumberOfPolyhedronFaces()+1 ; ii++ ) - tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii] ; + med_2_3::med_int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron(); + med_2_3::med_int NumberOfFaces = _ptrMesh->getNumberOfPolyhedronFaces(); + // ??? //_ptrMesh->getPolyhedronIndex(MED_DESCENDING)[nbPolyhedron] - 1; + // by default all polyhedron faces are polygons + vector<med_2_3::med_int> FacesGeometricTypes (NumberOfFaces, MED_POLYGON); + const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_DESCENDING); + const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_DESCENDING); + +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) + int ii, polyhedronConnectivityLength = _ptrMesh->getPolyhedronConnectivityLength(MED_DESCENDING); + + med_2_3::med_int * tmp_PolyhedronIndex = new med_2_3::med_int[nbPolyhedron + 1]; + for (ii = 0; ii < nbPolyhedron + 1; ii++) + tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii]; + + med_2_3::med_int * tmp_PolyhedronConnectivity = new med_2_3::med_int[polyhedronConnectivityLength]; + for (ii = 0; ii < polyhedronConnectivityLength; ii++) + tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii]; + err = MEDpolyedreConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), tmp_PolyhedronIndex, - _ptrMesh->getNumberOfPolyhedron()+1, + nbPolyhedron + 1, &FacesGeometricTypes[0], NumberOfFaces, tmp_PolyhedronConnectivity, - med_2_2::MED_DESC); - delete [] tmp_PolyhedronIndex ; - delete [] tmp_PolyhedronConnectivity ; + med_2_3::MED_DESC); + + delete [] tmp_PolyhedronIndex; + delete [] tmp_PolyhedronConnectivity; #else err = MEDpolyedreConnEcr(_medIdt, const_cast <char *> (_meshName.c_str()), - const_cast <med_int*> (_ptrMesh->getPolyhedronIndex(MED_DESCENDING)), - _ptrMesh->getNumberOfPolyhedron()+1, + const_cast <med_int*> (PolyhedronIndex), + nbPolyhedron + 1, &FacesGeometricTypes[0], NumberOfFaces, - const_cast <med_int*> (_ptrMesh->getPolyhedronConnectivity(MED_DESCENDING)), - med_2_2::MED_DESC); + const_cast <med_int*> (PolyhedronConnectivity), + med_2_3::MED_DESC); #endif if (err<0) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron descending connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName - << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" - )); + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron descending connectivities of mesh |" + << _meshName.c_str() << "| in file |" << _fileName + << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and" + )); } @@ -2687,12 +2833,209 @@ int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const return MED_VALID; } +/*!creates a vector of families from a vector of groups + * + * \param myGroups input : vector of groups + * \param myFamilies output vector of families + * + * Routine is meant to be called to reconstruct families from existing groups + * typically for writing meshes created by MEDMEM::MESHING containing overlapping groups + * + * if the groups do not overlap, the vector of families will have the same size + * as the vector of groups + * otherwise, the size of the family vector will be larger +*/ + +void MED_MESH_WRONLY_DRIVER22::groupFamilyConverter(const vector <GROUP*>& myGroups, vector <FAMILY*>& myFamilies ) const +{ + + BEGIN_OF("MED_MESH_WRONLY_DRIVER::groupFamilyConverter"); + if (myGroups.empty()) return; + +// if (!myFamilies.empty()) +// throw MEDEXCEPTION(LOCALIZED("Family vector must be empty on call " +// << "to groupFamilyConverter")); +// + //mapping elements to all the groups containing it + std::multimap <int,int> elem2groups; + for (int igroup=0; igroup< myGroups.size(); igroup++) + { + // if the support is on all Mesh elements + //all the items from 1 to nb are in the group + if (myGroups[igroup]->isOnAllElements()) + { + for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++) + { + elem2groups.insert(make_pair(ielem+1, igroup)); + } + } + //otherwise getNumber() gives the appropriate number of items + else + { + const int*Number = myGroups[igroup]->getNumber(MED_ALL_ELEMENTS) ; + for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++) + { + elem2groups.insert(make_pair(Number[ielem], igroup)); + } + } + } + + //creating a set of signatures for the groups intersections + std::multimap<vector<int>,int> signatures; + + typedef multimap<int,int>::iterator MI; + MI iter=elem2groups.begin(); + + while (iter!=elem2groups.end()) + { + vector<int> sign (1, iter -> second ); + int key = iter -> first; + iter ++; + while (iter!=elem2groups.end()&&iter-> first == key) + { + sign.push_back(iter -> second); + iter++; + } + signatures.insert(make_pair(sign,key)); + } + + elem2groups.clear(); + + //creating the families from the signatures mapping + //each signature will correspond to a new family + std::multimap<vector<int>,int>::const_iterator iter_signatures = signatures.begin(); + + //retrieving the entity type (all the groups have the same) + // node families are numbered above 0 + // cell families are numbered from -1 to -MAX_NB_GROUPS + // face falimies are numbered from -MAX_NB_GROUPS-1 to -2*MAX_NB_GROUPS + // edge families are numbered from -2*MAX_NB_GROUPS to -3*MAX_NB_GROUPS + // MAX_NB_GROUPS is defined in MEDMEM_define.hxx + + medEntityMesh entity = myGroups[0]->getEntity(); + MESH* mesh=myGroups[0]->getMesh(); + + int ifamily; + switch (entity) + { + case MED_NODE: + ifamily=1; + break; + case MED_CELL: + ifamily=-MAX_NB_GROUP; + break; + case MED_FACE: + ifamily=-2*MAX_NB_GROUP; + break; + case MED_EDGE: + ifamily=-3*MAX_NB_GROUP; + break; + } + + //browsing signatures to build all the families + //each signature corresponds to a new family + + while (iter_signatures!= signatures.end()) + { + const vector<int>& key= iter_signatures->first; + int size = signatures.count(key); + + list<int> numbers; + + for (int i=0; i< size; i++) + { + numbers.push_back(iter_signatures->second); + iter_signatures++; + } + + //TODO : see if build SupportOnElementFromElementList could not be built from another container + + // for nodes, the family is built directly from the node list + // for elements, it is built from the buildSupportOnElementsFromElementList + // which allocates a support + FAMILY* myFamily; + if (entity!=MED_NODE) + { + SUPPORT* support; + support=mesh->buildSupportOnElementsFromElementList(numbers, entity); + myFamily=new FAMILY(*support); + delete support; + } + else + { + myFamily= new FAMILY(); + myFamily->setMesh(mesh); + myFamily->fillFromNodeList(numbers); + } + + + // the identifier and the groups are set + myFamily->setIdentifier(ifamily); + myFamily->setNumberOfGroups(key.size()); + char family_name[MED_TAILLE_NOM]; + + //if the family has one group to which only one family + //is associated, the name of the family underlying the group + //is given back to the family + if (key.size()==1 && myGroups[key[0]]->getNumberOfFamilies()==0) + { + vector<FAMILY*> families; + families.push_back(myFamily); + myGroups[key[0]]->setFamilies(families); + //it is necessary to use strncpy because group and family + //have different name sizes + strncpy(family_name,myGroups[key[0]]->getName().c_str(),MED_TAILLE_NOM); + family_name[MED_TAILLE_NOM-1]='\0'; + } + else + sprintf(family_name,"family%d",ifamily); + + myFamily->setName(family_name); + + string* groupnames=new string[key.size()]; + //myFamily->getGroupsNames(); + //groupnames.set(key.size()); + + for (int igroup=0; igroup<key.size(); igroup++) + { + groupnames[igroup]=myGroups[key[igroup]]->getName(); + } + + myFamily->setGroupsNames(groupnames,true); + + myFamilies.push_back(myFamily); + ifamily++; + } + + //adding empty families corresponding to empty groups + for (int i=0; i<myGroups.size(); i++) + { + if (myGroups[i]->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)==0) + { + FAMILY* myFamily=new FAMILY(*(myGroups[i])); + char family_name[MED_TAILLE_NOM]; + //it is necessary to use strncpy because group and family + //have different name sizes + strncpy(family_name,myGroups[i]->getName().c_str(),MED_TAILLE_NOM); + family_name[MED_TAILLE_NOM-1]='\0'; + myFamily->setName(family_name); + myFamily->setIdentifier(ifamily); + ifamily++; + vector<string> groupnames; + groupnames.push_back(myGroups[i]->getName()); + myFamily->setGroupsNames(&groupnames[0]); + myFamilies.push_back(myFamily); + } + } + END_OF("MED_MESH_WRONLY_DRIVER::groupFamilyConverter"); +} + int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const : "; BEGIN_OF(LOC); - med_2_2::med_err err; + med_2_3::med_err err; // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH @@ -2701,25 +3044,20 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { // We build the array from the families list objects : int NumberOfNodes = _ptrMesh->getNumberOfNodes() ; //CCRT int * MEDArrayNodeFamily = new int[NumberOfNodes] ; - med_2_2::med_int * MEDArrayNodeFamily = new med_2_2::med_int[NumberOfNodes] ; + med_2_3::med_int * MEDArrayNodeFamily = new med_2_3::med_int[NumberOfNodes] ; // family 0 by default for (int i=0; i<NumberOfNodes; i++) MEDArrayNodeFamily[i]=0; //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(MED_NODE); vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode; int NumberOfNodesFamilies = myFamilies->size() ; - //bool ToDestroy = false; + // bool ToDestroy = false; if (0 == NumberOfNodesFamilies) { - //ToDestroy = true ; + // ToDestroy = true ; vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE); - int NumberOfGroups = myGroups.size() ; - // build families from groups - for (int i=0; i<NumberOfGroups; i++) { - SUPPORT * mySupport = myGroups[i] ; - FAMILY* myFamily = new FAMILY(*mySupport); - myFamily->setIdentifier(i+1); - myFamilies->push_back(myFamily); - } + + groupFamilyConverter(myGroups,*myFamilies); + NumberOfNodesFamilies=myFamilies->size() ; } for (int i=0 ; i<NumberOfNodesFamilies; i++) { @@ -2737,15 +3075,15 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { } } - for(int j=0; j<NumberOfNodes; j++) { - SCRUTE(MEDArrayNodeFamily[j]); - } +// for(int j=0; j<NumberOfNodes; j++) { +// SCRUTE(MEDArrayNodeFamily[j]); +// } // if ( !_ptrMesh->getIsAGrid() ) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), - MEDArrayNodeFamily, NumberOfNodes, med_2_2::MED_NOEUD, - (med_2_2::med_geometrie_element) MED_NONE); + MEDArrayNodeFamily, NumberOfNodes, med_2_3::MED_NOEUD, + (med_2_3::med_geometrie_element) MED_NONE); // else // err = MEDfamGridEcr(_medIdt, @@ -2760,21 +3098,24 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|" )); delete[] MEDArrayNodeFamily; - //if (true == ToDestroy) - // for (int i=0; i<NumberOfNodesFamilies; i++) - // delete myFamilies[i]; +//if (true == ToDestroy) +// for (int i=0; i<NumberOfNodesFamilies; i++) +// delete (*myFamilies)[i]; } { // CELLS RELATED BLOCK medEntityMesh entity=MED_EN::MED_CELL; // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH - if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { - + if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID + (_ptrMesh->existConnectivityWithPoly(MED_NODAL,entity)) || + (_ptrMesh->existConnectivityWithPoly(MED_DESCENDING,entity))) + { int numberOfTypes = _ptrMesh->getNumberOfTypesWithPoly(entity) ; medGeometryElement * types = _ptrMesh->getTypesWithPoly(entity) ; // We build the array from the families list objects : - int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS); + //int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS); + int NumberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity, MED_ALL_ELEMENTS); int * MEDArrayFamily = new int[NumberOfElements] ; // family 0 by default for (int i=0; i<NumberOfElements; i++) @@ -2782,19 +3123,11 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity); vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell ; int NumberOfFamilies = myFamilies->size() ; - //bool ToDestroy = false; + // bool ToDestroy = false; if (0 == NumberOfFamilies) { - //ToDestroy = true ; +// ToDestroy = true ; vector<GROUP*> myGroups = _ptrMesh->getGroups(entity); - int NumberOfGroups = myGroups.size() ; - // build families from groups - for (int i=0; i<NumberOfGroups; i++) { - SCRUTE( myGroups[i]->getName() ); - SUPPORT * mySupport = myGroups[i] ; - FAMILY* myFamily = new FAMILY(*mySupport); - myFamily->setIdentifier(-i-1); - myFamilies->push_back(myFamily); - } + groupFamilyConverter(myGroups,*myFamilies); NumberOfFamilies=myFamilies->size() ; } for (int i=0 ; i<NumberOfFamilies; i++) { @@ -2812,60 +3145,64 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { - for (int i=0; i<NumberOfElements; i++) - SCRUTE(MEDArrayFamily[i]); +// for (int i=0; i<NumberOfElements; i++) +// SCRUTE(MEDArrayFamily[i]); + //const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity); int offset=0; -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=NumberOfElements; - med_2_2::med_int *temp=new med_2_2::med_int[lgth]; + med_2_3::med_int *temp=new med_2_3::med_int[lgth]; for(int i2=0;i2<lgth;i2++) - temp[i2]=(med_2_2::med_int) (MEDArrayFamily[i2]); + temp[i2]=(med_2_3::med_int) (MEDArrayFamily[i2]); #endif for (int i=0; i<numberOfTypes; i++) { - int typeNumberOfElements=_ptrMesh->getNumberOfElementsWithPoly(entity,types[i]); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) + int typeNumberOfElements=_ptrMesh->getNumberOfElementsWithPoly(entity,types[i]); +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), - (temp+offset),(typeCount[i+1]-typeCount[i]), - //CCRT med_2_2::MED_REMP , -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i]); + //(temp+offset),(typeCount[i+1]-typeCount[i]), + (temp+offset), typeNumberOfElements, + //CCRT med_2_3::MED_REMP , +// (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + (med_2_3::med_geometrie_element) types[i]); #else err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), (MEDArrayFamily+offset), typeNumberOfElements, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i]); +// (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + (med_2_3::med_geometrie_element) types[i]); #endif MESSAGE("OK "<<i); - if ( err != MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i]) - << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |" - << _ptrMesh->_name.c_str() << "|" )); - offset+=typeNumberOfElements; + if ( err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements + << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |" + << _ptrMesh->_name.c_str() << "|" )); + offset+=typeNumberOfElements; } //CCRT Clutter -//CCRT#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +//CCRT#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) //CCRT delete [] temp; //CCRT#endif delete[] MEDArrayFamily ; delete[] types; - //if (true == ToDestroy) { - // int NumberOfFamilies = myFamilies->size(); - // for (int i=0; i<NumberOfFamilies; i++) - // delete myFamilies[i]; - //} +// if (true == ToDestroy) { +// int NumberOfFamilies = myFamilies->size(); +// for (int i=0; i<NumberOfFamilies; i++) +// delete (*myFamilies)[i]; +// } } } { // FACE RELATED BLOCK medEntityMesh entity=MED_EN::MED_FACE; // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH - if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { - + if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID + (_ptrMesh->existConnectivityWithPoly(MED_NODAL,entity)) || + (_ptrMesh->existConnectivityWithPoly(MED_DESCENDING,entity))) + { int numberOfTypes = _ptrMesh->getNumberOfTypesWithPoly(entity) ; medGeometryElement * types = _ptrMesh->getTypesWithPoly(entity) ; SCRUTE(numberOfTypes); @@ -2878,19 +3215,13 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ; //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ; vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace ; - //bool ToDestroy = false; + // bool ToDestroy = false; if (0 == numberOfFamilies) { //ToDestroy = true ; vector<GROUP*> myGroups = _ptrMesh->getGroups(entity); - int NumberOfGroups = myGroups.size() ; - // build families from groups - for (int i=0; i<NumberOfGroups; i++) { - SCRUTE( myGroups[i]->getName() ); - SUPPORT * mySupport = myGroups[i] ; - FAMILY* myFamily = new FAMILY(*mySupport); - myFamily->setIdentifier(-i-1000); - myFamilies->push_back(myFamily); - } + + groupFamilyConverter(myGroups,*myFamilies); + numberOfFamilies=myFamilies->size() ; } for (int i=0;i<numberOfFamilies;i++) { @@ -2910,11 +3241,11 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { SCRUTE(familyArray[i]); //CCRT Clutter -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=numberOfElements; - med_2_2::med_int *temp=new med_2_2::med_int[lgth]; + med_2_3::med_int *temp=new med_2_3::med_int[lgth]; for(int i2=0;i2<lgth;i2++) - temp[i2]=(med_2_2::med_int) (familyArray[i2]); + temp[i2]=(med_2_3::med_int) (familyArray[i2]); #endif SCRUTE(numberOfTypes); int offset=0; @@ -2922,39 +3253,39 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { int typeNumberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity,types[i]) ; SCRUTE(typeNumberOfElements); SCRUTE(offset); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), (temp+offset), typeNumberOfElements, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i]); +// (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + (med_2_3::med_geometrie_element) types[i]); #else MESSAGE("On est bien la !!! entity = " << entity << " type " << types[i]); err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), (familyArray+offset), typeNumberOfElements, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i]); +// (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + (med_2_3::med_geometrie_element) types[i]); #endif - if ( err != MED_VALID) - throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElementsWithPoly(entity, types[i]) - << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |" - << _ptrMesh->_name.c_str() << "|" )); - offset+=typeNumberOfElements; + if ( err != MED_VALID) + throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements + << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |" + << _ptrMesh->_name.c_str() << "|" )); + offset+=typeNumberOfElements; } //CCRT there was "temp" and "familyArray" for OSF, but only "familyArray" for Linux ... -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) delete [] temp; //CCRT#endif #endif delete[] familyArray ; delete[] types; - //if (true == ToDestroy) { - // int NumberOfFamilies = myFamilies->size(); - // for (int i=0; i<NumberOfFamilies; i++) - // delete myFamilies[i]; - //} +// if (true == ToDestroy) { +// int NumberOfFamilies = myFamilies->size(); +// for (int i=0; i<NumberOfFamilies; i++) +// delete (*myFamilies)[i]; +// } } } @@ -2962,14 +3293,16 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { //medEntityMesh entity=MED_EN::MED_FACE; medEntityMesh entity=MED_EN::MED_EDGE; // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH - if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { + if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID + ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) || + ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ; const medGeometryElement * types = _ptrMesh->getTypes (entity) ; int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ; int * familyArray = new int[numberOfElements] ; - // med_2_2::med_int * familyArray = new int[numberOfElements] ; + // med_2_3::med_int * familyArray = new int[numberOfElements] ; for (int i=0;i<numberOfElements;i++) familyArray[i]=0; @@ -2980,17 +3313,13 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { if (0 == numberOfFamilies) { //ToDestroy = true ; vector<GROUP*> myGroups = _ptrMesh->getGroups(entity); - int NumberOfGroups = myGroups.size() ; - // build families from groups - for (int i=0; i<NumberOfGroups; i++) { - SCRUTE( myGroups[i]->getName() ); - SUPPORT * mySupport = myGroups[i] ; - FAMILY* myFamily = new FAMILY(*mySupport); - myFamily->setIdentifier(-i-2000); - myFamilies->push_back(myFamily); - } + + groupFamilyConverter(myGroups,*myFamilies); + numberOfFamilies=myFamilies->size() ; + } + for (int i=0;i<numberOfFamilies;i++) { int familyNumber = (*myFamilies)[i]->getIdentifier() ; int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ; @@ -3011,11 +3340,11 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ; //CCRT : clutter : -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=numberOfElements; - med_2_2::med_int *temp=new med_2_2::med_int[lgth]; + med_2_3::med_int *temp=new med_2_3::med_int[lgth]; for(int i2=0;i2<lgth;i2++) - temp[i2]=(med_2_2::med_int) (familyArray[i2]); + temp[i2]=(med_2_3::med_int) (familyArray[i2]); #endif SCRUTE(numberOfTypes); @@ -3024,34 +3353,34 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { SCRUTE(typeNumberOfElements); SCRUTE(typeCount[i+1]); SCRUTE(typeCount[i]); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), (temp+(typeCount[i]-1)), typeNumberOfElements, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i]); +// (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + (med_2_3::med_geometrie_element) types[i]); #else err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ), (familyArray+(typeCount[i]-1)), typeNumberOfElements, -// (med_2_2::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity - (med_2_2::med_entite_maillage) MED_CELL, - (med_2_2::med_geometrie_element) types[i]); +// (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity + (med_2_3::med_entite_maillage) MED_CELL, + (med_2_3::med_geometrie_element) types[i]); #endif - if ( err != MED_VALID) + if ( err != MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i]) - << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |" - << _ptrMesh->_name.c_str() << "|" )); + << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |" + << _ptrMesh->_name.c_str() << "|" )); } -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) delete [] temp; #endif delete[] familyArray ; - //if (true == ToDestroy) { - // int NumberOfFamilies = myFamilies->size(); - // for (int i=0; i<NumberOfFamilies; i++) - // delete myFamilies[i]; - //} +// if (true == ToDestroy) { +// int NumberOfFamilies = myFamilies->size(); +// for (int i=0; i<NumberOfFamilies; i++) +// delete (*myFamilies)[i]; +// } } } @@ -3061,49 +3390,53 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const { int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const { - + const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> families) const : "; BEGIN_OF(LOC); - med_2_2::med_err err; - + med_2_3::med_err err; + MESSAGE(LOC<<" families.size() :"<<families.size()); for (unsigned int i=0; i< families.size(); i++) { - int numberOfAttributes = families[i]->getNumberOfAttributes (); - string attributesDescriptions = ""; + int numberOfAttributes = families[i]->getNumberOfAttributes (); + string attributesDescriptions (numberOfAttributes*MED_TAILLE_DESC,'\0'); // Recompose the attributes descriptions arg for MED - for (int j=0; j < numberOfAttributes; j++) { - + for (int j=0; j < numberOfAttributes; j++) + { string attributeDescription = families[i]->getAttributeDescription(j+1); - + if ( attributeDescription.size() > MED_TAILLE_DESC ) - throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName() - << "| with identifier |" << families[i]->getIdentifier() << "| is |" - << attributeDescription.size() <<"| and is more than |" << MED_TAILLE_DESC << "|")) ; - - attributesDescriptions += attributeDescription; + throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" + << j+1 << "| of the family |" << families[i]->getName() + << "| with identifier |" << families[i]->getIdentifier() + << "| is |" << attributeDescription.size() + <<"| and is more than |" << MED_TAILLE_DESC << "|")); + + int length = min(MED_TAILLE_LNOM,(int)attributeDescription.size()); + attributesDescriptions.replace(j*MED_TAILLE_DESC,length, attributeDescription,0,length); } - + int numberOfGroups = families[i]->getNumberOfGroups(); - string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ; - // Recompose the groups names arg for MED - for (int j=0; j < numberOfGroups; j++) { + string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0'); + // Recompose the groups names arg for MED + for (int j=0; j < numberOfGroups; j++) + { string groupName = families[i]->getGroupName(j+1); - + if ( groupName.size() > MED_TAILLE_LNOM ) - throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" << j+1 << "| of the family |" << families[i]->getName() - << "| with identifier |" << families[i]->getIdentifier() << "| is |" - << groupName.size() <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ; - + throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" + << j+1 << "| of the family |" << families[i]->getName() + << "| with identifier |" << families[i]->getIdentifier() + << "| is |" << groupName.size() + <<"| and is more than |" << MED_TAILLE_LNOM << "|")); int length = min(MED_TAILLE_LNOM,(int)groupName.size()); groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length); - } // test if the family already exists (HDF trick waiting a MED evolution to be replaced) @@ -3115,7 +3448,7 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/ELEME/"+families[i]->getName()+"/"; SCRUTE("|"<<dataGroupFam<<"|"); - err = med_2_2::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ; + err = med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ; if ( err < MED_VALID ) { SCRUTE(err); if ( families[i]->getName().size() > MED_TAILLE_NOM ) @@ -3136,16 +3469,16 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str()); MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups); MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str()); -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) int lgth=families[i]->getNumberOfAttributes(); - med_2_2::med_int * AttributesIdentifier2 = new med_2_2::med_int[lgth] ; - med_2_2::med_int * AttributesValues2 = new med_2_2::med_int[lgth] ; - for(med_2_2::med_int i2=0;i2<lgth;i2++) + med_2_3::med_int * AttributesIdentifier2 = new med_2_3::med_int[lgth] ; + med_2_3::med_int * AttributesValues2 = new med_2_3::med_int[lgth] ; + for(med_2_3::med_int i2=0;i2<lgth;i2++) { - AttributesIdentifier2[i2]=(med_2_2::med_int)(families[i]->getAttributesIdentifiers()[i2]); - AttributesValues2[i2]=(med_2_2::med_int)(families[i]->getAttributesValues()[i2]); + AttributesIdentifier2[i2]=(med_2_3::med_int)(families[i]->getAttributesIdentifiers()[i2]); + AttributesValues2[i2]=(med_2_3::med_int)(families[i]->getAttributesValues()[i2]); } - err = med_2_2::MEDfamCr( _medIdt, + err = med_2_3::MEDfamCr( _medIdt, const_cast <char *> ( _meshName.c_str() ), const_cast <char *> ( families[i]->getName().c_str() ), families[i]->getIdentifier(), @@ -3158,31 +3491,31 @@ int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const delete [] AttributesIdentifier2; delete [] AttributesValues2; #else - err = med_2_2::MEDfamCr( _medIdt, + err = med_2_3::MEDfamCr( _medIdt, const_cast <char *> ( _meshName.c_str() ), const_cast <char *> ( families[i]->getName().c_str() ), families[i]->getIdentifier(), - (med_2_2::med_int*)families[i]->getAttributesIdentifiers(), - (med_2_2::med_int*)families[i]->getAttributesValues(), + (med_2_3::med_int*)families[i]->getAttributesIdentifiers(), + (med_2_3::med_int*)families[i]->getAttributesValues(), const_cast <char *> (attributesDescriptions.c_str()), numberOfAttributes, const_cast <char *> (groupsNames.c_str()), numberOfGroups); #endif SCRUTE(err); - if ( err != MED_VALID) + if (err != MED_VALID) throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName() - << "| with identifier |" << families[i]->getIdentifier() << "| groups names |" - << groupsNames <<"| and attributes descriptions |" << attributesDescriptions << "|")) ; + << "| with identifier |" << families[i]->getIdentifier() + << "| groups names |" << groupsNames + << "| and attributes descriptions |" << attributesDescriptions << "|")); } else - med_2_2::_MEDdatagroupFermer(_medIdt); - + med_2_3::_MEDdatagroupFermer(_medIdt); } END_OF(LOC); - + return MED_VALID; } @@ -3223,8 +3556,8 @@ MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const MED_MESH_RDWR_DRIVER22 & dr MED_MESH_RDWR_DRIVER22::~MED_MESH_RDWR_DRIVER22() { //MESSAGE("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed"); -} - +} + GENDRIVER * MED_MESH_RDWR_DRIVER22::copy(void) const { return new MED_MESH_RDWR_DRIVER22(*this); @@ -3238,4 +3571,3 @@ void MED_MESH_RDWR_DRIVER22::read (void) { MED_MESH_RDONLY_DRIVER22::read(); } - diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver22.hxx b/src/MEDMEM/MEDMEM_MedMeshDriver22.hxx index fbd86d1f0..14f6a2589 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver22.hxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver22.hxx @@ -42,12 +42,12 @@ class MED_MESH_DRIVER22 : public virtual MED_MESH_DRIVER { protected: - med_2_2::med_idt _medIdt ; + med_2_3::med_idt _medIdt ; public : // all MED cell type - static const med_2_2::med_geometrie_element all_cell_type[MED_NBR_GEOMETRIE_MAILLE]; + static const med_2_3::med_geometrie_element all_cell_type[MED_NBR_GEOMETRIE_MAILLE]; static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]; @@ -58,8 +58,8 @@ public : /*! Constructor. */ - MED_MESH_DRIVER22(const string & fileName, - MESH * ptrMesh, + MED_MESH_DRIVER22(const string & fileName, + MESH * ptrMesh, MED_EN::med_mode_acces accessMode) ; /*! Copy constructor. @@ -85,7 +85,7 @@ public : class MED_MESH_RDONLY_DRIVER22 : public virtual IMED_MESH_RDONLY_DRIVER, public virtual MED_MESH_DRIVER22 { - + public : /*! @@ -110,6 +110,17 @@ public : Read MESH in the specified file. */ void read ( void ); + /*! + * This method activate global faces computation from SCRATCH if a family on FACE exists in the MED file. + * This implies a complete renumbering of FACES. This is the default behaviour of this driver. + */ + void activateFacesComputation() { _computeFaces=true; } + /*! + * This method desactivate global face computation. + * That is to say that FACES described in file are supposed to + * be correct and complete. The consequence is that reading is much faster. Use with care ! + */ + void desactivateFacesComputation() { _computeFaces=false; } private: int getCOORDINATE(); @@ -122,6 +133,8 @@ private: GENDRIVER * copy ( void ) const ; +private: + bool _computeFaces; }; /*! @@ -143,7 +156,7 @@ public : /*! Constructor. */ - MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) ; + MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces access=MED_EN::MED_WRONLY) ; /*! Copy constructor. */ @@ -162,6 +175,7 @@ public : private: int writeCoordinates () const; int writeConnectivities (MED_EN::medEntityMesh entity) const; + void groupFamilyConverter(const vector<GROUP*>& groups,vector<FAMILY*>& families) const; int writeFamilyNumbers () const; int writeFamilies (vector<FAMILY*> & families) const; int writeGRID() const; diff --git a/src/MEDMEM/MEDMEM_MedVersion.cxx b/src/MEDMEM/MEDMEM_MedVersion.cxx index 3ad0a36a9..3cbc7031d 100644 --- a/src/MEDMEM/MEDMEM_MedVersion.cxx +++ b/src/MEDMEM/MEDMEM_MedVersion.cxx @@ -30,20 +30,20 @@ medFileVersion MEDMEM::getMedFileVersion(const string & fileName) medFileVersion version; med_2_1::med_idt fid21; - med_2_2::med_idt fid22; + med_2_3::med_idt fid22; med_2_1::med_err ret21; - med_2_2::med_err ret22; + med_2_3::med_err ret22; med_2_1::med_int major21; med_2_1::med_int minor21; med_2_1::med_int release21; - med_2_2::med_int major22; - med_2_2::med_int minor22; - med_2_2::med_int release22; + med_2_3::med_int major22; + med_2_3::med_int minor22; + med_2_3::med_int release22; - med_2_2::med_mode_acces access22 = med_2_2::MED_LECTURE; + med_2_3::med_mode_acces access22 = med_2_3::MED_LECTURE; med_2_1::med_mode_acces access21 = med_2_1::MED_LECT; /* @@ -74,16 +74,16 @@ medFileVersion MEDMEM::getMedFileVersion(const string & fileName) throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.1 file closing"); /* - Med Version 2.2 access to the file + Med Version 2.3 access to the file */ - fid22 = med_2_2::MEDouvrir((const_cast <char *> (fileName.c_str())), + fid22 = med_2_3::MEDouvrir((const_cast <char *> (fileName.c_str())), access22); if (fid22 < 0) throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 access"); - ret22 = med_2_2::MEDversionLire(fid22,&major22,&minor22,&release22); + ret22 = med_2_3::MEDversionLire(fid22,&major22,&minor22,&release22); if (ret22 < 0) throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 version numbers reading"); @@ -95,7 +95,7 @@ medFileVersion MEDMEM::getMedFileVersion(const string & fileName) release22 = 5; } - ret22 = med_2_2::MEDfermer(fid22); + ret22 = med_2_3::MEDfermer(fid22); if (ret22 < 0) throw MEDEXCEPTION("Problem in getMedFileVersion(const string &) Med file V2.2 file closing"); @@ -121,3 +121,76 @@ medFileVersion MEDMEM::getMedFileVersion(const string & fileName) return version; } + +//================================================================================ +/*! + * \brief return file mode access corresponding to MED_EN::med_mode_acces in given med version + * \param mode - either MED_LECT, MED_ECRI or MED_REMP + * \param medVersion - V21 or V22 or ?? + * \retval int - file mode access + * + * To be used in MEDouvrir() call + */ +//================================================================================ + +int MEDMEM::getMedAccessMode(MED_EN::med_mode_acces mode, + MED_EN::medFileVersion medVersion) + throw (MEDEXCEPTION) +{ + switch ( medVersion ) { + case V21: +/* + from MEDouvrir.c: + switch(mode_acces) + { + case MED_LECT : + if (access(nom,F_OK)) + return -1; + else + if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0) + return -1; + break; + + case MED_ECRI : + if (access(nom,F_OK)) + { + if ((fid = _MEDfichierCreer(nom)) < 0) + return -1; + } + else + if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0) + return -1; + break; + + case MED_REMP : + if ((fid = _MEDfichierCreer(nom)) < 0) + return -1; + break; +*/ + switch ( mode ) { + case MED_EN::MED_LECT: return med_2_1::MED_LECT; + case MED_EN::MED_ECRI: return med_2_1::MED_ECRI; + case MED_EN::MED_REMP: return med_2_1::MED_ECRI; + default: + throw MEDEXCEPTION("getMedAccessMode(): Wrong access mode"); + } + case V22: +/* + from med.h: + MED_LECTURE : Ouverture en lecture seule + MED_LECTURE_ECRITURE : Ouverture en lecture/ecriture, si un Ă©lĂ©ment existe il est Ă©crasĂ© + MED_LECTURE_AJOUT : Ouverture en lecture/ecriture, si un Ă©lĂ©ment existe une erreur est gĂ©nĂ©rĂ©e + MED_CREATION : CrĂ©er le fichier s'il n'existe pas, l'Ă©crase sinon +*/ + switch ( mode ) { + case MED_EN::MED_LECT: return med_2_3::MED_LECTURE; + case MED_EN::MED_ECRI: return med_2_3::MED_LECTURE_ECRITURE; + case MED_EN::MED_REMP: return med_2_3::MED_LECTURE_ECRITURE; + case MED_EN::MED_CREA: return med_2_3::MED_CREATION; + default: + throw MEDEXCEPTION("getMedAccessMode(): Wrong access mode"); + } + default:; + } + throw MEDEXCEPTION("getMedAccessMode(): Unknown med version"); +} diff --git a/src/MEDMEM/MEDMEM_MedVersion.hxx b/src/MEDMEM/MEDMEM_MedVersion.hxx index b6074f275..d08f3dbdd 100644 --- a/src/MEDMEM/MEDMEM_MedVersion.hxx +++ b/src/MEDMEM/MEDMEM_MedVersion.hxx @@ -20,13 +20,23 @@ #ifndef MED_VERSION_HXX #define MED_VERSION_HXX +#include "MEDMEM.hxx" + #include <string> #include "MEDMEM_Exception.hxx" #include "MEDMEM_define.hxx" namespace MEDMEM { - MED_EN::medFileVersion getMedFileVersion(const string & fileName) + MEDMEM_EXPORT MED_EN::medFileVersion getMedFileVersion(const string & fileName) + throw (MEDEXCEPTION); + + int getMedAccessMode(MED_EN::med_mode_acces mode, + MED_EN::medFileVersion medVersion) + throw (MEDEXCEPTION); + + int getMedAccessMode(MED_EN::med_mode_acces mode, + MED_EN::medFileVersion medVersion) throw (MEDEXCEPTION); } diff --git a/src/MEDMEM/MEDMEM_Mesh.cxx b/src/MEDMEM/MEDMEM_Mesh.cxx index 7b75e662d..76b82d3a8 100644 --- a/src/MEDMEM/MEDMEM_Mesh.cxx +++ b/src/MEDMEM/MEDMEM_Mesh.cxx @@ -163,59 +163,59 @@ MESH::MESH(MESH &m) _numberOfNodes = m._numberOfNodes; _familyNode = m._familyNode; - for (int i=0; i<m._familyNode.size(); i++) + for (int i=0; i<(int)m._familyNode.size(); i++) { _familyNode[i] = new FAMILY(* m._familyNode[i]); - _familyNode[i]->setMesh(this); + _familyNode[i]->setMeshDirectly(this); } _familyCell = m._familyCell; - for (int i=0; i<m._familyCell.size(); i++) + for (int i=0; i<(int)m._familyCell.size(); i++) { _familyCell[i] = new FAMILY(* m._familyCell[i]); - _familyCell[i]->setMesh(this); + _familyCell[i]->setMeshDirectly(this); } _familyFace = m._familyFace; - for (int i=0; i<m._familyFace.size(); i++) + for (int i=0; i<(int)m._familyFace.size(); i++) { _familyFace[i] = new FAMILY(* m._familyFace[i]); - _familyFace[i]->setMesh(this); + _familyFace[i]->setMeshDirectly(this); } _familyEdge = m._familyEdge; - for (int i=0; i<m._familyEdge.size(); i++) + for (int i=0; i<(int)m._familyEdge.size(); i++) { _familyEdge[i] = new FAMILY(* m._familyEdge[i]); - _familyEdge[i]->setMesh(this); + _familyEdge[i]->setMeshDirectly(this); } _groupNode = m._groupNode; - for (int i=0; i<m._groupNode.size(); i++) + for (int i=0; i<(int)m._groupNode.size(); i++) { _groupNode[i] = new GROUP(* m._groupNode[i]); - _groupNode[i]->setMesh(this); + _groupNode[i]->setMeshDirectly(this); } _groupCell = m._groupCell; - for (int i=0; i<m._groupCell.size(); i++) + for (int i=0; i<(int)m._groupCell.size(); i++) { _groupCell[i] = new GROUP(* m._groupCell[i]); - _groupCell[i]->setMesh(this); + _groupCell[i]->setMeshDirectly(this); } _groupFace = m._groupFace; - for (int i=0; i<m._groupFace.size(); i++) + for (int i=0; i<(int)m._groupFace.size(); i++) { _groupFace[i] = new GROUP(* m._groupFace[i]); - _groupFace[i]->setMesh(this); + _groupFace[i]->setMeshDirectly(this); } _groupEdge = m._groupEdge; - for (int i=0; i<m._groupEdge.size(); i++) + for (int i=0; i<(int)m._groupEdge.size(); i++) { _groupEdge[i] = new GROUP(* m._groupEdge[i]); - _groupEdge[i]->setMesh(this); + _groupEdge[i]->setMeshDirectly(this); } //_drivers = m._drivers; //Recopie des drivers? @@ -305,6 +305,14 @@ int MESH::getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, MED_EN::medG return getNumberOfElements(Entity,Type); } +bool MESH::existConnectivityWithPoly(MED_EN::medConnectivity ConnectivityType, + MED_EN::medEntityMesh Entity) const +{ + if (_connectivity==(CONNECTIVITY*)NULL) + throw MEDEXCEPTION("MESH::existConnectivity(medConnectivity,medEntityMesh) : no connectivity defined !"); + return _connectivity->existConnectivityWithPoly(ConnectivityType,Entity); +} + MESH & MESH::operator=(const MESH &m) { const char * LOC = "MESH & MESH::operator=(const MESH &m) : "; @@ -397,8 +405,17 @@ bool MESH::deepCompare(const MESH& other) const return ret; } +/*! + * \brief print my contents + */ ostream & ::MEDMEM::operator<<(ostream &os, const MESH &myMesh) { + myMesh.printMySelf(os); + return os; +} +void MESH::printMySelf(ostream &os) const +{ + const MESH &myMesh = *this; int spacedimension = myMesh.getSpaceDimension(); int meshdimension = myMesh.getMeshDimension(); int numberofnodes = myMesh.getNumberOfNodes(); @@ -406,33 +423,37 @@ ostream & ::MEDMEM::operator<<(ostream &os, const MESH &myMesh) os << "Space Dimension : " << spacedimension << endl << endl; os << "Mesh Dimension : " << meshdimension << endl << endl; - - const double * coordinates = myMesh.getCoordinates(MED_FULL_INTERLACE); - os << "SHOW NODES COORDINATES : " << endl; - - os << "Name :" << endl; - const string * coordinatesnames = myMesh.getCoordinatesNames(); - for(int i=0; i<spacedimension ; i++) + + if(myMesh.getCoordinateptr()) { + const double * coordinates = myMesh.getCoordinates(MED_FULL_INTERLACE); + + os << "SHOW NODES COORDINATES : " << endl; + os << "Name :" << endl; + const string * coordinatesnames = myMesh.getCoordinatesNames(); + for(int i=0; i<spacedimension ; i++) { os << " - " << coordinatesnames[i] << endl; } - os << "Unit :" << endl; - const string * coordinatesunits = myMesh.getCoordinatesUnits(); - for(int i=0; i<spacedimension ; i++) + os << "Unit :" << endl; + const string * coordinatesunits = myMesh.getCoordinatesUnits(); + for(int i=0; i<spacedimension ; i++) { os << " - " << coordinatesunits[i] << endl; } - for(int i=0; i<numberofnodes ; i++) + for(int i=0; i<numberofnodes ; i++) { os << "Nodes " << i+1 << " : "; for (int j=0; j<spacedimension ; j++) os << coordinates[i*spacedimension+j] << " "; os << endl; } - - os << endl << "SHOW CONNECTIVITY :" << endl; - os << *myMesh._connectivity << endl; - + } + + if(myMesh.getConnectivityptr()) { + os << endl << "SHOW CONNECTIVITY :" << endl; + os << *myMesh._connectivity << endl; + } + medEntityMesh entity; os << endl << "SHOW FAMILIES :" << endl << endl; for (int k=1; k<=4; k++) @@ -465,8 +486,6 @@ ostream & ::MEDMEM::operator<<(ostream &os, const MESH &myMesh) os << * myMesh.getGroup(entity,i) << endl; } } - - return os; } /*! @@ -581,7 +600,7 @@ void MESH::fillSupportOnNodeFromElementList(const list<int>& listOfElt, SUPPORT { MED_EN::medEntityMesh entity=supportToFill->getEntity(); supportToFill->setAll(false); - supportToFill->setMesh((MESH *)this); + supportToFill->setMeshDirectly((MESH *)this); int i; set<int> nodes; @@ -730,7 +749,7 @@ FIELD<double, FullInterlace>* MESH::getVolume(const SUPPORT *Support) const thro int N5 = global_connectivity[pyra_index+4]-1; xvolume=CalculateVolumeForPyra(coord+dim_space*N1,coord+dim_space*N2,coord+dim_space*N3,coord+dim_space*N4,coord+dim_space*N5); volume->setIJ(index,1,xvolume) ; - index = index++; + index++; } break; } @@ -1326,7 +1345,6 @@ FIELD<double, FullInterlace>* MESH::getBarycenter(const SUPPORT * Support) const const medGeometryElement* types; int nb_entity_type; const int* global_connectivity; - const int * global_connectivityIndex; nb_type = Support->getNumberOfTypes(); length_values = Support->getNumberOfElements(MED_ALL_ELEMENTS); @@ -1353,7 +1371,6 @@ FIELD<double, FullInterlace>* MESH::getBarycenter(const SUPPORT * Support) const { medGeometryElement type = types[i] ; nb_entity_type = Support->getNumberOfElements(type); - global_connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity); if(type != MED_EN::MED_POLYGON && type != MED_EN::MED_POLYHEDRA ) { if (onAll) @@ -1368,6 +1385,7 @@ FIELD<double, FullInterlace>* MESH::getBarycenter(const SUPPORT * Support) const for (int k_type = 0; k_type<nb_entity_type; k_type++) { for (int j_ent = 0; j_ent<(type%100); j_ent++) { + const int *global_connectivityIndex = getConnectivityIndex(MED_NODAL,support_entity); global_connectivity_tmp[k_type*(type%100)+j_ent] = connectivity[global_connectivityIndex[supp_number[k_type]-1]+j_ent-1]; } } @@ -1646,6 +1664,28 @@ void MESH::read(int index) ); END_OF(LOC); } + +/*! Write all the content of the MESH using driver referenced by the integer handler index.*/ +void MESH::write(int index/*=0*/, const string & driverName/* = ""*/) +{ + const char * LOC = "MESH::write(int index=0, const string & driverName = \"\") : "; + BEGIN_OF(LOC); + + if ( _drivers[index] ) { + _drivers[index]->open(); + if (driverName != "") _drivers[index]->setMeshName(driverName); + _drivers[index]->write(); + _drivers[index]->close(); + } + else + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "The index given is invalid, index must be between 0 and |" + << _drivers.size() + ) + ); + END_OF(LOC); +} + //======================================================================= //function : getSkin //purpose : @@ -2059,6 +2099,52 @@ struct _cell MED_EN::medGeometryElement geometricType; }; +/*! +Create groups from families. + +It is used to create groups that have only one family +for meshes that come from codes that use families instead +of groups to define a subregion. +*/ +void MESH::createGroups() +{ + for (medEntityMesh entity=MED_CELL; entity!=MED_ALL_ENTITIES; ++entity) + { + // make myFamilies points to the member corresponding to entity + vector<FAMILY*>* myFamilies; + vector<GROUP*>* myGroups; + switch ( entity ) + { + case MED_CELL : + myFamilies = & _familyCell; + myGroups = & _groupCell; + break; + case MED_FACE : + myFamilies = & _familyFace; + myGroups = & _groupFace; + break; + case MED_EDGE : + myFamilies = & _familyEdge; + myGroups = & _groupEdge; + break; + case MED_NODE : + myFamilies = & _familyNode; + myGroups = & _groupNode; + break; + } + + + for (int i=0; i< myFamilies->size(); i++) + { + list <FAMILY*> fam_list; + fam_list.push_back((*myFamilies)[i]); + //creates a group with the family name and only one family + GROUP* group=new GROUP((*myFamilies)[i]->getName(),fam_list); + (*myGroups).push_back(group); + } + } +} + // Create families from groups void MESH::createFamilies() { @@ -2200,7 +2286,7 @@ void MESH::createFamilies() FAMILY* newFam = new FAMILY(); newFam->setTotalNumberOfElements(fam->second.size()); newFam->setName(famName); - newFam->setMesh(this); + newFam->setMeshDirectly(this); newFam->setNumberOfGeometricType(tab_types_geometriques.size()); newFam->setGeometricType(&tab_types_geometriques[0]); // we know the tab is not empy newFam->setNumberOfElements(&tab_nombres_elements[0]); @@ -2259,11 +2345,11 @@ void MESH::createFamilies() } // delete old families - for (int i=0;i<myOldFamilies.size();i++) + for (unsigned int i=0;i<myOldFamilies.size();i++) delete myOldFamilies[i] ; // update references in groups - for (int i=0;i<myGroups.size();i++) + for (unsigned int i=0;i<myGroups.size();i++) { myGroups[i]->setNumberOfFamilies(whichFamilyInGroup[i].size()); myGroups[i]->setFamilies(whichFamilyInGroup[i]); diff --git a/src/MEDMEM/MEDMEM_Mesh.hxx b/src/MEDMEM/MEDMEM_Mesh.hxx index 16ff9f32a..69bbb70be 100644 --- a/src/MEDMEM/MEDMEM_Mesh.hxx +++ b/src/MEDMEM/MEDMEM_Mesh.hxx @@ -20,6 +20,8 @@ #ifndef MESH_HXX #define MESH_HXX +#include <MEDMEM.hxx> + #include <string> #include <vector> #include <list> @@ -54,8 +56,11 @@ class CELLMODEL; class FAMILY; class GROUP; class SUPPORT; +class MESH; + +ostream & operator<<(ostream &os, const MESH &my); -class MESH : public RCBASE +class MEDMEM_EXPORT MESH : public RCBASE { //-----------------------// // Attributes @@ -138,6 +143,8 @@ public : friend class VTK_MESH_DRIVER; + friend class ENSIGHT_MESH_RDONLY_DRIVER; + void init(); MESH(); MESH(MESH &m); @@ -147,7 +154,8 @@ public : MESH( driverTypes driverType, const string & fileName="", const string & meshName="") throw (MEDEXCEPTION); virtual ~MESH(); - friend ostream & operator<<(ostream &os, const MESH &my); + friend MEDMEM_EXPORT ostream & operator<<(ostream &os, const MESH &my); + virtual void printMySelf(ostream &os) const; int addDriver(driverTypes driverType, const string & fileName ="Default File Name.med", @@ -158,11 +166,13 @@ public : virtual void read(int index=0); inline void read(const GENDRIVER & genDriver); - inline void write(int index=0, const string & driverName = ""); + //inline void write(int index=0, const string & driverName = ""); + virtual void write(int index=0, const string & driverName = ""); inline void write(const GENDRIVER & genDriver); inline void setName(string name); inline void setDescription(string description); + inline void setMeshDimension(int dim); inline string getName() const; inline string getDescription() const; inline int getSpaceDimension() const; @@ -191,6 +201,8 @@ public : MED_EN::medGeometryElement Type) const; virtual inline bool existConnectivity(MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + virtual bool existConnectivityWithPoly(MED_EN::medConnectivity ConnectivityType, + MED_EN::medEntityMesh Entity) const; inline bool existPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; inline bool existPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType, @@ -295,11 +307,13 @@ public : * (There is no way to know which family has change.) */ void createFamilies(); + void createGroups(); SUPPORT *buildSupportOnNodeFromElementList(const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); void fillSupportOnNodeFromElementList(const list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION); SUPPORT *buildSupportOnElementsFromElementList(const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); int getElementContainingPoint(const double *coord); - vector< vector<double> > MESH::getBoundingBox() const; +// vector< vector<double> > MESH::getBoundingBox() const; + vector< vector<double> > getBoundingBox() const; template<class T> static FIELD<T> * mergeFields(const vector< FIELD<T> * > & others, bool meshCompare=false); /*! @@ -319,45 +333,6 @@ inline const CONNECTIVITY* MESH::getConnectivityptr() const return _connectivity; } -// inline void MESH::read(int index/*=0*/) -// { -// const char * LOC = "MESH::read(int index=0) : "; -// BEGIN_OF(LOC); - -// if (_drivers[index]) { -// _drivers[index]->open(); -// _drivers[index]->read(); -// _drivers[index]->close(); -// } -// else -// throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) -// << "The index given is invalid, index must be between 0 and |" -// << _drivers.size() -// ) -// ); -// END_OF(LOC); -// } - -/*! Write all the content of the MESH using driver referenced by the integer handler index.*/ -inline void MESH::write(int index/*=0*/, const string & driverName/* = ""*/) -{ - const char * LOC = "MESH::write(int index=0, const string & driverName = \"\") : "; - BEGIN_OF(LOC); - - if ( _drivers[index] ) { - _drivers[index]->open(); - if (driverName != "") _drivers[index]->setMeshName(driverName); - _drivers[index]->write(); - _drivers[index]->close(); - } - else - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "The index given is invalid, index must be between 0 and |" - << _drivers.size() - ) - ); - END_OF(LOC); -} // This method is MED specific : don't use it // must be private. @@ -409,6 +384,11 @@ inline string MESH::getName() const return _name; } +inline void MESH::setMeshDimension(int dim) +{ + _meshDimension=dim; +} + /*! Set the MESH description */ inline void MESH::setDescription(string description) { @@ -727,7 +707,7 @@ inline const int * MESH::getConnectivityIndex(MED_EN::medConnectivity Connectivi inline int MESH::getPolygonsConnectivityLength(MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const { - return getPolygonsConnectivityIndex (ConnectivityType,Entity)[ getNumberOfPolygons() ] - 1; + return getPolygonsConnectivityIndex (ConnectivityType,Entity)[ getNumberOfPolygons(Entity) ] - 1; } /*! Return the required connectivity of polygons for the given entity. @@ -979,7 +959,7 @@ const MEDMEM::FAMILY* MESH::getFamily(MED_EN::medEntityMesh entity, int i) const default : throw MEDEXCEPTION("MESH::getFamilies : Unknown entity"); } - if (i>Family.size()) + if (i>(int)Family.size()) throw MEDEXCEPTION("MESH::getFamily(entity,i) : argument i must be <= _numberOfFamilies"); return Family[i-1]; } @@ -1010,7 +990,7 @@ const GROUP* MESH::getGroup(MED_EN::medEntityMesh entity, int i) const default : throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Unknown entity")); } - if (i>Group.size()) + if (i>(int)Group.size()) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"argument i="<<i<<" must be <= _numberOfGroups="<<Group.size())); return Group[i-1]; } diff --git a/src/MEDMEM/MEDMEM_Meshing.cxx b/src/MEDMEM/MEDMEM_Meshing.cxx index ab6041b94..6ff636659 100644 --- a/src/MEDMEM/MEDMEM_Meshing.cxx +++ b/src/MEDMEM/MEDMEM_Meshing.cxx @@ -59,13 +59,16 @@ void MESHING::setSpaceDimension(const int SpaceDimension) void MESHING::setMeshDimension(const int MeshDimension) { _meshDimension = MeshDimension ; - _connectivity->setEntityDimension(MeshDimension); + if (_connectivity) + _connectivity->setEntityDimension(MeshDimension); } /*! Set the number of nodes used in the MESH */ void MESHING::setNumberOfNodes(const int NumberOfNodes) { _numberOfNodes = NumberOfNodes ; + if (_connectivity) + _connectivity->setNumberOfNodes(NumberOfNodes); } /*! diff --git a/src/MEDMEM/MEDMEM_Meshing.hxx b/src/MEDMEM/MEDMEM_Meshing.hxx index 0f0fbd4bd..76fc175d8 100644 --- a/src/MEDMEM/MEDMEM_Meshing.hxx +++ b/src/MEDMEM/MEDMEM_Meshing.hxx @@ -25,6 +25,8 @@ #ifndef MESHING_HXX #define MESHING_HXX +#include "MEDMEM.hxx" + #include "MEDMEM_Mesh.hxx" /*! @@ -32,7 +34,7 @@ */ namespace MEDMEM { -class MESHING: public MESH +class MEDMEM_EXPORT MESHING: public MESH { public : MESHING(); diff --git a/src/MEDMEM/MEDMEM_ModulusArray.hxx b/src/MEDMEM/MEDMEM_ModulusArray.hxx index 0a6593313..f6dd5587f 100644 --- a/src/MEDMEM/MEDMEM_ModulusArray.hxx +++ b/src/MEDMEM/MEDMEM_ModulusArray.hxx @@ -20,7 +20,11 @@ #ifndef __MEDMODULUSARRAY_H__ #define __MEDMODULUSARRAY_H__ +#include "MEDMEM.hxx" + #include "MEDMEM_Utilities.hxx" +#include "MEDMEM_define.hxx" + /* This class is use to set cyclic (modulus length) array. @@ -31,23 +35,32 @@ */ namespace MEDMEM { -class MEDMODULUSARRAY { +class MEDMEM_EXPORT MEDMODULUSARRAY { private: + // nb vertex nodes; only vertex nodes are in cycle int _length ; + // total nb nodes; not vertex nodes exists in 2-nd order elements, + // only presence of not vertex nodes is checked by compare() + int _length2; const int * _array ; + bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const; + public: MEDMODULUSARRAY(int length, const int * array) ; + MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array); ~MEDMODULUSARRAY() ; - - const int & operator[](const int &i) const ; + + const int operator[](const int &i) const ; int compare(const MEDMODULUSARRAY &modulusArray) const; + const int *getArray(int& length) const { length=_length; return _array; } }; + MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) : - _length(length), _array(array) + _length(length), _array(array), _length2(0) { // SCRUTE(_length); // for (int i=0;i<_length;i++){ @@ -55,6 +68,11 @@ MEDMODULUSARRAY::MEDMODULUSARRAY(int length, const int * array) : // } }; + MEDMODULUSARRAY::MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array): + _length(vertexLength), _length2( totalLength ), _array(array) +{ +} + MEDMODULUSARRAY::~MEDMODULUSARRAY() { // do nothing because nothing is allocated ! @@ -62,11 +80,13 @@ MEDMODULUSARRAY::~MEDMODULUSARRAY() }; -const int & MEDMODULUSARRAY::operator[](const int &i) const +const int MEDMODULUSARRAY::operator[](const int &i) const { int position = i%_length ; - if (position<0) + //int position = i%_length2 ; + if (position < 0) position+=_length ; + //position += _length2 ; return _array[position] ; }; @@ -74,7 +94,8 @@ int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const { int ret = 0 ; - if (modulusArray._length != _length) + if (modulusArray._length != _length || + modulusArray._length2 != _length2 ) return ret ; if (_length==1) @@ -83,13 +104,17 @@ int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const else return 0; - if (_length==2) + if (_length==2) { if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1])) - return 1; + ret = 1; else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0])) - return -1; + ret = -1; else return 0; + if ( !compareNotVertexNodes( modulusArray ) ) + ret = 0; + return ret; + } //search if there is one start point in common in two array for(int i=0;i<_length;i++) @@ -111,13 +136,34 @@ int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const } } if (ret!=0) {// we have found it ! + if ( !compareNotVertexNodes( modulusArray ) ) + ret = 0; break ; } // else we continue if there is another start point i } return ret ; } + +/*! + * \brief Check presence of the same not vertex nodes + * \retval bool - comparison result + */ +bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const +{ + if ( _length2 > _length ) { + for ( int i = _length; i < _length2; ++i ) { + bool found = false; + for ( int j = _length; ( j < _length2 && !found ); ++j ) + found = ( _array[ i ] == modulusArray._array[ j ] ); + if ( !found ) + return false; + } + } + return true; +} + } -# endif /* # ifndef __MEDMODULUSARRAY_H__ */ +# endif /* # ifndef __MEDMODULUSARRAY_H__ */ diff --git a/src/MEDMEM/MEDMEM_PointerOf.hxx b/src/MEDMEM/MEDMEM_PointerOf.hxx index 01a82c842..6834c0c5a 100644 --- a/src/MEDMEM/MEDMEM_PointerOf.hxx +++ b/src/MEDMEM/MEDMEM_PointerOf.hxx @@ -97,7 +97,7 @@ template <typename T> PointerOf<T>::PointerOf( const int &size, const PointerOf< Memory will be desallocated when erasing this PointerOf*/ template <typename T> PointerOf<T>::PointerOf( const int &size ) { - if (size <= 0) + if (size < 0) { _pointer=(T*)NULL; _done=false; @@ -121,7 +121,7 @@ template <typename T> PointerOf<T>::PointerOf( const T* pointer ) : _pointer( (T Memory will be desallocated when erasing this PointerOf*/ template <typename T> PointerOf<T>::PointerOf( const int &size, const T* pointer) { - if (size <= 0) + if (size < 0) throw MEDEXCEPTION("PointerOf( const int,const T*) : array size <= 0"); _pointer = new T[ size ] ; @@ -180,7 +180,6 @@ template <typename T> PointerOf<T>::operator const T*() const return _pointer ; } - /*! If necessary, released memory holded by PointerOf\n. Else allocates memory and sets desallocation boolean to true.\n Can be used in order to "nullify" an existing PointerOf\n @@ -238,7 +237,7 @@ template <typename T> void PointerOf<T>::set( const int &size, const T *pointer) delete [] _pointer ; _pointer = NULL ; } - if (size <= 0) + if (size < 0) throw MEDEXCEPTION("PointerOf( const int,const T*) : array size <= 0"); _pointer = new T[ size ] ; diff --git a/src/MEDMEM/MEDMEM_PolyhedronArray.hxx b/src/MEDMEM/MEDMEM_PolyhedronArray.hxx index 691c2e7c5..46275ae46 100644 --- a/src/MEDMEM/MEDMEM_PolyhedronArray.hxx +++ b/src/MEDMEM/MEDMEM_PolyhedronArray.hxx @@ -20,12 +20,14 @@ # ifndef __POLYHEDRONARRAY_H__ # define __POLYHEDRONARRAY_H__ +#include "MEDMEM.hxx" + #include "MEDMEM_Exception.hxx" #include "MEDMEM_PointerOf.hxx" #include "MEDMEM_define.hxx" namespace MEDMEM { -class POLYHEDRONARRAY +class MEDMEM_EXPORT POLYHEDRONARRAY { private : MED_EN::med_int _numberOfPolyhedron; diff --git a/src/MEDMEM/MEDMEM_PorflowMeshDriver.cxx b/src/MEDMEM/MEDMEM_PorflowMeshDriver.cxx index c96cb7f6b..539fe988b 100644 --- a/src/MEDMEM/MEDMEM_PorflowMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_PorflowMeshDriver.cxx @@ -39,12 +39,12 @@ using namespace MED_EN; using namespace MEDMEM; // geometric types conversion from PORFLOW -> MED -const size_t PORFLOW_MESH_DRIVER::nb_geometrie_porflow; +//const size_t PORFLOW_MESH_DRIVER::nb_geometrie_porflow; const medGeometryElement PORFLOW_MESH_DRIVER::geomPORFLOWtoMED[nb_geometrie_porflow] = { /* 1 */ MED_TRIA3 ,/* 2 */ MED_QUAD4 ,/* 3 */ MED_TETRA4 ,/* 4 */ MED_PYRA5 , /* 5 */ MED_PENTA6 ,/* 6 */ MED_HEXA8 }; // indirection table from PORFLOW order to MED one for nodes numerotation in all PORFLOW geometries -const size_t PORFLOW_MESH_DRIVER::nb_nodes_max; +//const size_t PORFLOW_MESH_DRIVER::nb_nodes_max; // conversion from porflow connectivity to MED connectivity const int PORFLOW_MESH_DRIVER::numPORFLOWtoMED[nb_geometrie_porflow] [nb_nodes_max] = { @@ -56,8 +56,8 @@ const int PORFLOW_MESH_DRIVER::numPORFLOWtoMED[nb_geometrie_porflow] [nb_nodes_m /* HEXA8 */ { /*1*/ 1, /*2*/ 4, /*3*/ 3, /*4*/ 2, /*5*/ 5, /*6*/ 8, /*7*/ 7, /*8*/ 6 } }; // Porflox nodal connectivity of faces - documented in Porflow user's manual -const size_t PORFLOW_MESH_DRIVER::nb_faces_max; -const size_t PORFLOW_MESH_DRIVER::nb_nodes2_max; +//const size_t PORFLOW_MESH_DRIVER::nb_faces_max; +//const size_t PORFLOW_MESH_DRIVER::nb_nodes2_max; const int PORFLOW_MESH_DRIVER::connectivityPORFLOW[nb_geometrie_porflow][nb_faces_max][nb_nodes2_max]={ //{/* TRI3 */ {3,1,0,0}, {1,2,0,0}, {2,3,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} }, //{/* QUA4 */ {1,4,0,0}, {2,3,0,0}, {1,2,0,0}, {3,4,0,0}, {0,0,0,0}, {0,0,0,0} }, diff --git a/src/MEDMEM/MEDMEM_PorflowMeshDriver.hxx b/src/MEDMEM/MEDMEM_PorflowMeshDriver.hxx index e0fcbc3d9..589eb0afe 100644 --- a/src/MEDMEM/MEDMEM_PorflowMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_PorflowMeshDriver.hxx @@ -20,6 +20,8 @@ #ifndef PORFLOW_MESH_DRIVER_HXX #define PORFLOW_MESH_DRIVER_HXX +#include "MEDMEM.hxx" + #include <string> #include <fstream> @@ -48,9 +50,9 @@ class MESH; class FAMILY; class GROUP; class CONNECTIVITY; -class _intermediateMED; -class _maille; -class PORFLOW_MESH_DRIVER : public GENDRIVER +struct _intermediateMED; +struct _maille; +class MEDMEM_EXPORT PORFLOW_MESH_DRIVER : public GENDRIVER { protected: @@ -59,13 +61,23 @@ protected: string _meshName; ifstream _porflow; + // This enumeration is used to substitude static const + // memers data causing link errors on VC7 compiler. + enum + { + nb_geometrie_porflow = 6, + nb_nodes_max = 8, // maximal number of nodes for a porflow geometrie + nb_nodes2_max = 4, // maximal number of nodes for a 2D porflow geometrie + nb_faces_max = 6 // maximal number of faces for a porflow geometrie + }; + // tableau de correspondance des types gĂƒÂ©omĂƒÂ©triques de PORFLOW -> MED - static const size_t nb_geometrie_porflow = 6; + //static const size_t nb_geometrie_porflow = 6; static const MED_EN::medGeometryElement geomPORFLOWtoMED[nb_geometrie_porflow]; // indirection table from PORFLOW order to MED one for nodes numerotation in all PORFLOW geometries - static const size_t nb_nodes_max = 8; // maximal number of nodes for a porflow geometrie - static const size_t nb_nodes2_max = 4; // maximal number of nodes for a 2D porflow geometrie - static const size_t nb_faces_max = 6; // maximal number of faces for a porflow geometrie + //static const size_t nb_nodes_max = 8; // maximal number of nodes for a porflow geometrie + //static const size_t nb_nodes2_max = 4; // maximal number of nodes for a 2D porflow geometrie + //static const size_t nb_faces_max = 6; // maximal number of faces for a porflow geometrie static const int numPORFLOWtoMED[nb_geometrie_porflow] [nb_nodes_max]; static const int connectivityPORFLOW[nb_geometrie_porflow][nb_faces_max][nb_nodes2_max]; inline static int geomMEDtoPorflow(MED_EN::medGeometryElement medGeo); @@ -116,7 +128,7 @@ private: }; -class PORFLOW_MESH_RDONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER +class MEDMEM_EXPORT PORFLOW_MESH_RDONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER { public : @@ -165,7 +177,7 @@ private: */ -class PORFLOW_MESH_WRONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER { +class MEDMEM_EXPORT PORFLOW_MESH_WRONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER { public : @@ -210,7 +222,7 @@ private: */ -class PORFLOW_MESH_RDWR_DRIVER : public PORFLOW_MESH_RDONLY_DRIVER, public PORFLOW_MESH_WRONLY_DRIVER { +class MEDMEM_EXPORT PORFLOW_MESH_RDWR_DRIVER : public PORFLOW_MESH_RDONLY_DRIVER, public PORFLOW_MESH_WRONLY_DRIVER { public : diff --git a/src/MEDMEM/MEDMEM_RCBase.hxx b/src/MEDMEM/MEDMEM_RCBase.hxx index 6df6c023b..25be7c54e 100644 --- a/src/MEDMEM/MEDMEM_RCBase.hxx +++ b/src/MEDMEM/MEDMEM_RCBase.hxx @@ -20,9 +20,11 @@ #ifndef __MEDMEM_RCBASE_HXX__ #define __MEDMEM_RCBASE_HXX__ +#include "MEDMEM.hxx" + namespace MEDMEM { - class RCBASE { + class MEDMEM_EXPORT RCBASE { public: virtual void addReference() const = 0; virtual void removeReference() const = 0; diff --git a/src/MEDMEM/MEDMEM_STRING.hxx b/src/MEDMEM/MEDMEM_STRING.hxx index c11eaf1ff..f7fac0072 100644 --- a/src/MEDMEM/MEDMEM_STRING.hxx +++ b/src/MEDMEM/MEDMEM_STRING.hxx @@ -20,6 +20,8 @@ # ifndef MEDMEM_STRING_HXX # define MEDMEM_STRING_HXX +#include "MEDMEM.hxx" + using namespace std; # include <string> @@ -34,7 +36,7 @@ using namespace std; throw SALOME_EXCEPTION (LOCALIZED(msgErr)) ; */ namespace MEDMEM { - class STRING : public string + class MEDMEM_EXPORT STRING : public string { private : diff --git a/src/MEDMEM/MEDMEM_SetInterlacingType.hxx b/src/MEDMEM/MEDMEM_SetInterlacingType.hxx index 677cd0a22..3d6e15a20 100644 --- a/src/MEDMEM/MEDMEM_SetInterlacingType.hxx +++ b/src/MEDMEM/MEDMEM_SetInterlacingType.hxx @@ -30,6 +30,8 @@ namespace { static const MED_EN::medModeSwitch _interlacingType = MED_EN::MED_FULL_INTERLACE; }; template < > struct SET_INTERLACING_TYPE<NoInterlace> { static const MED_EN::medModeSwitch _interlacingType = MED_EN::MED_NO_INTERLACE; }; + template < > struct SET_INTERLACING_TYPE<NoInterlaceByType> { + static const MED_EN::medModeSwitch _interlacingType = MED_EN::MED_NO_INTERLACE_BY_TYPE; }; } #endif diff --git a/src/MEDMEM/MEDMEM_SkyLineArray.hxx b/src/MEDMEM/MEDMEM_SkyLineArray.hxx index 50434a8b1..4d9be82f9 100644 --- a/src/MEDMEM/MEDMEM_SkyLineArray.hxx +++ b/src/MEDMEM/MEDMEM_SkyLineArray.hxx @@ -20,13 +20,18 @@ # ifndef __MEDSKYLINEARRAY_H__ # define __MEDSKYLINEARRAY_H__ +#include "MEDMEM.hxx" + #include "MEDMEM_Exception.hxx" #include "MEDMEM_PointerOf.hxx" #include "MEDMEM_define.hxx" namespace MEDMEM { -class MEDSKYLINEARRAY + class MEDSKYLINEARRAY; + ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky); + +class MEDMEM_EXPORT MEDSKYLINEARRAY { private : int _count ; diff --git a/src/MEDMEM/MEDMEM_Support.cxx b/src/MEDMEM/MEDMEM_Support.cxx index f6ab76c90..d74b7293d 100644 --- a/src/MEDMEM/MEDMEM_Support.cxx +++ b/src/MEDMEM/MEDMEM_Support.cxx @@ -97,6 +97,8 @@ SUPPORT::SUPPORT(const SUPPORT & m) else _number = (MEDSKYLINEARRAY *) NULL; + _profilNames=m._profilNames; + END_OF(LOC) ; }; /*! @@ -130,6 +132,7 @@ SUPPORT & SUPPORT::operator=(const SUPPORT & m) _number = (MEDSKYLINEARRAY *) NULL; } else _number = (MEDSKYLINEARRAY *) NULL; + _profilNames=m._profilNames; END_OF(LOC) ; return *this; @@ -202,7 +205,7 @@ void SUPPORT::update() { _numberOfGeometricType=1 ; _geometricType.set(1); - _geometricType[0]=MED_NONE; + _geometricType[0]=MED_POINT1; _numberOfElements.set(1); _numberOfElements[0]=_mesh->getNumberOfNodes(); // VĂ©rifier le pointeur ! _totalNumberOfElements=_numberOfElements[0]; @@ -242,9 +245,6 @@ int SUPPORT::getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTI if (_isOnAllElts) return number; int nbOfEltsThis = getNumberOfElements(MED_ALL_ELEMENTS); - int nbOfEltsThisVerif = _mesh->getNumberOfElements(_entity,MED_ALL_ELEMENTS); - - if (nbOfEltsThis == nbOfEltsThisVerif) return number; const int *eltsThis = _number->getValue(); @@ -370,6 +370,17 @@ void SUPPORT::setpartial(string Description, int NumberOfGeometricType, delete[] index ; + // PAL16854(Partial support on nodes): + // giving a default value to profile names + vector<string> prof_names( NumberOfGeometricType); + for (int itype=0; itype < NumberOfGeometricType; itype++) + { + ostringstream typestr; + typestr<<_name<<"_type"<<itype; + prof_names[itype]=typestr.str(); + } + setProfilNames(prof_names); + END_OF(LOC); }; @@ -417,6 +428,20 @@ void SUPPORT::setpartial(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDE END_OF(LOC); }; +void SUPPORT::setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy) throw (MEDEXCEPTION) +//------------------- +{ + const char * LOC = "SUPPORT::setpartial_fromfile(MEDSKYLINEARRAY * number) : " ; + BEGIN_OF(LOC) ; + + if ( shallowCopy ) + _number_fromfile = number; + else + _number_fromfile = new MEDSKYLINEARRAY(*number); + + END_OF(LOC); +}; + void SUPPORT::setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION){ const char * LOC = "SUPPORT::setProfilNames(vector<string> profilNames) : " ; diff --git a/src/MEDMEM/MEDMEM_Support.hxx b/src/MEDMEM/MEDMEM_Support.hxx index 1d9470ad9..5e092b26b 100644 --- a/src/MEDMEM/MEDMEM_Support.hxx +++ b/src/MEDMEM/MEDMEM_Support.hxx @@ -25,6 +25,8 @@ #ifndef SUPPORT_HXX #define SUPPORT_HXX +#include <MEDMEM.hxx> + #include <list> #include <vector> #include <string> @@ -50,7 +52,7 @@ namespace MEDMEM { class MESH; -class SUPPORT : public RCBASE +class MEDMEM_EXPORT SUPPORT : public RCBASE { protected: /*! @@ -138,6 +140,15 @@ protected: */ mutable MEDSKYLINEARRAY * _number; + /*! + \if developper + Array of size _index[_numberOfType]-1 wich contain number of + entities of each geometric type. We use file numbering.\n + Defined only if _isOnAllElts is false. + \endif + */ + mutable MEDSKYLINEARRAY * _number_fromfile; + /*! \if developper Array of size <_numberOfGeometricType> wich contain the profil name of @@ -157,7 +168,7 @@ public: SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL); SUPPORT(const SUPPORT & m); virtual ~SUPPORT(); - friend ostream & operator<<(ostream &os,const SUPPORT &my); + friend MEDMEM_EXPORT ostream & operator<<(ostream &os,const SUPPORT &my); SUPPORT& operator=(const SUPPORT &support); bool operator == (const SUPPORT &support) const; @@ -168,6 +179,7 @@ public: inline void setName(string Name); inline void setDescription(string Description); void setMesh(MESH *Mesh) const; + void setMeshDirectly(MESH *Mesh) const { _mesh=Mesh; } inline void setMeshName(const string & meshName); inline void setAll(bool All); inline void setEntity(MED_EN::medEntityMesh Entity); @@ -190,7 +202,9 @@ public: inline int getNumberOfElements(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); inline const int * getNumberOfElements() const throw (MEDEXCEPTION); virtual inline MEDSKYLINEARRAY * getnumber() const throw (MEDEXCEPTION); + virtual inline MEDSKYLINEARRAY * getnumberFromFile() const throw (MEDEXCEPTION); virtual inline const int * getNumber(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + virtual inline const int * getNumberFromFile(MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); virtual inline const int * getNumberIndex() const throw (MEDEXCEPTION); virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION); @@ -204,6 +218,9 @@ public: void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION); + + void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION); + // Si les noms de profils ne sont pas positionnĂ©s, les profils ne seront // pas Ă©crits par MEDFICHIER. void setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION); @@ -273,6 +290,16 @@ inline MEDSKYLINEARRAY * SUPPORT::getnumber() const return _number ; } +//--------------------------------------------------------------------- +inline MEDSKYLINEARRAY * SUPPORT::getnumberFromFile() const + throw (MEDEXCEPTION) +//--------------------------------------------------------------------- +{ + if (_number_fromfile==NULL) + throw MEDEXCEPTION("Support::getnumberFromFile : Not defined !") ; + return _number_fromfile ; +} + /*! If isOnAllElements is false, returns an array which contains all number of given medGeometryElement. @@ -300,6 +327,22 @@ inline const int * SUPPORT::getNumber(MED_EN::medGeometryElement GeometricType) throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ; } +//--------------------------------------------------------------------- +inline const int * SUPPORT::getNumberFromFile(MED_EN::medGeometryElement GeometricType) const + throw (MEDEXCEPTION) +//--------------------------------------------------------------------- +{ + const char * LOC = "Support::getNumberFromFile : " ; +// if (_isOnAllElts) +// throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Not defined, support is on all entity !")) ; + if (GeometricType==MED_EN::MED_ALL_ELEMENTS) + return _number_fromfile->getValue() ; + for (int i=0;i<_numberOfGeometricType;i++) + if (_geometricType[i]==GeometricType) + return _number_fromfile->getI(i+1) ; + throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"GeometricType not found !")) ; +} + /*! If isOnAllElements is false, returns index of element number. Use it with getNumber(MED_ALL_ELEMENTS). @@ -384,10 +427,23 @@ inline void SUPPORT::setNumberOfGeometricType(int NumberOfGeometricType) inline void SUPPORT::setGeometricType(const MED_EN::medGeometryElement *GeometricType) //--------------------------------------------------------------------- { - if (NULL == _geometricType) + if (!_geometricType) _geometricType.set(_numberOfGeometricType); for (int i=0;i<_numberOfGeometricType;i++) _geometricType[i] = GeometricType[i]; + + if (_profilNames.empty()) + { + // giving a default value to profile names + vector<string> prof_names( _numberOfGeometricType); + for (int itype=0; itype < _numberOfGeometricType; itype++) + { + ostringstream typestr; + typestr<<_name<<"_type"<<itype; + prof_names[itype]=typestr.str(); + } + _profilNames=prof_names; + } } @@ -399,8 +455,11 @@ inline void SUPPORT::setGeometricType(const MED_EN::medGeometryElement *Geometri inline void SUPPORT::setNumberOfElements(const int *NumberOfElements) //---------------------------------------------------------- { - if (NULL == _numberOfElements) - _numberOfElements.set(_numberOfGeometricType,NumberOfElements); + if (_numberOfElements == NULL) + if (_numberOfGeometricType) + _numberOfElements.set(_numberOfGeometricType,NumberOfElements); + else + _numberOfElements.set(0); _totalNumberOfElements = 0 ; for (int i=0;i<_numberOfGeometricType;i++) _totalNumberOfElements+=_numberOfElements[i]; diff --git a/src/MEDMEM/MEDMEM_Tags.hxx b/src/MEDMEM/MEDMEM_Tags.hxx index 048207b20..69644dddf 100644 --- a/src/MEDMEM/MEDMEM_Tags.hxx +++ b/src/MEDMEM/MEDMEM_Tags.hxx @@ -25,6 +25,7 @@ struct Gauss {}; struct NoGauss {}; struct FullInterlace{}; struct NoInterlace{}; +struct NoInterlaceByType{}; } diff --git a/src/MEDMEM/MEDMEM_TopLevel.hxx b/src/MEDMEM/MEDMEM_TopLevel.hxx index 5281aa334..164ef865d 100644 --- a/src/MEDMEM/MEDMEM_TopLevel.hxx +++ b/src/MEDMEM/MEDMEM_TopLevel.hxx @@ -63,7 +63,7 @@ namespace MEDMEM { FIELD<T> *fieldObjNoC=(FIELD<T> *)fieldObj; driverTypes type=DRIVERFACTORY::deduceDriverTypeFromFileName(fileName); - int id=fieldObj->addDriver(type, fileName, fieldObj->getName()); + int id=fieldObjNoC->addDriver(type, fileName, fieldObj->getName()); fieldObjNoC->write(id); } } diff --git a/src/MEDMEM/MEDMEM_TypeMeshDriver.cxx b/src/MEDMEM/MEDMEM_TypeMeshDriver.cxx index a4fd4def0..a3aa6c4aa 100644 --- a/src/MEDMEM/MEDMEM_TypeMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_TypeMeshDriver.cxx @@ -40,7 +40,7 @@ TYPE_MESH_DRIVER::TYPE_MESH_DRIVER(): { } -TYPE_MESH_DRIVER::TYPE_MESH_DRIVER(const string & fileName, +TYPE_MESH_DRIVER::TYPE_MESH_DRIVER(const std::string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces accessMode): GENDRIVER(fileName,accessMode), diff --git a/src/MEDMEM/MEDMEM_TypeMeshDriver.hxx b/src/MEDMEM/MEDMEM_TypeMeshDriver.hxx index 8dcd36ed9..cd5267e2c 100644 --- a/src/MEDMEM/MEDMEM_TypeMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_TypeMeshDriver.hxx @@ -20,6 +20,8 @@ #ifndef TYPE_MESH_DRIVER_HXX #define TYPE_MESH_DRIVER_HXX +#include "MEDMEM.hxx" + #include <string> #include <vector> @@ -44,7 +46,7 @@ class MESH; class FAMILY; class GROUP; class CONNECTIVITY; -class TYPE_MESH_DRIVER : public GENDRIVER +class MEDMEM_EXPORT TYPE_MESH_DRIVER : public GENDRIVER { protected: @@ -61,7 +63,7 @@ public : /*! Constructor. */ - TYPE_MESH_DRIVER(const string & fileName, + TYPE_MESH_DRIVER(const std::string & fileName, MESH * ptrMesh, med_mode_acces accessMode) ; /*! @@ -97,7 +99,7 @@ private: }; -class TYPE_MESH_RDONLY_DRIVER : public virtual TYPE_MESH_DRIVER +class MEDMEM_EXPORT TYPE_MESH_RDONLY_DRIVER : public virtual TYPE_MESH_DRIVER { public : @@ -143,7 +145,7 @@ private: */ -class TYPE_MESH_WRONLY_DRIVER : public virtual TYPE_MESH_DRIVER { +class MEDMEM_EXPORT TYPE_MESH_WRONLY_DRIVER : public virtual TYPE_MESH_DRIVER { public : @@ -188,7 +190,7 @@ private: */ -class TYPE_MESH_RDWR_DRIVER : public TYPE_MESH_RDONLY_DRIVER, public TYPE_MESH_WRONLY_DRIVER { +class MEDMEM_EXPORT TYPE_MESH_RDWR_DRIVER : public TYPE_MESH_RDONLY_DRIVER, public TYPE_MESH_WRONLY_DRIVER { public : diff --git a/src/MEDMEM/MEDMEM_Unit.hxx b/src/MEDMEM/MEDMEM_Unit.hxx index 29b9aaf6c..4c2d09c8a 100644 --- a/src/MEDMEM/MEDMEM_Unit.hxx +++ b/src/MEDMEM/MEDMEM_Unit.hxx @@ -25,6 +25,8 @@ #ifndef UNIT_HXX #define UNIT_HXX +#include <MEDMEM.hxx> + #include <string> #include "MEDMEM_Utilities.hxx" @@ -32,7 +34,7 @@ #include "MEDMEM_define.hxx" namespace MEDMEM { -class UNIT { +class MEDMEM_EXPORT UNIT { protected: string _name ; string _description ; diff --git a/src/MEDMEM/MEDMEM_Utilities.hxx b/src/MEDMEM/MEDMEM_Utilities.hxx index 3adb52836..dff5421e6 100644 --- a/src/MEDMEM/MEDMEM_Utilities.hxx +++ b/src/MEDMEM/MEDMEM_Utilities.hxx @@ -20,6 +20,46 @@ #ifndef __MEDMEM_UTILITIES #define __MEDMEM_UTILITIES +// standart Linux/Unix functions +#include <string> + +#ifndef WNT + #include <libgen.h> +#endif +inline std::string getBaseName( std::string dataname ) { + std::string aBaseName = ""; +#ifndef WNT + aBaseName = basename((char*)dataname.c_str()); +#else + for ( int i = dataname.size()-1; i >= 0; i-- ) { + char aSymb = dataname[i]; + if ( dataname[i] == '\\' || dataname[i] == '/' ) + break; + aBaseName = dataname[i] + aBaseName; + } +#endif + return aBaseName; +} + +inline std::string getDirName( std::string dataname ) { + std::string aDirName = ""; +#ifndef WNT + aDirName = dirname((char*)dataname.c_str()); +#else + bool aFindLine = false; + for ( int i = dataname.size()-1; i >= 0; i-- ) { + char aSymb = dataname[i]; + if ( !aFindLine ) + aFindLine = dataname[i] == '\\' || dataname[i] == '/'; + else + aDirName = dataname[i] + aDirName; + } + if ( !aFindLine ) + aDirName = '.'; +#endif + return aDirName; +} + #ifdef MED_WITHOUT_KERNEL # include <cstdlib> diff --git a/src/MEDMEM/MEDMEM_VtkFieldDriver.hxx b/src/MEDMEM/MEDMEM_VtkFieldDriver.hxx index 9cc1209cd..c937a3071 100644 --- a/src/MEDMEM/MEDMEM_VtkFieldDriver.hxx +++ b/src/MEDMEM/MEDMEM_VtkFieldDriver.hxx @@ -618,12 +618,21 @@ template <class T> void VTK_FIELD_DRIVER<T>::write(void) const // IL EST POSSIBLE D'AVOIR LES DEUX BOUCLES D'ECRITURE POUR EVITER // DE CONVERTIR LE CHAMP DANS LE BON TYPE D'ENTRELACEMENT const T * value; + MEDMEM_Array_ * tmpArray = 0; if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) value = _ptrField->getValue(); + else if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + MEDMEM_Array_ * ptrArray = _ptrField->getArray(); + MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * > ( ptrArray ); + MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert2No( *temp ); + tmpArray = array; + value = array->getPtr(); + } else { MEDMEM_Array_ * ptrArray = _ptrField->getArray(); MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * > ( ptrArray ); MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert( *temp ); + tmpArray = array; value = array->getPtr(); } @@ -634,8 +643,8 @@ template <class T> void VTK_FIELD_DRIVER<T>::write(void) const (*_vtkFile) << endl ; } - if ( _ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) - delete value; + if ( _ptrField->getInterlacingType() != MED_EN::MED_NO_INTERLACE ) + delete tmpArray; END_OF(LOC); } @@ -715,12 +724,21 @@ template <class T> void VTK_FIELD_DRIVER<T>::writeAppend(void) const throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" there are more than 4 components !")); const T * value ; + MEDMEM_Array_ * tmpArray = 0; if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE ) value = _ptrField->getValue(); + else if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) { + MEDMEM_Array_ * ptrArray = _ptrField->getArray(); + MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * > ( ptrArray ); + MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert2No( *temp ); + tmpArray = array; + value = array->getPtr(); + } else { MEDMEM_Array_ * ptrArray = _ptrField->getArray(); MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * > ( ptrArray ); MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert( *temp ); + tmpArray = array; value = array->getPtr(); } @@ -731,8 +749,8 @@ template <class T> void VTK_FIELD_DRIVER<T>::writeAppend(void) const (*_vtkFile) << endl ; } - if ( _ptrField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) - delete value; + if ( _ptrField->getInterlacingType() != MED_EN::MED_NO_INTERLACE ) + delete tmpArray; END_OF(LOC); } diff --git a/src/MEDMEM/MEDMEM_VtkMedDriver.cxx b/src/MEDMEM/MEDMEM_VtkMedDriver.cxx index 4444d9637..1b0428dda 100644 --- a/src/MEDMEM/MEDMEM_VtkMedDriver.cxx +++ b/src/MEDMEM/MEDMEM_VtkMedDriver.cxx @@ -62,7 +62,6 @@ VTK_MED_DRIVER::~VTK_MED_DRIVER() const char * LOC ="VTK_MED_DRIVER::~VTK_MED_DRIVER()"; BEGIN_OF(LOC); - close(); delete _vtkFile ; END_OF(LOC); @@ -112,10 +111,10 @@ void VTK_MED_DRIVER::closeConst() const { // if (*_vtkFile) // _status = MED_CLOSED ; // else - if (!(*_vtkFile)) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file " - << _fileName) - ); +// if (!(*_vtkFile)) +// throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file " +// << _fileName) +// ); END_OF(LOC); } @@ -481,6 +480,12 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { ) ); value = myArray->getPtr(); + } else if ( myField->getInterlacingType() == MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< FIELD<int,NoInterlaceByType>* > + (myField)->getArrayNoGauss() + ) + ); + value = myArray->getPtr(); } else { value = ((FIELD<int>*)myField)->getValue() ; } @@ -490,8 +495,9 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { (*_vtkFile) << value[j*NumberOfValue+i] << " " ; (*_vtkFile) << endl ; } - if ( myField->getInterlacingType() == MED_FULL_INTERLACE ) - delete[] myArray; + // mkr : PAL13994 (commented the code below) + if ( myField->getInterlacingType() != MED_NO_INTERLACE ) + delete /*[]*/ myArray; break ; } case MED_REEL64 : { @@ -514,6 +520,12 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { ) ); value = myArray->getPtr(); + } else if ( myField->getInterlacingType() == MED_NO_INTERLACE_BY_TYPE ) { + myArray = ArrayConvert2No( *( dynamic_cast< FIELD<double,NoInterlaceByType>* > + (myField)->getArrayNoGauss() + ) + ); + value = myArray->getPtr(); } else { value = ((FIELD<double>*)myField)->getValue() ; } @@ -523,8 +535,9 @@ void VTK_MED_DRIVER::writeField(FIELD_ * myField,string name) const { (*_vtkFile) << value[j*NumberOfValue+i] << " " ; (*_vtkFile) << endl ; } - if ( myField->getInterlacingType() == MED_FULL_INTERLACE ) - delete[] myArray; + // mkr : PAL13994 (commented the code below) + if ( myField->getInterlacingType() != MED_NO_INTERLACE ) + delete/*[]*/ myArray; break ; } default : { diff --git a/src/MEDMEM/MEDMEM_VtkMedDriver.hxx b/src/MEDMEM/MEDMEM_VtkMedDriver.hxx index 622f948ca..82d0445e9 100644 --- a/src/MEDMEM/MEDMEM_VtkMedDriver.hxx +++ b/src/MEDMEM/MEDMEM_VtkMedDriver.hxx @@ -20,6 +20,8 @@ #ifndef VTK_MED_DRIVER_HXX #define VTK_MED_DRIVER_HXX +#include "MEDMEM.hxx" + #include <string> #include "MEDMEM_STRING.hxx" #include "MEDMEM_Utilities.hxx" @@ -38,7 +40,7 @@ class SUPPORT; class FIELD_; class MED; // This driver pilots within a VTK class read/write accesses of fields/meshes -class VTK_MED_DRIVER : public GENDRIVER +class MEDMEM_EXPORT VTK_MED_DRIVER : public GENDRIVER { protected: diff --git a/src/MEDMEM/MEDMEM_VtkMeshDriver.cxx b/src/MEDMEM/MEDMEM_VtkMeshDriver.cxx index 443c5ca92..0b7e57eb7 100644 --- a/src/MEDMEM/MEDMEM_VtkMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_VtkMeshDriver.cxx @@ -68,7 +68,8 @@ VTK_MESH_DRIVER::VTK_MESH_DRIVER(const VTK_MESH_DRIVER & driver): _ptrMesh(driver._ptrMesh), _meshName(driver._meshName) { - _ptrMesh->addDriver(*this); + // next string commented by skl for bug NPAL14840 + //_ptrMesh->addDriver(*this); _vtkFile = new ofstream(); } @@ -407,7 +408,6 @@ void VTK_MESH_DRIVER::write(void) const (*_vtkFile) << vtkType << endl ; } - END_OF(LOC); } diff --git a/src/MEDMEM/MEDMEM_VtkMeshDriver.hxx b/src/MEDMEM/MEDMEM_VtkMeshDriver.hxx index ce1649c5d..d7c7f9cf3 100644 --- a/src/MEDMEM/MEDMEM_VtkMeshDriver.hxx +++ b/src/MEDMEM/MEDMEM_VtkMeshDriver.hxx @@ -20,6 +20,8 @@ #ifndef VTK_MESH_DRIVER_HXX #define VTK_MESH_DRIVER_HXX +#include "MEDMEM.hxx" + #include <string> #include <vector> #include "MEDMEM_define.hxx" @@ -44,7 +46,7 @@ class MESH; class FAMILY; class GROUP; class CONNECTIVITY; -class VTK_MESH_DRIVER : public GENDRIVER +class MEDMEM_EXPORT VTK_MESH_DRIVER : public GENDRIVER { protected: diff --git a/src/MEDMEM/MEDMEM_define.hxx b/src/MEDMEM/MEDMEM_define.hxx index 68dc408f7..19ca0c2be 100644 --- a/src/MEDMEM/MEDMEM_define.hxx +++ b/src/MEDMEM/MEDMEM_define.hxx @@ -75,6 +75,7 @@ namespace MED_EN { typedef long medModeSwitch; const medModeSwitch MED_FULL_INTERLACE = 0; const medModeSwitch MED_NO_INTERLACE = 1; + const medModeSwitch MED_NO_INTERLACE_BY_TYPE = 2; const medModeSwitch MED_UNDEFINED_INTERLACE = 3; typedef long medConnectivity; @@ -83,7 +84,7 @@ namespace MED_EN { typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type; - typedef enum {MED_LECT,MED_ECRI,MED_REMP} med_mode_acces; + typedef enum {MED_LECT,MED_ECRI,MED_REMP,MED_CREA} med_mode_acces; typedef enum {ASCENDING=7,DESCENDING=77} med_sort_direc; @@ -113,7 +114,7 @@ typedef enum {MED_HDF_VERSION, MED_VERSION, MED_FICH_DES} med_fich_info; // //#define MED_ALL 0 !!!!! NB: WARNING MED_ALL deja utilise dans l'enum medGeometryElement !!!!!!!! // #define MED_ALL 0 -#if defined(SUN4SOL2) || defined(PCLINUX) || defined(OSF1_32) || defined(IRIX64_32) || defined(RS6000) +#if defined(SUN4SOL2) || defined(PCLINUX) || defined(PCLINUX64_32) || defined(OSF1_32) || defined(IRIX64_32) || defined(RS6000) /* interface C/FORTRAN */ /* this true only with g77 and gcc : we must change it to use directly NOMF_... and INT32 or INT64 - it will be more simple to understand and to use ! */ // #define NOMF_POST_UNDERSCORE @@ -141,7 +142,7 @@ typedef int med_int; typedef double med_float; #endif -#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) +#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64) // #define NOMF_POST_UNDERSCORE /* correspondance des types avec HDF 5 */ @@ -211,6 +212,7 @@ typedef double med_float; // rĂƒÂ©initialisĂƒÂ©. Cf une ĂƒÂ©volution de MED. #define MED_WRONLY MED_ECRI #define MED_RDWR MED_ECRI +#define MED_CREATE MED_CREA // Fin #define FAUX 0 @@ -243,6 +245,8 @@ typedef double med_float; #define OK 0 #define KO 1 +//maximum number of groups handled by the Family Group converter +#define MAX_NB_GROUP 100000 /* enum definition for the used Med File version V2.1 or V2.2 because of incompatibility between them. diff --git a/src/MEDMEM/MEDMEM_medimport_src.cxx b/src/MEDMEM/MEDMEM_medimport_src.cxx index 55d196265..e1fb5f9e3 100644 --- a/src/MEDMEM/MEDMEM_medimport_src.cxx +++ b/src/MEDMEM/MEDMEM_medimport_src.cxx @@ -35,2241 +35,30 @@ * *************************************************************************/ #include "MEDMEM_medimport_src.hxx" -#include "hdf5_version2api.hxx" -using namespace med_2_2; -using namespace MEDMEM; - -extern "C" { - extern med_err MEDgaussInfo(med_idt fid, int indice, char * locname, - med_geometrie_element * type_geo, - med_int * ngauss ); - - extern void _MEDmodeErreurVerrouiller(void); - - extern med_err _MEDnomGeometrie(char *nom_geo, - med_geometrie_element type_geo); -} - -med_err med_2_2::OLD_MEDattrNumLire(med_idt pere, med_type_champ type, - char *nom, unsigned char *val, - hid_t hdf_file) -{ - med_idt attid; - med_err ret; - int type_hdf; - - if ((attid = H5Aopen_name(pere,nom)) < 0) - return -1; - - switch(type) - { - case MED_FLOAT64 : -#if defined(PCLINUX) || defined(OSF1) -/* type_hdf = H5T_IEEE_F64BE; */ - if (H5Tequal(hdf_file,H5T_IEEE_F64BE)) - type_hdf = H5T_IEEE_F64LE; - if (H5Tequal(hdf_file,H5T_IEEE_F64LE)) - type_hdf = H5T_IEEE_F64BE; -#else -/* type_hdf = H5T_IEEE_F64LE; */ - if (H5Tequal(hdf_file,H5T_IEEE_F64BE)) - type_hdf = H5T_IEEE_F64LE; - if (H5Tequal(hdf_file,H5T_IEEE_F64LE)) - type_hdf = H5T_IEEE_F64BE; -#endif - break; - - case MED_INT : -#if defined(IRIX64) || defined(OSF1) - type_hdf = H5T_NATIVE_LONG; -#else - type_hdf = H5T_NATIVE_INT; -#endif - break; - - default : - return -1; - } - - if ((ret = H5Aread(attid,type_hdf,val)) < 0) - return -1; - - if ((ret = H5Aclose(attid)) < 0) - return -1; - - return 0; -} - - -med_err med_2_2::OLD_MEDdatasetNumLire(med_idt pere, char *nom, - med_type_champ type, - med_mode_switch interlace, - med_size nbdim, med_size fixdim, - med_size psize, med_ssize * pfltab, - med_int ngauss, - unsigned char *val,hid_t hdf_file) -{ - med_idt dataset, dataspace = 0, memspace = 0; - -#ifdef HDF_NEW_API - med_size start_mem[1],start_data[1],*pflmem=0,*pfldsk=0; -#else - med_ssize start_mem[1],start_data[1],*pflmem=0,*pfldsk=0; -#endif - - med_size stride[1],count[1],pcount[1],size[1],pflsize[1]; - med_err ret; - int i,j,index,type_hdf; - hid_t datatype; - size_t typesize; - int dim, firstdim, dimutil, lastdim; - med_mode_profil pflmod; - - /* Verify fixdim is between [0, nbdim] ( 0 is MED_ALL ) */ - if ( ( fixdim < 0 ) || ( fixdim > nbdim ) ) - return -1; - - /* block pflmod to MED_COMPACT (until med2.2) */ - pflmod = MED_COMPACT; - - switch(type) - { - case MED_FLOAT64 : - /* 1) IA32 is LE but due to an (?HDF convertion BUG?) when using H5T_NATIVE_DOUBLE/MED_REEL64? under PCLINUX - the file read under SGI is incorrect - 2) Compaq OSF/1 is LE, since we force SGI64,SUN4SOL2,HP to write double in LE even if they are BE, mips OSF/1 must be BE - REM : Be careful of compatibility between MED files when changing this (med2.2) */ -#if defined(PCLINUX) || defined(OSF1) -/* type_hdf = H5T_IEEE_F64BE; */ - if (H5Tequal(hdf_file,H5T_IEEE_F64BE)) - type_hdf = H5T_IEEE_F64LE; - if (H5Tequal(hdf_file,H5T_IEEE_F64LE)) - type_hdf = H5T_IEEE_F64BE; -#else -/* type_hdf = H5T_IEEE_F64LE; */ - if (H5Tequal(hdf_file,H5T_IEEE_F64BE)) - type_hdf = H5T_IEEE_F64LE; - if (H5Tequal(hdf_file,H5T_IEEE_F64LE)) - type_hdf = H5T_IEEE_F64BE; -#endif - break; - - case MED_INT32 : - type_hdf = H5T_NATIVE_INT; - break; - - case MED_INT64 : - type_hdf = H5T_NATIVE_LONG; - break; - - default : - return -1; - } - - /* Ouverture du Dataset Ă  lire */ - if ((dataset = H5Dopen(pere,nom)) < 0) - return -1; - - /* Interrogation de la taille du dataset */ - if ( (datatype = H5Dget_type(dataset )) < 0) return -1; - if ( (typesize = H5Tget_size(datatype)) < 0) return -1; - size[0] = H5Dget_storage_size(dataset) / typesize; - if ( H5Tclose(datatype) < 0) return -1; - - /* Create dataspace */ - if ((dataspace = H5Screate_simple(1,size,NULL)) < 0) - return -1; - - switch(interlace) - { - case MED_FULL_INTERLACE : - - /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/ - if ( fixdim != MED_ALL) - { - firstdim = fixdim-1; - lastdim = fixdim; - dimutil = 1; - } else { - firstdim = 0; - lastdim = nbdim; - dimutil = nbdim; - } - - count [0] = (*size)/(nbdim); - - - /*rem: Pas de vĂ©rification de l'assertion (*size)=n*nbdim */ - if ( psize == MED_NOPF ) { - - /* Creation d'un data space mĂ©moire de dimension 1, de longeur size, et de longeur maxi size */ - if ( (memspace = H5Screate_simple (1, size, NULL)) <0) - return -1; - - stride[0] = nbdim; - - for (dim=firstdim; dim < lastdim; dim++) { - - start_mem[0] = dim; - if ( (ret = H5Sselect_hyperslab (memspace, H5S_SELECT_SET, start_mem, stride, - count, NULL)) <0) - return -1; - - start_data[0] = dim*count[0]; - if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL, - count, NULL)) <0) - return -1; - - if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace, - H5P_DEFAULT, val)) < 0) - return -1; - } - - } else { - - pflsize [0] = psize*ngauss*nbdim; - pcount [0] = psize*ngauss*dimutil; - -#ifdef HDF_NEW_API - pflmem = (med_size *) malloc (sizeof(med_size)*pcount[0]); - pfldsk = (med_size *) malloc (sizeof(med_size)*pcount[0]); -#else - pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); - pfldsk = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); -#endif - - switch(pflmod) - { /* switch pflmod pour FULL_INTERLACE*/ - case MED_GLOBAL : - - /* Creation d'un data space mĂ©moire de dimension 1, de longeur size, et de longeur maxi size */ - if ( (memspace = H5Screate_simple (1, size, NULL)) <0) - return -1; - - for (dim=firstdim; dim < lastdim; dim++) { - - for (i=0; i < psize; i++) /* i balaye les Ă©lements du profil */ - for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); - pflmem[index] = (pfltab[i]-1)*ngauss*nbdim + j*nbdim+dim; - pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; - } - } - -#ifdef HDF_NEW_API - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hsize_t **) pflmem ) ) <0) - return -1; - - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hsize_t **) pfldsk ) ) <0) - return -1; -#else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) - return -1; - - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) - return -1; -#endif - break; - - case MED_COMPACT : - - /* Creation d'un data space mĂ©moire de dimension 1, de la longeur du profil */ - /* La dimension utilisĂ©e est ici nbdim, mĂªme pour un profil compact on suppose */ - /* que l'utilisateur a toutes les coordonĂ©es stockĂ©es, mĂªme si il en demande qu'une */ - - if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0) - return -1; - - for (dim=firstdim; dim < lastdim; dim++) { - - for (i=0; i < psize; i++) /* i balaye les Ă©lements du profil */ - for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); - pflmem[index] = i*ngauss*nbdim + j*nbdim+dim; - pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; - } - } - -#ifdef HDF_NEW_API - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hsize_t **) pflmem ) ) <0) - return -1; - - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hsize_t **) pfldsk ) ) <0) - return -1; -#else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) - return -1; - - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) - return -1; -#endif - - break; - - default : - return -1; - } - - if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0) - return -1; - - free(pflmem); - free(pfldsk); - } - - break; - - case MED_NO_INTERLACE : - - /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/ - - count[0] = (*size)/nbdim; - - if ( psize == MED_NOPF ) { - - if ( fixdim != MED_ALL) - start_data[0] = (fixdim-1)*count[0]; - else { - count[0] = *size; - start_data[0] = 0; - }; - - if ( (ret = H5Sselect_hyperslab (dataspace, H5S_SELECT_SET, start_data, NULL, - count, NULL)) <0) - return -1; - - if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace, - H5P_DEFAULT, val)) < 0) - return -1; - - } else { - - if ( fixdim != MED_ALL) - { - firstdim = fixdim-1; - lastdim = fixdim; - dimutil = 1; - } else { - firstdim = 0; - lastdim = nbdim; - dimutil = nbdim; - } - - pflsize [0] = psize*ngauss*nbdim; - pcount [0] = psize*ngauss*dimutil; /* nom pas très coherent avec count !!! A revoir */ -#ifdef HDF_NEW_API - pfldsk = (med_size *) malloc(sizeof(med_size)*pcount[0]); -#else - pfldsk = (med_ssize *) malloc(sizeof(med_ssize)*pcount[0]); -#endif - - switch(pflmod) - { /*switch plfmod pour NO_INTERLACE */ - case MED_GLOBAL : - - for (dim=firstdim; dim < lastdim; dim++) { - - for (i=0; i < psize; i++) /* i balaye le nbre d'Ă©lements du profil */ - for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); - pfldsk[index] = dim*count[0]+(pfltab[i]-1)*ngauss+j; - } - } - -#ifdef HDF_NEW_API - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hsize_t **) pfldsk ) ) <0) - return -1; -#else - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) - return -1; -#endif - - if ((ret = H5Dread(dataset,type_hdf,dataspace,dataspace,H5P_DEFAULT, val)) < 0) - return -1; - - break; - - case MED_COMPACT : - - /* Creation d'un data space mĂ©moire de dimension 1, de la longeur du profil */ - /* La dimension utilisĂ©e est ici nbdim, mĂªme pour un profil compact on suppose */ - /* que l'utilisateur a toutes les coordonĂ©es stockĂ©es, mĂªme si il en demande qu'une */ - - if ( (memspace = H5Screate_simple (1, pflsize, NULL)) <0) - return -1; - -#ifdef HDF_NEW_API - pflmem = (med_size *) malloc (sizeof(med_size)*pcount[0]); -#else - pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); -#endif - - /* Le profil COMPACT est contigĂ¼e, mais il est possible que l'on selectionne uniquemenent une dimension*/ - - for (dim=firstdim; dim < lastdim; dim++) { - - for (i=0; i < psize; i++) /* i balaye le nbre d'Ă©lements du profil */ - for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); - pflmem[index] = dim*(psize*ngauss) + (pfltab[i]-1)*ngauss+j; - pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; - } - } - -#ifdef HDF_NEW_API - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hsize_t **) pflmem ) ) <0) - return -1; - - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hsize_t **) pfldsk ) ) <0) - return -1; -#else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) - return -1; - - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) - return -1; -#endif - - if ((ret = H5Dread(dataset,type_hdf,memspace,dataspace,H5P_DEFAULT, val)) < 0) - return -1; - - break; - - default : - return -1; - - } - - free(pfldsk); - - }; - - break; - - default : - return -1; - } - - - - if (memspace) - if ((ret = H5Sclose(memspace)) < 0) - return -1; - - if ((ret = H5Sclose(dataspace)) < 0) - return -1; - - if ((ret = H5Dclose(dataset)) < 0) - return -1; - - return 0; -} - - -void med_2_2::conversion_chaine(char *ancienne_chaine, - char *nouvelle_chaine, - med_int n) -{ - int i; - int j; - char tmp[MED_TAILLE_PNOM+1]; - - for (i=0;i<n;i++) { - if (i == n-1) { - strcpy(tmp,ancienne_chaine+i*ANCIEN_MED_TAILLE_PNOM); - if (strlen(tmp) < ANCIEN_MED_TAILLE_PNOM) - for(j=strlen(tmp);j<ANCIEN_MED_TAILLE_PNOM;j++) - tmp[j] = ' '; - } - else - strncpy(tmp,ancienne_chaine+i*ANCIEN_MED_TAILLE_PNOM,ANCIEN_MED_TAILLE_PNOM); - tmp[ANCIEN_MED_TAILLE_PNOM] = '\0'; - /* 12345678 */ - strcat(tmp," "); - /* printf("[%s]\n",tmp); */ - if (i == 0) - strcpy(nouvelle_chaine,tmp); - else - strcat(nouvelle_chaine,tmp); - } - *(nouvelle_chaine+MED_TAILLE_PNOM*n) = '\0'; -} - -void med_2_2::MAJ_version(med_idt fid) throw (MEDEXCEPTION) -{ - med_err ret; - med_idt gid; - med_int majeur, mineur, release; - - /* On ecrit le bon numero de version */ - majeur = 2; - mineur = 2; - release = 1; - gid = _MEDdatagroupOuvrir(fid,MED_NOM_INFOS); - if (gid < 0) - gid = _MEDdatagroupCreer(fid,MED_NOM_INFOS); - -// EXIT_IF(gid < 0,"Ouverture du groupe HDF MED_NOM_INFOS",NULL); - - if (gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(gid,MED_NOM_MAJEUR,&majeur); - -// EXIT_IF(ret < 0,"Ecriture du numĂ©ro majeur",NULL); - - if (ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(gid,MED_NOM_MINEUR,&mineur); - -// EXIT_IF(ret < 0,"Ecriture du numĂ©ro mineur",NULL); - - if (ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(gid,MED_NOM_RELEASE,&release); - -// EXIT_IF(ret < 0,"Ecrriture du numĂ©ro de release",NULL); +#include <exception> +#include <iostream> - if (ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF MED_NOM_INFOS",NULL); +using namespace MEDMEM; - if (ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -} -void med_2_2::MAJ_noeuds_maillage(med_idt mid, med_int dimension) - throw (MEDEXCEPTION) +char * MEDMEM::med2_1_To_med2_3(char * fileNameIn) throw (MEDEXCEPTION) { - med_idt nid, gid, tid; - med_float *coo; - char *nom, *unit; - char tmp[MED_TAILLE_PNOM+1]; - char *nouvelle_chaine; - med_int n; - med_size dimd[1]; - med_err ret; - int i; - hid_t hdf_type; - med_repere repere; - - /* Accès aux noeuds du maillage */ - nid = _MEDdatagroupOuvrir(mid,MED_NOM_NOE); - -// EXIT_IF(nid < 0,"Ouverture du groupe HDF MED_NOM_NOE",NULL); - - if(nid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Lecture du nombre de noeuds */ - gid = _MEDdatasetOuvrir(nid,MED_NOM_COO); - if (gid > 0) - ret = _MEDattrEntierLire(gid,MED_NOM_NBR,&n); - -// EXIT_IF(gid < 0,"Lecture du nombre de noeuds",NULL); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Mise a jour des coordonnees */ - /* On cree un groupe HDF tampon */ - /* Lecture des coordonnĂ©es */ - hdf_type = H5Dget_type(gid); - -// EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des coordonnĂ©es",NULL); - - if(hdf_type < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - coo = (med_float *) malloc(sizeof(med_float)*n*dimension); - -// EXIT_IF(coo == NULL,NULL,NULL); - - if(coo == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = OLD_MEDdatasetNumLire(nid,MED_NOM_COO,MED_FLOAT64, - MED_FULL_INTERLACE,dimension,MED_ALL, - 0,NULL,MED_NOPG, - (unsigned char*) coo,hdf_type); - -// EXIT_IF(ret < 0,"Lecture des coordonnĂ©es des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - dimd[0] = n*dimension; - /* printf("EGALITE des types : %d \n",H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)); */ - /* printf("Avant conversion : [%f] [%f] [%f] \n",*(coo),*(coo+1),*(coo+2)); */ - if (! H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)) { - ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)coo,NULL,0); - /* printf("Après conversion Ă©ventuelle : [%f] [%f] [%f] \n",*(coo),*(coo+1),*(coo+2)); */ - -// EXIT_IF(ret < 0,"Conversion des coordonnĂ©es des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } - ret = H5Tclose(hdf_type); - -// EXIT_IF(ret < 0,"Fermeture du data type HDF",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On reporte les coordonnĂ©es dans le groupe HDF TMP */ - ret = _MEDdatasetNumEcrire(nid,"TMP",MED_FLOAT64,MED_FULL_INTERLACE, - dimension,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd, - (unsigned char*) coo); - -// EXIT_IF(ret < 0,"Ecriture des coordonnĂ©es des noeuds après conversion",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - free(coo); - - /* Ecriture du nombre de noeuds et du type du repertoire dans le dataset TMP */ - tid = _MEDdatasetOuvrir(nid,"TMP"); - -// EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL); - - if(tid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(tid,MED_NOM_NBR,&n); - -// EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierLire(gid,MED_NOM_REP,&repere); - -// EXIT_IF(ret < 0,"Lecture du type de repere des coordonnĂ©es", NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(tid,MED_NOM_REP,&repere); - -// EXIT_IF(ret < 0,"Ecriture du type de rĂ©pertoire dans le dataset HDF TMP",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Mise a jour des noms et types des unitĂ©s des coordonnees */ - nom = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1); - -// EXIT_IF(nom == NULL,NULL,NULL); - - if(nom == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - unit = (char *) malloc(dimension*ANCIEN_MED_TAILLE_PNOM+1); - -// EXIT_IF(unit == NULL,NULL,NULL); - - if(unit == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); +// char * fileNameOut = new char[strlen(fileNameIn)+strlen("2.3")+1]; + char * fileNameOut = ""; + int ret; - nouvelle_chaine = (char *) malloc(dimension*MED_TAILLE_PNOM+1); - -// EXIT_IF(nouvelle_chaine == NULL,NULL,NULL); - - if(nouvelle_chaine == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrStringLire(gid,MED_NOM_NOM,dimension*ANCIEN_MED_TAILLE_PNOM,nom); - -// EXIT_IF(ret < 0,"Lecture des noms des coordonnĂ©es des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrStringLire(gid,MED_NOM_UNI,dimension*ANCIEN_MED_TAILLE_PNOM,unit); - -// EXIT_IF(ret < 0,"Lecture des unitĂ©s des coordonnĂ©es des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - conversion_chaine(nom,nouvelle_chaine,dimension); - ret = _MEDattrStringEcrire(tid,MED_NOM_NOM,dimension*MED_TAILLE_PNOM,nouvelle_chaine); - -// EXIT_IF(ret < 0,"Ecriture des nouveaux noms des coordonnĂ©es des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - conversion_chaine(unit,nouvelle_chaine,dimension); - ret = _MEDattrStringEcrire(tid,MED_NOM_UNI,dimension*MED_TAILLE_PNOM,nouvelle_chaine); - -// EXIT_IF(ret < 0,"Ecriture des nouvelles unitĂ©s des coordonnĂ©es des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - free(nom); - free(unit); - free(nouvelle_chaine); - - /* Fermeture de l'accès aux coordonnĂ©es */ - ret = _MEDdatasetFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_COO",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Gunlink(nid,MED_NOM_COO); - -// EXIT_IF(ret < 0,"Suppression des anciennes coordonnĂ©es",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatasetFermer(tid); - -// EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Gmove(nid,"TMP",MED_NOM_COO); - -// EXIT_IF(ret < 0,"Mise en place des nouvelles coordonnĂ©es",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Mise a jour des noms des noeuds */ - nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1); - -// EXIT_IF(nom == NULL,NULL,NULL); - - if(nom == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1); - -// EXIT_IF(nouvelle_chaine == NULL,NULL,NULL); - - if(nouvelle_chaine == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatasetStringLire(nid,MED_NOM_NOM,nom); - if (ret == 0) { - conversion_chaine(nom,nouvelle_chaine,n); - H5Gunlink(nid,MED_NOM_NOM); - dimd[0] = n*MED_TAILLE_PNOM+1; - ret = _MEDdatasetStringEcrire(nid,MED_NOM_NOM,dimd,nouvelle_chaine); - -// EXIT_IF(ret < 0,"Ecriture des nouveaux noms des noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - gid = _MEDdatasetOuvrir(nid,MED_NOM_NOM); - ret = _MEDattrEntierEcrire(gid,MED_NOM_NBR,&n); - ret = _MEDdatasetFermer(gid); - } - free(nom); - free(nouvelle_chaine); - - /* on ferme tout */ - ret = _MEDdatagroupFermer(nid); - -// EXIT_IF(ret < 0,"Fermeture de l'accès aux noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); -} - -void med_2_2::MAJ_elements_maillage(med_idt mid, med_int dimension) - throw (MEDEXCEPTION) -{ - med_idt eid,gid,did,tid; - med_err ret; - int i,j; - med_geometrie_element typmai[MED_NBR_GEOMETRIE_MAILLE] = {MED_POINT1,MED_SEG2, - MED_SEG3,MED_TRIA3, - MED_TRIA6,MED_QUAD4, - MED_QUAD8,MED_TETRA4, - MED_TETRA10,MED_HEXA8, - MED_HEXA20,MED_PENTA6, - MED_PENTA15,MED_PYRA5, - MED_PYRA13}; - int taille, edim; - char *nom, *nouvelle_chaine; - char nomgroup[MED_TAILLE_NOM_ENTITE+1]; - med_int n; - med_size dimd[1]; - med_int *old_conn,*conn; +// strcpy(fileNameOut,fileNameIn); +// strcat(fileNameOut,"2.3"); - /* On ne regarde que les mailles et la connectivitĂ© nodale */ - eid = _MEDdatagroupOuvrir(mid,MED_NOM_MAI); - -// EXIT_IF(eid < 0,"Ouverture du groupe HDF MED_NOM_MAI",NULL); - - if(eid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On normalise selon tous les types geometriques */ - for (i=0;i<MED_NBR_GEOMETRIE_MAILLE;i++) { - - /* On recupere le nom du groupe HDF */ - _MEDnomGeometrie(nomgroup,typmai[i]); - - /* On accède au type s'il existe dans le fichier */ - gid = _MEDdatagroupOuvrir(eid,nomgroup); - if (gid < 0) - continue; - - /* Nombre d'element ? */ - did = _MEDdatasetOuvrir(gid,MED_NOM_NOD); - -// EXIT_IF(did < 0,"Ouverture du dataset HDF MED_NOM_NOD",NULL); - - if(did < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierLire(did,MED_NOM_NBR,&n); - -// EXIT_IF(ret < 0,"Lecture du nombre d'elements",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatasetFermer(did); - -// EXIT_IF(ret < 0,"Fermeture du dataset HDF MED_NOM_NOD",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* on normalise la connectivitĂ© si edim < dimension */ - edim = typmai[i] / 100; - if (edim < dimension) { - taille = typmai[i]%100 + 1; - old_conn = (med_int *) malloc(sizeof(med_int)*taille*n); - -// EXIT_IF(old_conn == NULL,NULL,NULL); - - if(old_conn == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -#if defined(IRIX64)||defined(OSF1) - ret = OLD_MEDdatasetNumLire(gid,MED_NOM_NOD,MED_INT64, - MED_NO_INTERLACE,(med_size)taille,MED_ALL, - 0,NULL,MED_NOPG, - (unsigned char*) old_conn,H5T_NATIVE_INT); -#else - ret = OLD_MEDdatasetNumLire(gid,MED_NOM_NOD,MED_INT32, - MED_NO_INTERLACE,(med_size) taille,MED_ALL, - 0,NULL,MED_NOPG, - (unsigned char*) old_conn,H5T_NATIVE_INT); -#endif - /* On recopie dans le bon tableau */ - taille --; - conn = (med_int *) malloc(sizeof(med_int)*taille*n); - -// EXIT_IF(conn == NULL,NULL,NULL); - - if(conn == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - for (j=0;j<n*taille;j++) - *(conn+j) = *(old_conn+j); - dimd[0] = n*taille; -#if defined(IRIX64)||defined(OSF1) - ret = _MEDdatasetNumEcrire(gid,"TMP",MED_INT64,MED_NO_INTERLACE, - taille,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd, - (unsigned char*) conn); -#else - ret = _MEDdatasetNumEcrire(gid,"TMP",MED_INT32,MED_NO_INTERLACE, - taille,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd, - (unsigned char*) conn); -#endif - -// EXIT_IF(ret < 0,"Ecriture de la nouvelle connectivitĂ© des mailles",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); + try { + ret=MEDimport(fileNameIn,fileNameOut) ; + } catch ( std::exception &ex) { + std::cout << "An error eoccured durrnig execution of medImport" << std::endl; + std::cout << ex.what() << std::endl; + throw MEDEXCEPTION("An error occured during execution of medImport "); - /* Ecriture du nombre de mailles dans le dataset HDF TMP */ - tid = _MEDdatasetOuvrir(gid,"TMP"); - -// EXIT_IF(tid < 0,"Ouverture du dataset HDF TMP",NULL); - - if(tid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(tid,MED_NOM_NBR,&n); - -// EXIT_IF(ret < 0,"Ecriture du nombre de noeuds dans le dataset HDF TMP",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatasetFermer(tid); - -// EXIT_IF(ret < 0,"Fermeture du dataset HDF TMP",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Fermeture de l'accès aux connectivites */ - ret = H5Gunlink(gid,MED_NOM_NOD); - -// EXIT_IF(ret < 0,"Suppression des anciennes connectivitĂ©s",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Gmove(gid,"TMP",MED_NOM_NOD); - -// EXIT_IF(ret < 0,"Mise en place des nouvelles connectivitĂ©s",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* on libere la memoire */ - free(old_conn); - free(conn); - } - - /* Mise a niveau des noms */ - nom = (char *) malloc(n*ANCIEN_MED_TAILLE_PNOM+1); - -// EXIT_IF(nom == NULL,NULL,NULL); - - if(nom == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - nouvelle_chaine = (char *) malloc(n*MED_TAILLE_PNOM+1); - -// EXIT_IF(nouvelle_chaine == NULL,NULL,NULL); - - if(nouvelle_chaine == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatasetStringLire(gid,MED_NOM_NOM,nom); - if (ret == 0) { - conversion_chaine(nom,nouvelle_chaine,n); - H5Gunlink(gid,MED_NOM_NOM); - dimd[0] = n*MED_TAILLE_PNOM+1; - ret = _MEDdatasetStringEcrire(gid,MED_NOM_NOM,dimd,nouvelle_chaine); - -// EXIT_IF(ret < 0,"Ecriture des nouveaux noms des Ă©lĂ©ments",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - did = _MEDdatasetOuvrir(gid,MED_NOM_NOM); - ret = _MEDattrEntierEcrire(did,MED_NOM_NBR,&n); - ret = _MEDdatasetFermer(did); - } - free(nom); - free(nouvelle_chaine); - - /* on ferme avant de passer au type geometrique suivant */ - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture de l'accès aux mailles",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); } - - /* On ferme tout */ - ret = _MEDdatagroupFermer(eid); - -// EXIT_IF(ret < 0,"Fermeture de l'accès aux mailles",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); -} - -void med_2_2::MAJ_familles_maillage(med_idt mid) throw (MEDEXCEPTION) -{ - med_idt fid, gid; - char *nouvelle_chaine; - int n; - med_size dimd[1]; - med_err ret; - int i; - char chemin[MED_TAILLE_FAS+2*MED_TAILLE_NOM+1]; - char nom[MED_TAILLE_NOM+1]; - char *noeuds, *elements; - int nnoeuds = 0; - int nelements = 0; - med_int numero; - char *groupe_noeuds = "NOEUD"; - char *groupe_elements = "ELEME"; - char *nom_famille_zero = "FAMILLE_ZERO"; - char famille0[MED_TAILLE_NOM+1]; - int *index_noeuds, *index_elements; - char stockage[MED_TAILLE_DESC]; - med_float *valr; - - /* Combien de famille ? */ - fid = _MEDdatagroupOuvrir(mid,"FAS"); - -// EXIT_IF(fid < 0,"Ouverture du groupe HDF 'FAS'",NULL); - - if(fid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - n = 0; - _MEDnObjets(fid,".",&n); - -// EXIT_IF(n < 0,"Lecture du nombre de famille",NULL); - - if(n < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - noeuds = (char *) malloc(n*MED_TAILLE_NOM+1); - -// EXIT_IF(noeuds == NULL,NULL,NULL); - - if(noeuds == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - index_noeuds = (int *) malloc(sizeof(int)*(n+1)); - -// EXIT_IF(index_noeuds == NULL,NULL,NULL); - - if(index_noeuds < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - elements = (char *) malloc(n*MED_TAILLE_NOM+1); - -// EXIT_IF(elements == NULL,NULL,NULL); - - if(elements == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - index_elements = (int *) malloc(sizeof(int)*(n+1)); - -// EXIT_IF(index_elements == NULL,NULL,NULL); - if(index_elements == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On recupere les familles une par une et on les - normalise */ - for (i=0;i<n;i++) { - ret = _MEDobjetIdentifier(fid,".",i,nom); - -// EXIT_IF(ret < 0,"Identification d'une famille",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On accede a la famille */ - gid = _MEDdatagroupOuvrir(fid,nom); - -// EXIT_IF(gid < 0,"Ouverture de l'accès Ă  la famille",nom); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On lit le numero de la famille */ - ret = _MEDattrEntierLire(gid,MED_NOM_NUM,&numero); - -// EXIT_IF(ret < 0,"Lecture du numĂ©ro de la famille",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On ferme l'acces a la famille */ - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture de l'accès a la famille",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - if (numero == 0) - strcpy(famille0,nom); - - if (numero < 0) { - if (nelements == 0) { - *(index_elements) = 0; - strcpy(elements,nom); - } - else - strcat(elements,nom); - nelements ++; - *(index_elements+nelements) = strlen(nom) + *(index_elements+nelements-1); - } - - if (numero > 0) { - if (nnoeuds == 0) { - strcpy(noeuds,nom); - *(index_noeuds) = 0; - } - else - strcat(noeuds,nom); - nnoeuds++; - *(index_noeuds+nnoeuds) = strlen(nom) + *(index_noeuds+nnoeuds-1); - } - } - - /* Normalisation de la famille 0 */ - ret = H5Gmove(fid,famille0,nom_famille_zero); - -// EXIT_IF(ret < 0,"Normalisation de la famille ZERO",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On cree les groupes HDF pour les familles de noeuds et d'elements */ - gid = _MEDdatagroupCreer(fid,groupe_noeuds); - -// EXIT_IF(gid < 0,"Creation du grupe HDF pour les familles de noeuds",NULL); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles de noeuds",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - gid = _MEDdatagroupCreer(fid,groupe_elements); - -// EXIT_IF(gid < 0,"Creation du groupe HDF pour les familles d'Ă©lĂ©ments",NULL); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles d'Ă©lĂ©ments",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On deplace les groupes HDF des familles en fonction de la nature de - chaque famille */ - for (i=0;i<nnoeuds;i++) { - strncpy(nom,noeuds+*(index_noeuds+i),*(index_noeuds+i+1)-*(index_noeuds+i)); - nom[*(index_noeuds+i+1)-*(index_noeuds+i)] = '\0'; - strcpy(stockage,groupe_noeuds); - strcat(stockage,"/"); - strcat(stockage,nom); - ret = H5Gmove(fid,nom,stockage); - -// EXIT_IF(ret < 0,"Normalisation de la famille",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } - - for (i=0;i<nelements;i++) { - strncpy(nom,elements+*(index_elements+i),*(index_elements+i+1)-*(index_elements+i)); - nom[*(index_elements+i+1)-*(index_elements+i)] = '\0'; - strcpy(stockage,groupe_elements); - strcat(stockage,"/"); - strcat(stockage,nom); - ret = H5Gmove(fid,nom,stockage); - -// EXIT_IF(ret < 0,"Normalisation de la famille",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } - - /* On libere la memoire */ - free(noeuds); - free(index_noeuds); - free(elements); - free(index_elements); - - /* On ferme tout */ - ret = _MEDdatagroupFermer(fid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF 'FAS'",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); -} - -void med_2_2::MAJ_maillages(med_idt fid) throw (MEDEXCEPTION) -{ - med_idt gid; - med_err ret; - int n,i; - char nom[MED_TAILLE_NOM+1]; - char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1]; - char description[MED_TAILLE_DESC+1] = "Maillage converti au format MED V2.2"; - med_int type = (med_int) MED_NON_STRUCTURE; - med_int dimension; - - /* Lecture du nombre de maillages */ - n = 0; - _MEDnObjets(fid,MED_MAA,&n); - -// EXIT_IF(n < 0,"Erreur a la lecture du nombre de maillage",NULL); - - if(n < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* - * Mise a jour des maillages : - * - type : MED_NON_STRUCTURE - * - description : "Maillage converti au format V2.2" - */ - for (i=0;i<n;i++) { - /* on recupere le nom du maillage */ - ret = _MEDobjetIdentifier(fid,MED_MAA,i,nom); - -// EXIT_IF(ret < 0,"Identification d'un maillage",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -// fprintf(stdout," >>> Normalisation du maillage [%s] \n",nom); - - MESSAGE("med File convertor 2.1 to 2.2 :: >>> Normalisation du maillage [" << nom << "]"); - - /* on accede au maillage */ - strcpy(chemin,MED_MAA); - strcat(chemin,nom); - gid = _MEDdatagroupOuvrir(fid,chemin); - -// EXIT_IF(gid < 0,"Accès au maillage",nom); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* lecture de la dimension du maillage */ - ret = _MEDattrEntierLire(gid,MED_NOM_DIM,&dimension); - -// EXIT_IF(ret < 0,"Lecture de la dimension du maillage",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Ecriture du type et de la description */ - ret = _MEDattrStringEcrire(gid,MED_NOM_DES,MED_TAILLE_DESC,description); - -// EXIT_IF(ret < 0,"Ecriture de la description du maillage ",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(gid,MED_NOM_TYP,&type); - -// EXIT_IF(ret < 0,"Ecriture de la dimension du maillage ",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Mise a jour des noeuds du maillage */ - MAJ_noeuds_maillage(gid,dimension); - -// fprintf(stdout," ... Normalisation des noeuds effectuĂ©e ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des noeuds effectuĂ©e ..."); - - /* Mise a jour des Ă©lĂ©ments du maillage */ - MAJ_elements_maillage(gid,dimension); - -// fprintf(stdout," ... Normalisation des Ă©lĂ©ments effectuĂ©e ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des Ă©lĂ©ments effectuĂ©e ..."); - - /* Mise a jour des familles du maillage */ - MAJ_familles_maillage(gid); - -// fprintf(stdout," ... Normalisation des familles effectuĂ©e ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des familles effectuĂ©e ..."); - - /* On ferme tout */ - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture de l'accès au maillage",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -// fprintf(stdout," >>> Normalisation du maillage [%s] ... OK ... \n",nom); - - MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du maillage [" << nom << "] ... OK ... "); - } -} - -void med_2_2::MAJ_localisation_Gauss(med_idt fid,char *nom_modele, - med_int ngauss) - throw (MEDEXCEPTION) -{ - med_err ret; - med_geometrie_element type; - med_float *refcoo, *gaucoo, *poids; - char nom_type[4]; - med_int edim, nsom,n,nlu; - int i; - char nom[MED_TAILLE_NOM+1]; - - /* On regarde si la localisation bidon existe deja - Si oui on s'en va */ - n = MEDnGauss(fid); - if (n > 0) - for (i=1;i<=n;i++) { - ret = MEDgaussInfo(fid,i,nom,&type,&nlu); - if (! strcmp(nom,nom_modele)) return; - } - - /* On deduit le type en fonction de nom_modele */ - strncpy(nom_type,nom_modele,3); - nom_type[3] = '\0'; - if (! strcmp(nom_type,MED_NOM_SE2)) - type = MED_SEG2; - if (! strcmp(nom_type,MED_NOM_SE3)) - type = MED_SEG3; - if (! strcmp(nom_type,MED_NOM_TR3)) - type = MED_TRIA3; - if (! strcmp(nom_type,MED_NOM_TR6)) - type = MED_TRIA6; - if (! strcmp(nom_type,MED_NOM_QU4)) - type = MED_QUAD4; - if (! strcmp(nom_type,MED_NOM_QU8)) - type = MED_QUAD8; - if (! strcmp(nom_type,MED_NOM_TE4)) - type = MED_TETRA4; - if (! strcmp(nom_type,MED_NOM_T10)) - type = MED_TETRA10; - if (! strcmp(nom_type,MED_NOM_HE8)) - type = MED_HEXA8; - if (! strcmp(nom_type,MED_NOM_H20)) - type = MED_HEXA20; - if (! strcmp(nom_type,MED_NOM_PE6)) - type = MED_PENTA6; - if (! strcmp(nom_type,MED_NOM_P15)) - type = MED_PENTA15; - if (! strcmp(nom_type,MED_NOM_PY5)) - type = MED_PYRA5; - if (! strcmp(nom_type,MED_NOM_P13)) - type = MED_PYRA13; - - /* Dimension de la maille */ - edim = type / 100; - nsom = type % 100; - - /* On definit des coordonnĂ©es et des poids bidon */ - refcoo = (med_float*) malloc(sizeof(med_float)*edim*nsom); - -// EXIT_IF(refcoo == NULL,NULL,NULL); - - if(refcoo == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - for (i=0;i<edim*nsom;i++) *(refcoo+i) = 0.; - gaucoo = (med_float*) malloc(sizeof(med_float)*edim*ngauss); - -// EXIT_IF(gaucoo == NULL,NULL,NULL); - - if(gaucoo == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - for (i=0;i<edim*ngauss;i++) *(gaucoo+i) = 0.; - poids = (med_float*) malloc(sizeof(med_float)*ngauss); - -// EXIT_IF(poids == NULL,NULL,NULL); - - if(poids == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - for (i=0;i<ngauss;i++) *(poids+i) = 0.; - - /* On ecrit la localisation bidon */ - ret = MEDgaussEcr(fid,type,refcoo,MED_FULL_INTERLACE,ngauss,gaucoo,poids,nom_modele); - -// EXIT_IF(ret < 0,"Ecriture de la localisation des points de Gauss",nom_modele); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On libere la memoire */ - free(refcoo); - free(gaucoo); - free(poids); -} - -void med_2_2::MAJ_champs(med_idt fid) throw (MEDEXCEPTION) -{ - med_idt gid,eid,pid,mid,did,aid; - med_err ret; - int n,i,j,k; - char nom[MED_TAILLE_NOM+1]; - char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1]; - char maillage[MED_TAILLE_NOM+1]; - med_int type; - char *comp, *unit; - char *nouvelle_chaine; - med_int ncomp; - int nent, npdt; - char noment[MED_TAILLE_NOM+1]; - char nompdt[2*MED_MAX_PARA+1]; - char oldunidt[ANCIEN_MED_TAILLE_PNOM+1]; - char unitdt[MED_TAILLE_PNOM+1]; - char tmp[MED_TAILLE_DESC+1]; - med_int att; - char profil[MED_TAILLE_NOM+1]; - char gauss[MED_TAILLE_NOM+1]; - med_float *valr; - med_int nval; - hid_t hdf_type; - med_size dimd[1]; - med_float pdt; - - /* Lecture du nombre de champs */ - n = 0; - _MEDnObjets(fid,MED_CHA,&n); - -// EXIT_IF(n < 0,"Erreur a la lecture du nombre de champ",NULL); - - if(n < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - for (i=0;i<n;i++) { - /* on recupere le nom du champ */ - ret = _MEDobjetIdentifier(fid,MED_CHA,i,nom); - -// EXIT_IF(ret < 0,"Identification d'un champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -// fprintf(stdout," >>> Normalisation du champ [%s] \n",nom); - - MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du champ [" << nom << "]"); - - /* on accede au champ */ - strcpy(chemin,MED_CHA); - strcat(chemin,nom); - gid = _MEDdatagroupOuvrir(fid,chemin); - -// EXIT_IF(gid < 0,"Accès au champ",nom); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Lecture du nombre de composantes */ - ret = _MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp); - -// EXIT_IF(ret < 0,"Lecture du nombre de composante",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Lecture du type du champ */ - ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&type); - -// EXIT_IF(ret < 0,"Lecture du type du champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Normalisation des nom et unites des composantes */ - comp = (char *) malloc(ncomp*ANCIEN_MED_TAILLE_PNOM+1); - -// EXIT_IF(comp == NULL,NULL,NULL); - - if(comp == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - unit = (char *) malloc(ncomp*ANCIEN_MED_TAILLE_PNOM+1); - -// EXIT_IF(unit == NULL,NULL,NULL); - - if(unit == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - nouvelle_chaine = (char *) malloc(ncomp*MED_TAILLE_PNOM+1); - -// EXIT_IF(nouvelle_chaine == NULL,NULL,NULL); - - if(nouvelle_chaine == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrStringLire(gid,MED_NOM_NOM,ncomp*ANCIEN_MED_TAILLE_PNOM,comp); - -// EXIT_IF(ret < 0,"Lecture des noms des composantes du champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - conversion_chaine(comp,nouvelle_chaine,ncomp); - H5Adelete(gid,MED_NOM_NOM); - ret = _MEDattrStringEcrire(gid,MED_NOM_NOM,MED_TAILLE_PNOM*ncomp,nouvelle_chaine); - -// EXIT_IF(ret < 0,"Ecriture des nouveaux noms des composantes du champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - free(comp); - - ret = _MEDattrStringLire(gid,MED_NOM_UNI,ncomp*ANCIEN_MED_TAILLE_PNOM,unit); - -// EXIT_IF(ret < 0,"Lecture des unitĂ©s des composantes du champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - conversion_chaine(unit,nouvelle_chaine,ncomp); - H5Adelete(gid,MED_NOM_UNI); - ret = _MEDattrStringEcrire(gid,MED_NOM_UNI,MED_TAILLE_PNOM*ncomp,nouvelle_chaine); - -// EXIT_IF(ret < 0,"Ecriture des nouvelles unitĂ©s des composantes du champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - free(unit); - - free(nouvelle_chaine); - -// fprintf(stdout," ... Normalisation des noms et unitĂ©s des composantes effectuĂ©e...\n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation des noms et unitĂ©s des composantes effectuĂ©e..."); - - /* On ajoute le groupe HDF correspondant au maillage */ - /* On recupere le nom du maillage par defaut */ - nent = 0; - _MEDnObjets(gid,"./",&nent); - -// EXIT_IF(nent < 0,"Erreur a la lecture du nombre d'entitĂ© dans un champ",NULL); - - if(nent < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - for (j=0;j<nent;j++) { - /* on recupere le nom du groupe HDF correspondant a l'entite */ - ret = _MEDobjetIdentifier(gid,"./",j,noment); - -// EXIT_IF(ret < 0,"Identification des objets de niveau 1 dans le champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On ouvre le groupe HDF */ - eid = _MEDdatagroupOuvrir(gid,noment); - -// EXIT_IF(eid < 0,"Ouverture du groupe HDF de niveau 1",NULL); - - if(eid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On recupere le nombre de pas de temps */ - npdt = 0; - _MEDnObjets(eid,"./",&npdt); - -// EXIT_IF(nent < 0,"Erreur a la lecture du nombre de pas de temps",NULL); - - if(nent < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On traite chaque pas de temps */ - for (k=0;k<npdt;k++) { - /* On recupere le nom du groupe HDF correspondant au pas de temps */ - ret = _MEDobjetIdentifier(eid,"./",k,nompdt); - -// EXIT_IF(ret < 0,"Identification des objets de niveau 2 dans le champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On ouvre le groupe HDF correspondant au pas de temps */ - pid = _MEDdatagroupOuvrir(eid,nompdt); - -// EXIT_IF(pid < 0,"Ouverture du groupe HDF de niveau 2",NULL); - - if(pid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On lit le pas de temps */ - aid = H5Aopen_name(pid,MED_NOM_PDT); - -// EXIT_IF(aid < 0,"Ouverture de l'attribut HDF MED_NOM_PDT",NULL); - - if(aid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - hdf_type = H5Aget_type(aid); - -// EXIT_IF(hdf_type < 0,"Lecture du type de l'attribut HDF MED_NOM_PDT",NULL); - - if(hdf_type < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Aclose(aid); - -// EXIT_IF(ret < 0,"Fermeture de l'attribut MED_NOM_PDT",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = OLD_MEDattrNumLire(pid,MED_FLOAT64,MED_NOM_PDT,(unsigned char*)(&pdt),hdf_type); - -// EXIT_IF(ret < 0,"Lecture du pas de temps dans MED_NOM_PDT",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - dimd[0] = 1; - /* printf("EGALITE des types : %d \n",H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)); */ - /* printf("Avant conversion : [%f]\n",pdt); */ - if (! H5Tequal(hdf_type,H5T_NATIVE_DOUBLE)) { - ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)(&pdt),NULL,0); - /* printf("Après conversion Ă©ventuelle : [%f] \n",pdt); */ - -// EXIT_IF(ret < 0,"Conversion du pas de temps",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } - H5Tclose(hdf_type); - /* printf("pdt = %f\n",pdt); */ - H5Adelete(pid,MED_NOM_PDT); - ret = _MEDattrFloatEcrire(pid,MED_NOM_PDT,&pdt); - -// EXIT_IF(ret < 0,"Ecriture du nouveau pas de temps",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On met a jour l'unitĂ© du pas de temps : 8 -> 16 caractères - Si on rencontre " " => on ecrit "" - */ - ret = _MEDattrStringLire(pid,MED_NOM_UNI,ANCIEN_MED_TAILLE_PNOM,oldunidt); - -// EXIT_IF(ret < 0,"Lecture de l'unite du pas de temps",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - if (! strcmp(oldunidt,ANCIEN_MED_BLANC_PNOM)) - strcpy(unitdt,""); - else - conversion_chaine(oldunidt,unitdt,1); - H5Adelete(pid,MED_NOM_UNI); - ret = _MEDattrStringEcrire(pid,MED_NOM_UNI,MED_TAILLE_PNOM,unitdt); - -// EXIT_IF(ret < 0,"Ecriture de la nouvelle unitĂ© du pas de temps",NULL); - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On recupere le nom du maillage */ - ret = _MEDattrStringLire(pid,MED_NOM_MAI,MED_TAILLE_NOM,maillage); - -// EXIT_IF(ret < 0,"Lecture du nom du maillage du pas de temps",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On cree le groupe HDF de niveau 3 qui porte le nom du maillage */ - mid = _MEDdatagroupCreer(pid,maillage); - -// EXIT_IF(mid < 0,"Creation du groupe HDF de niveau 3",NULL); - - if(mid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* DĂ©placement de l'attribut MED_NOM_NBR */ - ret = _MEDattrEntierLire(pid,MED_NOM_NBR,&nval); - -// EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_NBR",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Adelete(pid,MED_NOM_NBR); - -// EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_NBR",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(mid,MED_NOM_NBR,&nval); - -// EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NBR au niveau 3",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Deplacement de l'attribut MED_NOM_NGA */ - ret = _MEDattrEntierLire(pid,MED_NOM_NGA,&att); - -// EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_NGA",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Adelete(pid,MED_NOM_NGA); - -// EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_NGA",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(mid,MED_NOM_NGA,&att); - -// EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NGA au niveau 3",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Ecriture de l'attribut MED_NOM_GAU : localisation des points de Gauss */ - if (att < 2) - strcpy(gauss,MED_NOM_BLANC); - else { - /* on prend en compte que les 3 dernières lettres de noment : - Exemple : "MAI.QU4" => gauss="QU4_LocalisationDefaut_MEDIMPORT */ - strcpy(gauss,noment+4); - strcat(gauss,"_LocalisationDefaut_MEDIMPORT"); - /* On ecrit en plus la localisation bidon des points de Gauss */ - MAJ_localisation_Gauss(fid,gauss,att); - } - ret = _MEDattrStringEcrire(mid,MED_NOM_GAU,MED_TAILLE_NOM,gauss); - -// EXIT_IF(ret < 0,"Ecriture de la localisation des points de Gauss",NULL); - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* Deplacement de l'attribut MED_NOM_PFL */ - ret = _MEDattrStringLire(pid,MED_NOM_PFL,MED_TAILLE_NOM,profil); - -// EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_PFL",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Adelete(pid,MED_NOM_PFL); - -// EXIT_IF(ret < 0,"Desctruction de l'attribut MED_NOM_PFL",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrStringEcrire(mid,MED_NOM_PFL,MED_TAILLE_NOM,profil); - -// EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_PFL au niveau 3",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On ferme le groupe HDF de niveau 3 */ - ret = _MEDdatagroupFermer(mid); - -// EXIT_IF(ret < 0,"fermeture du groupe HDF de niveau 3",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* On deplace du niveau 2 -> 3, le dataset MED_NOM_CO - avec si type==MED_FLOAT_64 une conversion au passage */ - strcpy(tmp,maillage); - strcat(tmp,"/"); - strcat(tmp,MED_NOM_CO); - if (type != MED_FLOAT64) { - ret = H5Gmove(pid,MED_NOM_CO,tmp); - -// EXIT_IF(ret < 0,"Transfert du dataset MED_NOM_CO",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } else { - did = _MEDdatasetOuvrir(pid,MED_NOM_CO); - -// EXIT_IF(did < 0,"Ouverture du dataset HDF des valeurs",NULL); - - if(did < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - hdf_type = H5Dget_type(did); - -// EXIT_IF(hdf_type < 0,"Lecture du type HDF de stockage des valeurs",NULL); - - if(hdf_type < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDdatasetFermer(did); - -// EXIT_IF(ret < 0,"Fermeture du dataset HDF des valeurs",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - valr = (med_float *) malloc(sizeof(med_float)*ncomp*nval); - -// EXIT_IF(valr == NULL,NULL,NULL); - - if(valr == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = OLD_MEDdatasetNumLire(pid,MED_NOM_CO,MED_FLOAT64, - MED_FULL_INTERLACE,ncomp,MED_ALL, - 0,NULL,MED_NOPG, - (unsigned char*) valr,hdf_type); - -// EXIT_IF(ret < 0,"Lecture des valeurs du champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - H5Gunlink(pid,MED_NOM_CO); - dimd[0] = ncomp*nval; - ret = H5Tconvert(hdf_type,H5T_NATIVE_DOUBLE,(hsize_t)*dimd,(void *)valr,NULL,0); - -// EXIT_IF(ret < 0,"Conversion des valeurs",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - H5Tclose(hdf_type); - /* On reporte les valeurs dans le groupe HDF TMP */ - ret = _MEDdatasetNumEcrire(pid,tmp,MED_FLOAT64,MED_FULL_INTERLACE, - ncomp,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,MED_NOPG,dimd, - (unsigned char*) valr); - -// EXIT_IF(ret < 0,"Ecriture des valeurs après conversion",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - free(valr); - } - - /* On ferme le groupe HDF de niveau 2*/ - ret = _MEDdatagroupFermer(pid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF de niveau 2",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } - - /* On ferme le groupe HDF */ - ret = _MEDdatagroupFermer(eid); - - // EXIT_IF(ret < 0,"Fermeture du groupe HDF de niveau 1",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - } - -// fprintf(stdout," ... Normalisation de tous les pas de temps effectuĂ©e...\n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: ... Normalisation de tous les pas de temps effectuĂ©e...\n"); - - /* On ferme tout */ - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture de l'accès au champ",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -// fprintf(stdout," >>> Normalisation du champ [%s] : ... OK ... \n",nom); - - MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du champ [" << nom << "] : ... OK ... "); - } -} - -void med_2_2::MAJ_profils(med_idt fid,med_int nprofil) throw (MEDEXCEPTION) -{ - med_err ret; - med_int i; - char nom[MED_TAILLE_NOM+1]; - char chemin[MED_TAILLE_DESC+1]; - med_idt gid; - med_int att; - - for (i=0;i<nprofil;i++) - { - /* on recupere le nom du profil */ - ret = _MEDobjetIdentifier(fid,MED_PROFILS,i,nom); - - // EXIT_IF(ret < 0,"Identification d'un profil",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -// fprintf(stdout," >>> Normalisation du profil [%s] \n",nom); - - MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du profil [" << nom << "] "); - - /* on accede au profil */ - strcpy(chemin,MED_PROFILS); - strcat(chemin,nom); - gid = _MEDdatagroupOuvrir(fid,chemin); - -// EXIT_IF(gid < 0,"Accès au profil",nom); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - - /* On change l'attribut MED_NOM_N => MED_NOM_NBR */ - ret = _MEDattrEntierLire(gid,"N",&att); - -// EXIT_IF(ret < 0,"Lecture de l'attribut MED_NOM_N",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = H5Adelete(gid,"N"); - -// EXIT_IF(ret < 0,"Destruction de l'attribut MED_NOM_N",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - ret = _MEDattrEntierEcrire(gid,MED_NOM_NBR,&att); - -// EXIT_IF(ret < 0,"Ecriture de l'attribut MED_NOM_NBR dans le profil ",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* on ferme le profil */ - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture de l'acces au profil",nom); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - -// fprintf(stdout," >>> Normalisation du profil [%s] effectuĂ©e \n",nom); - - MESSAGE("med File convertor 2.1 to 2.2 :: Normalisation du profil [" << nom << "]"); - } -} - -char * MEDMEM::med2_1_To_med2_2(char * fileNameIn) throw (MEDEXCEPTION) -{ - med_idt fid, gid; - med_err ret; - med_int majeur, mineur, release; -/* char *nom; */ - char *commande; - med_int nprofil; - char chemin_profils[MED_TAILLE_PROFILS+1]; - char chemin_liens[MED_TAILLE_LIENS+1]; - - char * InternalFileNameOut; - - char * envHome = (char *) malloc(sizeof(char)*(strlen("HOME")+1)); - - strcpy(envHome,"HOME"); - - char * envHomeChar = getenv(envHome); - - /* Test du nombre d'argument */ -// EXIT_IF(argc != 2,"Nombre de parametre incorrect",NULL); - - /* Test du format du fichier */ -/* EXIT_IF(MEDformatConforme(argv[1]) < 0, */ -/* "Le fichier n'est pas au format HDF 5 : ", argv[1]); */ - -// EXIT_IF(MEDformatConforme(fileNameIn) < 0, -// "Le fichier n'est pas au format HDF 5 : ", fileNameIn); - - if(MEDformatConforme(fileNameIn) < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check the med File you wanted to mount in memory"); - - /* opening the old file to check the versions (Med File and HDF) */ - - fid = MEDouvrir(fileNameIn,MED_LECTURE); - -/* EXIT_IF(fid < 0,"Ouverture du fichier : ", */ -/* nom); */ - -// EXIT_IF(fid < 0,"Ouverture du fichier : ", -// InternalFileNameOut); - - MESSAGE("med File convertor 2.1 to 2.2 :: opening of the old file id " << fid); - - if(fid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file : openning of the file"); - - /* Verification du numero de version */ - ret = MEDversionLire(fid,&majeur,&mineur,&release); - -// EXIT_IF(ret < 0,"Lecture du numero de version de MED-fichier",NULL); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - if (majeur == 2 && mineur == 2) { -/* fprintf(stdout,"Le fichier %s est dĂ©jĂ  au format V2.2 !!! \n",nom); */ - -// fprintf(stdout,"Le fichier %s est dĂ©jĂ  au format V2.2 !!! \n",InternalFileNameOut); - - MESSAGE("med File convertor 2.1 to 2.2 :: the file " << fileNameIn << " is already a med 2.2 file"); - - ret = MEDfermer(fid); -/* EXIT_IF(ret < 0,"Fermeture du fichier",argv[1]); */ - -// EXIT_IF(ret < 0,"Fermeture du fichier",fileNameIn); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - return fileNameIn ; - } - - ret = MEDfermer(fid); - - /* - we are sure now that the file is an old version one - creation of the directory if it does not existe - */ - - commande = (char *) malloc(sizeof(char)*(strlen("mkdir ")+ - strlen(envHomeChar)+ - strlen("/TMP_Med2_2Files/")+1)); - -// EXIT_IF(commande == NULL,NULL,NULL); - - if(commande == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - strcpy(commande,"ls "); - strcat(commande,envHomeChar); - strcat(commande,"/TMP_Med2_2Files/"); - - int systemReturn = system(commande); - - if (systemReturn != 0) - { - strcpy(commande,"mkdir "); - strcat(commande,envHomeChar); - strcat(commande,"/TMP_Med2_2Files/"); - - systemReturn = system(commande); - } - - free(commande); - - free(envHome); - - string::size_type pos1 = string(fileNameIn).rfind('/'); - string::size_type pos = strlen(fileNameIn); - InternalFileNameOut = (char *) malloc(sizeof(char)*(strlen(envHomeChar)+ - strlen("/TMP_Med2_2Files/") - +strlen(string(fileNameIn,pos1+1,pos-pos1-1).c_str())+1)); - - strcpy(InternalFileNameOut,envHomeChar); - strcat(InternalFileNameOut,"/TMP_Med2_2Files/"); - strcat(InternalFileNameOut,string(fileNameIn,pos1+1,pos-pos1-1).c_str()); - - MESSAGE("med File convertor 2.1 to 2.2 :: " << InternalFileNameOut); - - /* Creation et ouverture du fichier que l'on va convertire au format MED V2.2 */ -/* commande = (char *) malloc(sizeof(char)*(strlen("cp ")+2*strlen(argv[1])+strlen(" ")+strlen("2.2")+1)); */ - - commande = (char *) malloc(sizeof(char)*(strlen("cp -f ") + - strlen(fileNameIn) + strlen(" ") + - strlen(InternalFileNameOut) + - strlen(" ; chmod ug+rw ") + - strlen(InternalFileNameOut) + 1)); - -// EXIT_IF(commande == NULL,NULL,NULL); - - if(commande == NULL) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - -/* nom = (char *) malloc(sizeof(char)*(strlen(argv[1])+strlen("2.2")+1)); */ - -/* nom = (char *) malloc(sizeof(char)*(strlen(fileNameIn)+strlen("2.2")+1)); */ - -/* EXIT_IF(nom == NULL,NULL,NULL); */ -/* strcpy(nom,argv[1]); */ - -/* strcpy(nom,fileNameIn); */ - -/* strcat(nom,"2.2"); */ - -// strcpy(fileNameOut,fileNameIn); - -// strcat(fileNameOut,"2.2"); - - strcpy(commande,"cp -f "); -/* strcat(commande,argv[1]); */ - - strcat(commande,fileNameIn); - - strcat(commande," "); -/* strcat(commande,nom); */ - - strcat(commande,InternalFileNameOut); - - strcat(commande," ; chmod ug+rw "); - - strcat(commande,InternalFileNameOut); - - system(commande); -/* fprintf(stdout,">>> Creation du fichier %s : %s \n",nom,commande); */ - -// fprintf(stdout,">>> Creation du fichier %s : %s \n",InternalFileNameOut,commande); - - MESSAGE("med File convertor 2.1 to 2.2 :: Creation du fichier " << InternalFileNameOut << " with the commande " << commande); - - free(commande); - -/* fid = MEDouvrir(nom,MED_LECTURE_ECRITURE); */ - - fid = MEDouvrir(InternalFileNameOut,MED_LECTURE_ECRITURE); - -/* EXIT_IF(fid < 0,"Ouverture du fichier : ", */ -/* nom); */ - -// EXIT_IF(fid < 0,"Ouverture du fichier : ", -// InternalFileNameOut); - - MESSAGE("med File convertor 2.1 to 2.2 :: opening of the new file id " << fid); - - if(fid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file : openning of the file"); - - /* On avertit qu'on commence la conversion */ - -// fprintf(stdout,">>> Lancement de la normalisation du fichier selon le format MED V2.2 ...\n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Running the convertor fromV 2.1 to V2.2"); - - /* On inhibe le gestionnaire d'erreur HDF5 */ - _MEDmodeErreurVerrouiller(); - - /* Mise a jour du numero de version */ - -// fprintf(stdout,"- Lancement de la mise Ă  jour du numĂ©ro de version ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of the version number"); - - MAJ_version(fid); - -// fprintf(stdout," NumĂ©ro de version : ... OK ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Version number OK ..."); - - /* Mise a jour des maillages : type = MED_NON_STRUCTURE, description, ... */ - -// fprintf(stdout,"- Lancement de la mise Ă  jour des maillages ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of all meshes"); - - MAJ_maillages(fid); - -// fprintf(stdout," Maillage(s) : ... OK ...\n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: meshes are OK...."); - - /* Mise a jour des champs */ - -// fprintf(stdout,"- Lancement de la mise Ă  jour des champs de rĂ©sultats ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Running of the update of all fields .."); - - MAJ_champs(fid); - -// fprintf(stdout," Champs(s) : ... OK ...\n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Fields are OK .."); - - /* Mise a jour des profils eventuels */ - nprofil = MEDnProfil(fid); - if (nprofil > 0) { -// fprintf(stdout,"- Lancement de la mise Ă  jour des profils ... \n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Running the update of all profils"); - - MAJ_profils(fid,nprofil); - -// fprintf(stdout," Profils(s) : ... OK ...\n"); - - MESSAGE("med File convertor 2.1 to 2.2 :: Profils are OK ... "); - } else { - strncpy(chemin_profils,MED_PROFILS,MED_TAILLE_PROFILS-1); - chemin_profils[MED_TAILLE_PROFILS-1] = '\0'; - gid = _MEDdatagroupCreer(fid,chemin_profils); - -// EXIT_IF(gid < 0,"Creation du groupe HDF sur les profils",chemin_profils); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les profils",chemin_profils); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - } - - /* On cree le groupe HDF pour les liens */ - strncpy(chemin_liens,MED_LIENS,MED_TAILLE_LIENS-1); - chemin_liens[MED_TAILLE_LIENS-1] = '\0'; - gid = _MEDdatagroupCreer(fid,chemin_liens); - -// EXIT_IF(gid < 0,"Creation du groupe HDF sur les liens",chemin_liens); - - if(gid < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - ret = _MEDdatagroupFermer(gid); - -// EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les liens",chemin_liens); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - /* Fermeture du fichier */ - ret = MEDfermer(fid); -/* EXIT_IF(ret < 0,"Fermeture du fichier",nom); */ - -// EXIT_IF(ret < 0,"Fermeture du fichier",InternalFileNameOut); - - if(ret < 0) - throw MEDEXCEPTION("Problem in the med File convertor 2.1 to 2.2, you should check you have enough memory and/or space disc to write the new med 2.2 file"); - - /* On avertit que c'est fini */ -/* fprintf(stdout,">>> Conversion du fichier %s au format MED V2.2. terminĂ©e\n", */ -/* nom); */ - -// fprintf(stdout,">>> Conversion du fichier %s au format MED V2.2. terminĂ©e\n", -// InternalFileNameOut); - - /* On libere la memoire */ -/* free(nom); */ - - char * fileNameOut = new char[strlen(InternalFileNameOut)+1]; - - fileNameOut = strcpy(fileNameOut,InternalFileNameOut); - - free(InternalFileNameOut); - - MESSAGE("med File convertor 2.1 to 2.2 :: Convertion of the med file " << fileNameOut << " has run OK"); - return fileNameOut; } diff --git a/src/MEDMEM/MEDMEM_medimport_src.hxx b/src/MEDMEM/MEDMEM_medimport_src.hxx index 825f4cc39..f7876d9f7 100644 --- a/src/MEDMEM/MEDMEM_medimport_src.hxx +++ b/src/MEDMEM/MEDMEM_medimport_src.hxx @@ -37,268 +37,25 @@ #ifndef IMPORT_HXX #define IMPORT_HXX -#include "MEDMEM_Utilities.hxx" -#include "MEDMEM_STRING.hxx" -#include "MEDMEM_Exception.hxx" -// #include "MEDMEM_define.hxx" - +#include <MEDMEM.hxx> -/* - Med File V 2.2 attributes in the med_2_2 namespace -*/ +#include "MEDimport.hxx" + +#include "MEDMEM_Exception.hxx" #undef MED_H -namespace med_2_2 { - extern "C" { -#include <med.h> -#include <med_proto.h> -#include <med_hdfi.h> - - /* - Med File V 2.2 attributes more addings to encapsulate the Med File V2_2 - medimport utilitary - */ - -#define MED_NOM_INFOS "INFOS_GENERALES" -#define MED_NOM_MAJEUR "MAJ" -#define MED_NOM_MINEUR "MIN" -#define MED_NOM_RELEASE "REL" -#define MED_NOM_NOE "NOE" -#define MED_NOM_NBR "NBR" -#define MED_NOM_REP "REP" -#define MED_NOM_NOM "NOM" -#define MED_NOM_UNI "UNI" -#define MED_NOM_COO "COO" -#define MED_TAILLE_NOM_ENTITE 3 -#define MED_NOM_MAI "MAI" -#define MED_NOM_NOD "NOD" -#define MED_TAILLE_FAS 5 -#define MED_NOM_NUM "NUM" -#define MED_TAILLE_MAA 9 -#define MED_MAA "/ENS_MAA/" -#define MED_NOM_DIM "DIM" -#define MED_NOM_DES "DES" -#define MED_NOM_TYP "TYP" -#define MED_NOM_PO1 "PO1" -#define MED_NOM_SE2 "SE2" -#define MED_NOM_SE3 "SE3" -#define MED_NOM_TR3 "TR3" -#define MED_NOM_TR6 "TR6" -#define MED_NOM_QU4 "QU4" -#define MED_NOM_QU8 "QU8" -#define MED_NOM_TE4 "TE4" -#define MED_NOM_T10 "T10" -#define MED_NOM_HE8 "HE8" -#define MED_NOM_H20 "H20" -#define MED_NOM_PE6 "PE6" -#define MED_NOM_P15 "P15" -#define MED_NOM_PY5 "PY5" -#define MED_NOM_P13 "P13" -#define MED_CHA "/CHA/" -#define MED_TAILLE_CHA 5 -#define MED_NOM_NCO "NCO" -#define MED_NOM_PDT "PDT" -#define MED_NOM_NGA "NGA" -#define MED_NOM_GAU "GAU" -#define MED_NOM_PFL "PFL" -#define MED_NOM_CO "CO" -#define MED_PROFILS "/PROFILS/" -#define MED_TAILLE_PROFILS 9 -#define MED_LIENS "/LIENS/" -#define MED_TAILLE_LIENS 7 - } -} - -// namespace med_2_2 { -// extern "C" { -// #include <med_hdfi.h> -// #include <med_misc.h> - -// #define MED_NOM_MAJEUR "MAJ" -// #define MED_NOM_MINEUR "MIN" -// #define MED_NOM_RELEASE "REL" - -// #define MED_NUM_MAJEUR 2 -// #define MED_NUM_MINEUR 2 -// #define MED_NUM_RELEASE 1 - -// #define MED_NOM_INFOS "INFOS_GENERALES" - -// #define MED_NOM_DESCRIPTEUR "descripteur de fichier" -// #define MED_VERSION_ACTUELLE "2.2.1" -// #define HDF_VERSION_ACTUELLE "5-1.4.4" - -// /* Noms des data sets ou attributs correspondant a des entites MED */ -// #define MED_TAILLE_NOM_ENTITE 3 -// #define MED_NOM_NUM "NUM" -// #define MED_NOM_NBR "NBR" -// #define MED_NOM_NOM "NOM" -// #define MED_NOM_UNV "UNV" -// #define MED_NOM_NNS "NNS" -// #define MED_NOM_NNM "NNM" -// #define MED_NOM_NNI "NNI" -// #define MED_NOM_GRO "GRO" -// #define MED_NOM_ATT "ATT" -// #define MED_NOM_NCO "NCO" -// #define MED_NOM_DIM "DIM" -// #define MED_NOM_ESP "ESP" -// #define MED_NOM_FAM "FAM" -// #define MED_NOM_IDE "IDE" -// #define MED_NOM_VAL "VAL" -// #define MED_NOM_DES "DES" -// #define MED_NOM_COR "COR" -// #define MED_NOM_DIM "DIM" -// #define MED_NOM_NOE "NOE" -// #define MED_NOM_COO "COO" -// #define MED_NOM_IN1 "IN1" -// #define MED_NOM_IN2 "IN2" -// #define MED_NOM_IN3 "IN3" -// #define MED_NOM_REP "REP" -// #define MED_NOM_UNI "UNI" -// #define MED_NOM_NOD "NOD" -// #define MED_NOM_TYP "TYP" -// #define MED_NOM_GTY "GTY" -// #define MED_NOM_CO "CO" -// #define MED_NOM_NCW "NCW" -// #define MED_NOM_TYW "TYW" - -// #define MED_NOM_MAI "MAI" -// #define MED_NOM_FAC "FAC" -// #define MED_NOM_ARE "ARE" - -// #define MED_NOM_PO1 "PO1" -// #define MED_NOM_SE2 "SE2" -// #define MED_NOM_SE3 "SE3" -// #define MED_NOM_TR3 "TR3" -// #define MED_NOM_TR6 "TR6" -// #define MED_NOM_QU4 "QU4" -// #define MED_NOM_QU8 "QU8" -// #define MED_NOM_TE4 "TE4" -// #define MED_NOM_T10 "T10" -// #define MED_NOM_HE8 "HE8" -// #define MED_NOM_H20 "H20" -// #define MED_NOM_PE6 "PE6" -// #define MED_NOM_P15 "P15" -// #define MED_NOM_PY5 "PY5" -// #define MED_NOM_P13 "P13" - -// #define MED_NOM_TAI "TAI" -// #define MED_NOM_TTI "TTI" -// #define MED_NOM_IFN "IFN" -// #define MED_NOM_IFD "IFD" -// #define MED_NOM_INN "INN" -// #define MED_NOM_IND "IND" -// #define MED_NOM_POG "POG" -// #define MED_NOM_POE "POE" - -// #define MED_NOM_GEO "GEO" -// #define MED_NOM_GAU "GAU" -// #define MED_NOM_NGA "NGA" -// #define MED_NOM_PFL "PFL" -// #define MED_NOM_NDT "NDT" -// #define MED_NOM_PDT "PDT" -// #define MED_NOM_NOR "NOR" -// #define MED_NOM_LIE "LIE" - -// /* Nom du DATA GROUP CONTENANT TOUS LES MAILLAGES DU FICHIER HDF */ -// #define MED_MAA "/ENS_MAA/" -// #define MED_TAILLE_MAA 9 - -// /* Nom du data group ou ranger les champs solution */ -// #define MED_CHA "/CHA/" -// #define MED_TAILLE_CHA 5 - -// /* Nom du data group point de montage */ -// #define MED_MNT "/MNT/" -// #define MED_TAILLE_MNT 5 - -// /* Nom du data group ou ranger les familles */ -// #define FAMILLE_ZERO "FAMILLE_ZERO" -// #define MED_FAS "/FAS/" -// #define MED_TAILLE_FAS 5 -// #define MED_FAS_NOEUD "/NOEUD/" -// #define MED_FAS_NOEUD_NOM "NOEUD" -// #define MED_FAS_ELEME "/ELEME/" -// #define MED_FAS_ELEME_NOM "ELEME" -// #define MED_TAILLE_FAS_ENTITE 7 - - -// /* Nom du data group ou ranger les equivalences */ -// #define MED_EQS "/EQS/" -// #define MED_TAILLE_EQS 5 - -// /* Nom du data group contenant les profils */ -// #define MED_PROFILS "/PROFILS/" -// #define MED_TAILLE_PROFILS 9 - -// /* Nom du data group contenant la localisation des points de GAUSS */ -// #define MED_GAUSS "/GAUSS/" -// #define MED_TAILLE_GAUSS 7 - -// /* Nom du groupe HDF ou sont rangees les valeurs numeriques scalaires -// non liees au modele de donnees -// */ -// #define MED_NUM_DATA "/NUM_DATA/" -// #define MED_TAILLE_NUM_DATA 10 - -// /* Nom du data group contenant les liens */ -// #define MED_LIENS "/LIENS/" -// #define MED_TAILLE_LIENS 7 - -// } -// } - -#include <stdio.h> -#include <string.h> - -#define ANCIEN_MED_TAILLE_PNOM 8 -/* 12345678 */ -#define ANCIEN_MED_BLANC_PNOM " " - -namespace med_2_2 { - -med_err OLD_MEDattrNumLire(med_idt pere, med_type_champ type, char *nom, - unsigned char *val, hid_t hdf_file); - -med_err OLD_MEDdatasetNumLire(med_idt pere, char *nom, med_type_champ type, - med_mode_switch interlace, med_size nbdim, - med_size fixdim, med_size psize, - med_ssize * pfltab, med_int ngauss, - unsigned char *val,hid_t hdf_file); - -void conversion_chaine(char *ancienne_chaine, char *nouvelle_chaine, - med_int n); - -void MAJ_version(med_idt fid) throw (MEDMEM::MEDEXCEPTION) ; - -void MAJ_noeuds_maillage(med_idt mid, med_int dimension) throw (MEDMEM::MEDEXCEPTION) ; - -void MAJ_elements_maillage(med_idt mid, med_int dimension) - throw (MEDMEM::MEDEXCEPTION); - -void MAJ_familles_maillage(med_idt mid) throw (MEDMEM::MEDEXCEPTION) ; - -void MAJ_maillages(med_idt fid) throw (MEDMEM::MEDEXCEPTION) ; - -void MAJ_localisation_Gauss(med_idt fid,char *nom_modele,med_int ngauss) - throw (MEDMEM::MEDEXCEPTION) ; - -void MAJ_champs(med_idt fid) throw (MEDMEM::MEDEXCEPTION) ; - -void MAJ_profils(med_idt fid,med_int nprofil) throw (MEDMEM::MEDEXCEPTION) ; -} - namespace MEDMEM { /*! - This method is supposed to be the same as the med File V2.2 medimport + This method is supposed to be the same as the med File V2.3 medimport utility. fileNameIn is .med V2.1 file supplied by the user including - all the directory path. fileNameOut is .med V2.2 file produced by this - command in the directory $HOME/TMP_Med2_2Files/ + all the directory path. fileNameOut is .med V2.3.3 file produced by this + command (same name + 2.3). */ -char * med2_1_To_med2_2(char * fileNameIn) throw (MEDMEM::MEDEXCEPTION) ; +MEDMEM_EXPORT char * med2_1_To_med2_3(char * fileNameIn) throw (MEDMEM::MEDEXCEPTION) ; } #endif /* IMPORT_HXX */ + diff --git a/src/MEDMEM/MEDMEM_nArray.hxx b/src/MEDMEM/MEDMEM_nArray.hxx index 01a6c9b88..6df981e70 100644 --- a/src/MEDMEM/MEDMEM_nArray.hxx +++ b/src/MEDMEM/MEDMEM_nArray.hxx @@ -19,6 +19,8 @@ #ifndef MEDMEM_ARRAY_HXX #define MEDMEM_ARRAY_HXX +#include "MEDMEM.hxx" + #include "MEDMEM_InterlacingPolicy.hxx" #include "MEDMEM_IndexCheckingPolicy.hxx" @@ -27,7 +29,7 @@ namespace MEDMEM { -class MEDMEM_Array_ { +class MEDMEM_EXPORT MEDMEM_Array_ { public: //virtual void dummy() {}; virtual bool getGaussPresence() const { return false; } @@ -63,6 +65,18 @@ public : _array.set(InterlacingPolicy::_arraySize); }; + // Le mot clĂ© inline permettra d'instancier le constructeur uniquement + // s'il est appelĂ© NoInterlaceByTypeNoGaussPolicy(...) + // Rem : Le constructeur de la policy demandĂ©e est appelĂ© + inline MEDMEM_Array(int dim, int nbelem, + int nbtypegeo, const int * const nbelgeoc) + : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc) + { + CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem); + CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim); + _array.set(InterlacingPolicy::_arraySize); + }; + // Le mot clĂ© inline permettra d'instancier le constructeur uniquement // s'il est appelĂ© ( ...NoGaussPolicy) // Rem : Le constructeur de la policy demandĂ©e est appelĂ© @@ -84,6 +98,29 @@ public : } + // Le mot clĂ© inline permettra d'instancier le constructeur uniquement + // s'il est appelĂ© NoInterlaceByTypeNoGaussPolicy(...) + // Rem : Le constructeur de la policy demandĂ©e est appelĂ© + inline MEDMEM_Array( ElementType * values, int dim, int nbelem, + int nbtypegeo, const int * const nbelgeoc, + bool shallowCopy=false, + bool ownershipOfValues=false) + : InterlacingPolicy(nbelem, dim, nbtypegeo, nbelgeoc) + { + CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",nbelem); + CHECKING_POLICY::checkMoreThanZero("MEDMEM_Array",dim); + if(shallowCopy) + + if(ownershipOfValues) + _array.setShallowAndOwnership((const ElementType *)values); + else + _array.set((const ElementType*)values); + + else // Cas par dĂ©faut + _array.set(InterlacingPolicy::_arraySize,values); + + } + // Le mot clĂ© inline permettra d'instancier le constructeur uniquement // s'il est appelĂ© ( ...GaussPolicy) // Rem : Le constructeur de la policy demandĂ©e est appelĂ© @@ -227,6 +264,41 @@ public : return _array[ InterlacingPolicy::getIndex(i,j,k) ]; }; + inline const ElementType & getIJByType(int i, int j, int t) const { + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType())); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t); + if ( InterlacingPolicy::getGaussPresence() ) + return _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,t) ]; + else + return _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,t) ]; + } + + inline const ElementType & getIJKByType(int i, int j, int k, int t) const { + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType())); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j); + + if ( InterlacingPolicy::getGaussPresence() ) { + // not compilable on Debian40 +// checkInInclusiveRange("MEDMEM_Array", +// 1,((NoInterlaceByTypeGaussPolicy*)this)->getNbGaussByType(t),k); + int kmax = ((NoInterlaceByTypeGaussPolicy*)this)->getNbGaussByType(t); + if ( k < 1 || k > kmax ) + throw MEDEXCEPTION(LOCALIZED(STRING("MEDMEM_Array::getIJKByType(), ") + << " k : " << k << " not in rang [1," << kmax <<"]")); + return _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,k,t) ]; + } + else { + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k); + return _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,k,t) ]; + } + }; + inline void setIJ(int i, int j, const ElementType & value) { //autre signature avec checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i); checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j); @@ -234,6 +306,19 @@ public : _array[ InterlacingPolicy::getIndex(i,j) ] = value; // retour ElementType & ? }; + inline void setIJByType(int i, int j, int t, const ElementType & value) { //autre signature avec + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType())); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t); + + if ( InterlacingPolicy::getGaussPresence() ) + _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,t) ] = value; + else + _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,t) ] = value; + }; + inline void setIJK(int i, int j, int k, const ElementType & value) { //autre signature avec checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i); checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j); @@ -242,6 +327,29 @@ public : _array[ InterlacingPolicy::getIndex(i,j,k) ] = value; // retour ElementType & ? }; + inline void setIJKByType(int i, int j, int k, int t, const ElementType & value) { //autre signature avec + if ( getInterlacingType() != MED_EN::MED_NO_INTERLACE_BY_TYPE ) + throw MEDEXCEPTION(LOCALIZED(STRING("Wrong interlacing type ") << getInterlacingType())); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_nbelem,i); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::_dim,j); + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGeoType(),t); + + if ( InterlacingPolicy::getGaussPresence() ) { + // not compilable on Debian40 +// checkInInclusiveRange("MEDMEM_Array", +// 1,((NoInterlaceByTypeGaussPolicy*)this)->getNbGaussByType(t),k); + int kmax = ((NoInterlaceByTypeGaussPolicy*)this)->getNbGaussByType(t); + if ( k < 1 || k > kmax ) + throw MEDEXCEPTION(LOCALIZED(STRING("MEDMEM_Array::getIJKByType(), ") + << " k : " << k << " not in rang [1," << kmax <<"]")); + _array[ ((NoInterlaceByTypeGaussPolicy*)this)->getIndexByType(i,j,k,t) ] = value; + } + else { + checkInInclusiveRange("MEDMEM_Array",1,InterlacingPolicy::getNbGauss(i),k); + _array[ ((NoInterlaceByTypeNoGaussPolicy*)this)->getIndexByType(i,j,k,t) ] = value; + } + }; + bool operator == (const MEDMEM_Array & array ) const { if ( this == &array ) return true; diff --git a/src/MEDMEM/Makefile.am b/src/MEDMEM/Makefile.am new file mode 100644 index 000000000..3dea27feb --- /dev/null +++ b/src/MEDMEM/Makefile.am @@ -0,0 +1,232 @@ +# MED MEDMEM : MED files in memory +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# first '.' says that this folder must be compiled before Test (MEDMEM/Test uses MEDMEM) +if CPPUNIT_IS_OK + SUBDIRS=. Test +endif + +DIST_SUBDIRS= Test + +lib_LTLIBRARIES= libmedmem.la + +salomeinclude_HEADERS= \ +MEDMEM_PointerOf.hxx \ +MEDMEM_CellModel.hxx \ +MEDMEM_Connectivity.hxx \ +MEDMEM_Coordinate.hxx \ +MEDMEM_define.hxx \ +MEDMEM_DriversDef.hxx \ +MEDMEM_DriverFactory.hxx \ +MEDMEM_Family.hxx \ +MEDMEM_Field.hxx \ +MEDMEM_GenDriver.hxx \ +MEDMEM_Group.hxx \ +MEDMEM_Array.hxx \ +MEDMEM_Exception.hxx \ +MEDMEM_MedFieldDriver.hxx \ +MEDMEM_AsciiFieldDriver.hxx \ +MEDMEM_Med.hxx \ +MEDMEM_MedMedDriver.hxx \ +MEDMEM_MedMeshDriver.hxx \ +MEDMEM_GibiMeshDriver.hxx \ +MEDMEM_PorflowMeshDriver.hxx \ +MEDMEM_DriverTools.hxx \ +MEDMEM_ModulusArray.hxx \ +MEDMEM_SkyLineArray.hxx \ +MEDMEM_VtkMedDriver.hxx \ +MEDMEM_VtkMeshDriver.hxx \ +MEDMEM_VtkFieldDriver.hxx \ +MEDMEM_Mesh.hxx \ +MEDMEM_Meshing.hxx \ +MEDMEM_STRING.hxx \ +MEDMEM_Support.hxx \ +MEDMEM_Unit.hxx \ +MEDMEM_Grid.hxx \ +MEDMEM_RCBase.hxx \ +MEDMEM_medimport_src.hxx \ +MEDMEM_MedVersion.hxx \ +MEDMEM_Compatibility21_22.hxx \ +MEDMEM_MedFieldDriver21.hxx \ +MEDMEM_MedMeshDriver21.hxx \ +MEDMEM_MedMedDriver21.hxx \ +MEDMEM_PolyhedronArray.hxx \ +MEDMEM_MedFieldDriver22.hxx \ +MEDMEM_MedMedDriver22.hxx \ +MEDMEM_MedMeshDriver22.hxx \ +MEDMEM_TopLevel.hxx \ +MEDMEM_Utilities.hxx \ +MEDMEM_ArrayInterface.hxx \ +MEDMEM_IndexCheckingPolicy.hxx \ +MEDMEM_InterlacingPolicy.hxx \ +MEDMEM_InterlacingTraits.hxx \ +MEDMEM_nArray.hxx \ +MEDMEM_Tags.hxx \ +MEDMEM_FieldConvert.hxx \ +MEDMEM_ArrayConvert.hxx \ +MEDMEM_FieldForward.hxx \ +MEDMEM_GaussLocalization.hxx \ +MEDMEM_SetInterlacingType.hxx\ +MEDMEM_ConnectZone.hxx \ +MEDMEM_EnsightMedDriver.hxx \ +MEDMEM_EnsightMeshDriver.hxx \ +MEDMEM_EnsightFieldDriver.hxx \ +MEDMEM.hxx + +# not exported headers +EXTRA_DIST+= DataTest \ +MEDMEM_MEDMEMchampLire.hxx \ +MEDMEM_MEDMEMgaussEcr.hxx \ +MEDMEM_MEDMEMprofilEcr.hxx \ +MEDMEM_Formulae.hxx + +dist_libmedmem_la_SOURCES= \ +MEDMEM_Init.cxx \ +MEDMEM_CellModel.cxx \ +MEDMEM_Connectivity.cxx \ +MEDMEM_Coordinate.cxx \ +MEDMEM_DriversDef.cxx \ +MEDMEM_DriverFactory.cxx \ +MEDMEM_Family.cxx \ +MEDMEM_Field.cxx \ +MEDMEM_GenDriver.cxx \ +MEDMEM_Group.cxx \ +MEDMEM_Med.cxx \ +MEDMEM_Exception.cxx \ +MEDMEM_MedMedDriver.cxx \ +MEDMEM_MedMeshDriver.cxx \ +MEDMEM_GibiMeshDriver.cxx \ +MEDMEM_PorflowMeshDriver.cxx \ +MEDMEM_DriverTools.cxx \ +MEDMEM_SkyLineArray.cxx \ +MEDMEM_Mesh.cxx \ +MEDMEM_Meshing.cxx \ +MEDMEM_Support.cxx \ +MEDMEM_Unit.cxx \ +MEDMEM_VtkMedDriver.cxx \ +MEDMEM_VtkMeshDriver.cxx \ +MEDMEM_Grid.cxx \ +MEDMEM_MedVersion.cxx \ +MEDMEM_MedMeshDriver21.cxx \ +MEDMEM_MedMedDriver21.cxx \ +MEDMEM_medimport_src.cxx \ +MEDMEM_PolyhedronArray.cxx \ +MEDMEM_MedMedDriver22.cxx \ +MEDMEM_MedMeshDriver22.cxx \ +MEDMEM_TopLevel.cxx \ +MEDMEM_ConnectZone.cxx \ +MEDMEM_EnsightMedDriver.cxx \ +MEDMEM_EnsightMeshDriver.cxx \ +MEDMEM_GaussLocalization.cxx + +#libmedmem_la_LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome +libmedmem_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ + -I$(srcdir)/../MEDWrapper/Base \ + -I$(srcdir)/../MEDWrapper/V2_1/Core -I$(srcdir)/../INTERPOLATION + +# change motivated by the bug KERNEL4778. +libmedmem_la_LDFLAGS=$(MED2_LIBS) $(HDF5_LIBS) ../MEDWrapper/V2_1/Core/libmed_V2_1.la \ + ../MEDWrapper/Base/libMEDWrapperBase.la $(STDLIB) +if MED_ENABLE_KERNEL + libmedmem_la_CPPFLAGS+= ${KERNEL_CXXFLAGS} + libmedmem_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace +endif + +bin_PROGRAMS= \ + ensight2med med2ensight \ + med2_1_To_med2_2 med2vtk duplicateMED med_test duplicateMEDMESH test_write_groups_poly\ + test_MEDMEM_ModulusArray test_MEDMEM_Array test_MEDMEM_SkyLineArray \ + test_MEDMEM_CellModel testUPointerOf testUCoordinate testUUnit \ + testUGeoNameMeshEntities testUMedException testUModulusArray \ + testUSkyLineArray testUArray testUCellModel readEntete readCoordinate \ + test_copie_field_ test_copie_fieldT test_copie_coordinate \ + test_copie_medarray test_copie_connectivity test_copie_support \ + test_copie_family test_copie_group test_copie_mesh test_affect_medarray \ + test_MEDMEM_Meshing test_MEDMEM_MeshingPoly test_operation_fielddouble \ + test_operation_fieldint test_gibi_driver test_porflow_driver \ + test_grid test_MEDMEM_PolyhedronArray test_MEDMEM_PolyConnectivity \ + test_MEDMEM_PolyDriverMedMeshRead test_MEDMEM_PolyDriverMedMeshWrite \ + test_MEDMEM_poly3D test_MEDMEM_nArray test_MEDMEM_Meshing_poly test_profil_MedFieldDriver \ + test_profil_gauss_MedFieldDriver test_GaussLocalization testAnalFile test_MEDMEM_MeshingFlica \ + create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_mesh_c3h8q4_wrong \ + create_mesh_c2q4s2_wrong create_grid create_mesh_c2q4 create_mesh_c3h8 create_poly3D + +AM_CPPFLAGS= $(libmedmem_la_CPPFLAGS) +LDADD= $(libmedmem_la_LDFLAGS) -lm libmedmem.la +if MED_ENABLE_KERNEL + LDADD+=-lSALOMEBasics +endif + +dist_ensight2med_SOURCES= ensight2med.cxx +dist_med2ensight_SOURCES= med2ensight.cxx +dist_med2_1_To_med2_2_SOURCES= med2_1_To_med2_2.cxx +dist_med2vtk_SOURCES= med2vtk.cxx +dist_duplicateMED_SOURCES= duplicateMED.cxx +dist_med_test_SOURCES= med_test.cxx +dist_duplicateMEDMESH_SOURCES= duplicateMEDMESH.cxx +dist_test_write_groups_poly_SOURCES= test_write_groups_poly.cxx +dist_test_MEDMEM_ModulusArray_SOURCES= test_MEDMEM_ModulusArray.cxx +dist_test_MEDMEM_Array_SOURCES= test_MEDMEM_Array.cxx +dist_test_MEDMEM_SkyLineArray_SOURCES= test_MEDMEM_SkyLineArray.cxx +dist_test_MEDMEM_CellModel_SOURCES= test_MEDMEM_CellModel.cxx +dist_testUPointerOf_SOURCES= tests/testUPointerOf.cxx +dist_testUCoordinate_SOURCES= tests/testUCoordinate.cxx +dist_testUUnit_SOURCES= tests/testUUnit.cxx +dist_testUGeoNameMeshEntities_SOURCES= tests/testUGeoNameMeshEntities.cxx +dist_testUMedException_SOURCES= tests/testUMedException.cxx +dist_testUModulusArray_SOURCES= tests/testUModulusArray.cxx +dist_testUSkyLineArray_SOURCES= tests/testUSkyLineArray.cxx +dist_testUArray_SOURCES= tests/testUArray.cxx +dist_testUCellModel_SOURCES= tests/testUCellModel.cxx +dist_readEntete_SOURCES= tests/readEntete.cxx +dist_readCoordinate_SOURCES= tests/readCoordinate.cxx +dist_test_copie_field__SOURCES= test_copie_field_.cxx +dist_test_copie_fieldT_SOURCES= test_copie_fieldT.cxx +dist_test_copie_coordinate_SOURCES= test_copie_coordinate.cxx +dist_test_copie_medarray_SOURCES= test_copie_medarray.cxx +dist_test_copie_connectivity_SOURCES= test_copie_connectivity.cxx +dist_test_copie_support_SOURCES= test_copie_support.cxx +dist_test_copie_family_SOURCES= test_copie_family.cxx +dist_test_copie_group_SOURCES= test_copie_group.cxx +dist_test_copie_mesh_SOURCES= test_copie_mesh.cxx +dist_test_affect_medarray_SOURCES= test_affect_medarray.cxx +dist_test_MEDMEM_Meshing_SOURCES= test_MEDMEM_Meshing.cxx +dist_test_MEDMEM_MeshingPoly_SOURCES= test_MEDMEM_MeshingPoly.cxx +dist_test_operation_fielddouble_SOURCES= test_operation_fielddouble.cxx +dist_test_operation_fieldint_SOURCES= test_operation_fieldint.cxx +dist_test_gibi_driver_SOURCES= test_gibi_driver.cxx +dist_test_porflow_driver_SOURCES= test_porflow_driver.cxx +dist_test_grid_SOURCES= test_grid.cxx +dist_test_MEDMEM_PolyhedronArray_SOURCES= test_MEDMEM_PolyhedronArray.cxx +dist_test_MEDMEM_PolyConnectivity_SOURCES= test_MEDMEM_PolyConnectivity.cxx +dist_test_MEDMEM_PolyDriverMedMeshRead_SOURCES= test_MEDMEM_PolyDriverMedMeshRead.cxx +dist_test_MEDMEM_PolyDriverMedMeshWrite_SOURCES= test_MEDMEM_PolyDriverMedMeshWrite.cxx +dist_test_MEDMEM_poly3D_SOURCES= test_MEDMEM_poly3D.cxx +dist_test_MEDMEM_nArray_SOURCES= test_MEDMEM_nArray.cxx +dist_test_MEDMEM_Meshing_poly_SOURCES= test_MEDMEM_Meshing_poly.cxx +dist_test_profil_MedFieldDriver_SOURCES= test_profil_MedFieldDriver.cxx +dist_test_profil_gauss_MedFieldDriver_SOURCES= test_profil_gauss_MedFieldDriver.cxx +dist_test_GaussLocalization_SOURCES= test_GaussLocalization.cxx +dist_testAnalFile_SOURCES= testAnalFile.cxx +dist_test_MEDMEM_MeshingFlica_SOURCES= test_MEDMEM_MeshingFlica.cxx diff --git a/src/MEDMEM/Makefile.in b/src/MEDMEM/Makefile.in deleted file mode 100644 index 70c5cb418..000000000 --- a/src/MEDMEM/Makefile.in +++ /dev/null @@ -1,196 +0,0 @@ -# MED MEDMEM : MED files in memory -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Patrick GOLDBRONN (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir):$(srcdir)/tests - -MACHINE=PCLINUX - -@COMMENCE@ - - -EXPORT_PYSCRIPTS = \ - - -EXPORT_HEADERS = \ -MEDMEM_PointerOf.hxx \ -MEDMEM_CellModel.hxx \ -MEDMEM_Connectivity.hxx \ -MEDMEM_Coordinate.hxx \ -MEDMEM_define.hxx \ -MEDMEM_DriversDef.hxx \ -MEDMEM_DriverFactory.hxx \ -MEDMEM_Family.hxx \ -MEDMEM_Field.hxx \ -MEDMEM_GenDriver.hxx \ -MEDMEM_Group.hxx \ -MEDMEM_Array.hxx \ -MEDMEM_Exception.hxx \ -MEDMEM_MedFieldDriver.hxx \ -MEDMEM_AsciiFieldDriver.hxx \ -MEDMEM_Med.hxx \ -MEDMEM_MedMedDriver.hxx \ -MEDMEM_MedMeshDriver.hxx \ -MEDMEM_GibiMeshDriver.hxx \ -MEDMEM_PorflowMeshDriver.hxx \ -MEDMEM_DriverTools.hxx \ -MEDMEM_ModulusArray.hxx \ -MEDMEM_SkyLineArray.hxx \ -MEDMEM_VtkMedDriver.hxx \ -MEDMEM_VtkMeshDriver.hxx \ -MEDMEM_VtkFieldDriver.hxx \ -MEDMEM_Mesh.hxx \ -MEDMEM_Meshing.hxx \ -MEDMEM_STRING.hxx \ -MEDMEM_Support.hxx \ -MEDMEM_Unit.hxx \ -MEDMEM_Grid.hxx \ -MEDMEM_RCBase.hxx \ -MEDMEM_medimport_src.hxx \ -MEDMEM_MedVersion.hxx \ -MEDMEM_Compatibility21_22.hxx \ -MEDMEM_MedFieldDriver21.hxx \ -MEDMEM_MedMeshDriver21.hxx \ -MEDMEM_MedMedDriver21.hxx \ -MEDMEM_PolyhedronArray.hxx \ -MEDMEM_MedFieldDriver22.hxx \ -MEDMEM_MedMedDriver22.hxx \ -MEDMEM_MedMeshDriver22.hxx \ -MEDMEM_TopLevel.hxx \ -MEDMEM_Utilities.hxx \ -MEDMEM_ArrayInterface.hxx \ -MEDMEM_IndexCheckingPolicy.hxx \ -MEDMEM_InterlacingPolicy.hxx \ -MEDMEM_InterlacingTraits.hxx \ -MEDMEM_nArray.hxx \ -MEDMEM_Tags.hxx \ -MEDMEM_FieldConvert.hxx \ -MEDMEM_ArrayConvert.hxx \ -MEDMEM_FieldForward.hxx \ -MEDMEM_GaussLocalization.hxx \ -MEDMEM_MEDMEMgaussEcr.hxx \ -MEDMEM_MEDMEMprofilEcr.hxx \ -MEDMEM_MEDMEMchampLire.hxx \ -MEDMEM_SetInterlacingType.hxx - -# Libraries targets - -LIB=libmedmem.la - -LIB_SRC = \ -MEDMEM_Init.cxx \ -MEDMEM_CellModel.cxx \ -MEDMEM_Connectivity.cxx \ -MEDMEM_Coordinate.cxx \ -MEDMEM_DriversDef.cxx \ -MEDMEM_DriverFactory.cxx \ -MEDMEM_Family.cxx \ -MEDMEM_Field.cxx \ -MEDMEM_GenDriver.cxx \ -MEDMEM_Group.cxx \ -MEDMEM_Med.cxx \ -MEDMEM_Exception.cxx \ -MEDMEM_MedMedDriver.cxx \ -MEDMEM_MedMeshDriver.cxx \ -MEDMEM_GibiMeshDriver.cxx \ -MEDMEM_PorflowMeshDriver.cxx \ -MEDMEM_DriverTools.cxx \ -MEDMEM_SkyLineArray.cxx \ -MEDMEM_Mesh.cxx \ -MEDMEM_Meshing.cxx \ -MEDMEM_Support.cxx \ -MEDMEM_Unit.cxx \ -MEDMEM_VtkMedDriver.cxx \ -MEDMEM_VtkMeshDriver.cxx \ -MEDMEM_Grid.cxx \ -MEDMEM_MedVersion.cxx \ -MEDMEM_MedMeshDriver21.cxx \ -MEDMEM_MedMedDriver21.cxx \ -MEDMEM_medimport_src.cxx \ -MEDMEM_PolyhedronArray.cxx \ -MEDMEM_MedMedDriver22.cxx \ -MEDMEM_MedMeshDriver22.cxx \ -MEDMEM_TopLevel.cxx \ -MEDMEM_MEDMEMgaussEcr.cxx \ -MEDMEM_MEDMEMprofilEcr.cxx \ -MEDMEM_MEDMEMchampLire.cxx - - -# Executables targets -BIN = med2_1_To_med2_2 med2vtk duplicateMED med_test duplicateMEDMESH -BIN_SRC = -BIN_SERVER_IDL = -BIN_CLIENT_IDL = - -TEST_PROGS = test_MEDMEM_ModulusArray test_MEDMEM_Array test_MEDMEM_SkyLineArray \ - test_MEDMEM_CellModel testUPointerOf testUCoordinate testUUnit \ - testUGeoNameMeshEntities testUMedException testUModulusArray \ - testUSkyLineArray testUArray testUCellModel readEntete readCoordinate \ - test_copie_field_ test_copie_fieldT test_copie_coordinate \ - test_copie_medarray test_copie_connectivity test_copie_support \ - test_copie_family test_copie_group test_copie_mesh test_affect_medarray \ - test_MEDMEM_Meshing test_MEDMEM_MeshingPoly test_operation_fielddouble \ - test_operation_fieldint test_gibi_driver test_porflow_driver \ - test_grid test_MEDMEM_PolyhedronArray test_MEDMEM_PolyConnectivity \ - test_MEDMEM_PolyDriverMedMeshRead test_MEDMEM_PolyDriverMedMeshWrite \ - test_MEDMEM_poly3D test_MEDMEM_nArray test_MEDMEM_Meshing_poly test_profil_MedFieldDriver \ - test_profil_gauss_MedFieldDriver test_GaussLocalization testAnalFile test_MEDMEM_MeshingFlica - -LDFLAGS+= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN+= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS+=$(MED2_INCLUDES) $(HDF5_INCLUDES) - -CXXFLAGS+=@CXXTMPDPTHFLAGS@ -#LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -# change motivated by the bug KERNEL4778. -LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 $(STDLIB) - -#LDFLAGSFORBIN+=$(MED2_LIBS) $(HDF5_LIBS) -# change motivated by the bug KERNEL4778. -LDFLAGSFORBIN+=-lm $(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 - -ifeq ($(MED_WITH_KERNEL),yes) - CPPFLAGS+= ${KERNEL_CXXFLAGS} - CXXFLAGS+= ${KERNEL_CXXFLAGS} - LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace - LDFLAGSFORBIN+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace -lSALOMEBasics -endif - -LIBSFORBIN= - -LIBS= - -# build create_mesh : -bin: create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_mesh_c3h8q4_wrong create_mesh_c2q4s2_wrong create_grid create_mesh_c2q4 create_mesh_c3h8 create_poly3D - -create_mesh create_mesh_c2q4s2 create_mesh_c3h8q4 create_grid create_mesh_c2q4 create_mesh_c3h8 create_mesh_c3h8q4_wrong create_mesh_c2q4s2_wrong create_poly3D: %: %.c - $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(MED2_LIBS) $(HDF5_LIBS) $< - -@CONCLUDE@ diff --git a/src/MEDMEM/Test/BasicMainTest.hxx b/src/MEDMEM/Test/BasicMainTest.hxx new file mode 100644 index 000000000..3794dcc1c --- /dev/null +++ b/src/MEDMEM/Test/BasicMainTest.hxx @@ -0,0 +1,88 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef _BASICMAINTEST_HXX_ +#define _BASICMAINTEST_HXX_ + +#include <cppunit/CompilerOutputter.h> +#include <cppunit/TestResult.h> +#include <cppunit/TestResultCollector.h> +#include <cppunit/TextTestProgressListener.h> +#include <cppunit/BriefTestProgressListener.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/TestRunner.h> +#include <stdexcept> + +#include <iostream> +#include <fstream> + +// ============================================================================ +/*! + * Main program source for Unit Tests with cppunit package does not depend + * on actual tests, so we use the same for all partial unit tests. + */ +// ============================================================================ + +int main(int argc, char* argv[]) +{ + // --- Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + + // --- Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener( &result ); + + // --- Add a listener that print dots as test run. +#ifdef WIN32 + CPPUNIT_NS::TextTestProgressListener progress; +#else + CPPUNIT_NS::BriefTestProgressListener progress; +#endif + controller.addListener( &progress ); + + // --- Get the top level suite from the registry + + CPPUNIT_NS::Test *suite = + CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); + + // --- Adds the test to the list of test to run + + CPPUNIT_NS::TestRunner runner; + runner.addTest( suite ); + runner.run( controller); + + // --- Print test in a compiler compatible format. + + std::ofstream testFile; + testFile.open("UnitTestsResult", std::ios::out | std::ios::trunc); + //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr ); + CPPUNIT_NS::CompilerOutputter outputter( &result, testFile ); + outputter.write(); + + // --- Run the tests. + + bool wasSucessful = result.wasSuccessful(); + testFile.close(); + + // --- Return error code 1 if the one of test failed. + + return wasSucessful ? 0 : 1; +} + +#endif diff --git a/src/MEDMEM/Test/MEDMEMTest.cxx b/src/MEDMEM/Test/MEDMEMTest.cxx new file mode 100644 index 000000000..42fd84996 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest.cxx @@ -0,0 +1,701 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_IndexCheckingPolicy.hxx" +#include "MEDMEM_MedFieldDriver.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_STRING.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; + +// ============================================================================ +/*! + * Set up the environment + */ +// ============================================================================ +void MEDMEMTest::setUp() +{ +} + +// ============================================================================ +/*! + * - delete + */ +// ============================================================================ +void MEDMEMTest::tearDown() +{ +} + +// #1: MEDMEM_Array.hxx \ +// #2: MEDMEM_ArrayConvert.hxx } MEDMEMTest_Array.cxx +// #3: MEDMEM_ArrayInterface.hxx (-) / +// #4: MEDMEM_AsciiFieldDriver.hxx } MEDMEMTest_AsciiFieldDriver.cxx +// #5: MEDMEM_CellModel.hxx } MEDMEMTest.cxx (-) +// #6: MEDMEM_Compatibility21_22.hxx } nothing to test +// #7: MEDMEM_Connectivity.hxx } MEDMEMTest_Connectivity.cxx +// #8: MEDMEM_Coordinate.hxx } MEDMEMTest_Coordinate.cxx +// #9: MEDMEM_DriverFactory.hxx } MEDMEMTest_DriverFactory.cxx +// #10: MEDMEM_DriversDef.hxx } MEDMEMTest.cxx (-) +// #11: MEDMEM_DriverTools.hxx } MEDMEMTest.cxx (-) +// #12: MEDMEM_Exception.hxx } MEDMEMTest_Exception.cxx +// #13: MEDMEM_Family.hxx } MEDMEMTest.cxx +// #14: MEDMEM_Field.hxx \ +// #15: MEDMEM_FieldConvert.hxx / MEDMEMTest_Field.cxx +// #16: MEDMEM_FieldForward.hxx } no methods to test +// #17: MEDMEM_Formulae.hxx } MEDMEMTest_Formulae.cxx +// #18: MEDMEM_GaussLocalization.hxx } MEDMEMTest_GaussLocalization.cxx +// #19: MEDMEM_GenDriver.hxx } abstract class; implemented methods are tested during its successors testing +// #20: MEDMEM_GibiMeshDriver.hxx } MEDMEMTest_GibiMeshDriver.cxx +// #21: MEDMEM_Grid.cxx } MEDMEMTest_Grid.cxx +// #22: MEDMEM_Group.cxx } MEDMEMTest_Group.cxx +// #23: MEDMEM_IndexCheckingPolicy.cxx } MEDMEMTest.cxx +// #24: MEDMEM_Init.cxx } MEDMEMTest.cxx +// #25: MEDMEM_InterlacingPolicy.hxx } MEDMEMTest.cxx (-) +// #26: MEDMEM_InterlacingTraits.hxx } MEDMEMTest.cxx (-) +// #27: MEDMEM_MedFieldDriver21.hxx } MEDMEMTest_MedFieldDriver21.cxx +// #28: MEDMEM_MedFieldDriver22.hxx } MEDMEMTest_MedFieldDriver22.cxx +// #29: MEDMEM_MedFieldDriver.hxx } MEDMEMTest.cxx (-) +// #30: MEDMEM_Med.hxx } MEDMEMTest_Med.cxx +// #31: MEDMEM_MedMedDriver21.hxx } MEDMEMTest_MedMedDriver21.cxx +// #32: MEDMEM_MedMedDriver22.hxx } MEDMEMTest_MedMedDriver22.cxx +// #33: MEDMEM_MedMedDriver.hxx } MEDMEMTest.cxx (-) +// #34: MEDMEM_MEDMEMchampLire.hxx } MEDMEMTest.cxx (-) +// #35: MEDMEM_MEDMEMgaussEcr.hxx } MEDMEMTest.cxx (-) +// #36: MEDMEM_MEDMEMprofilEcr.hxx } MEDMEMTest.cxx (-) +// #37: MEDMEM_MedMeshDriver21.hxx } MEDMEMTest_MedMeshDriver21.cxx +// #38: MEDMEM_MedMeshDriver22.hxx } MEDMEMTest_MedMeshDriver22.cxx +// #39: MEDMEM_MedMeshDriver.hxx } MEDMEMTest.cxx (-) +// #40: MEDMEM_MedVersion.hxx } MEDMEMTest_MedVersion.cxx +// #41: MEDMEM_Mesh.hxx \ +// #42: MEDMEM_Meshing.hxx / MEDMEMTest_MeshAndMeshing.cxx +// #43: MEDMEM_ModulusArray.hxx } MEDMEMTest_ModulusArray.cxx +// #44: MEDMEM_nArray.hxx } MEDMEMTest_nArray.cxx +// #45: MEDMEM_PointerOf.hxx } MEDMEMTest_PointerOf.cxx +// #46: MEDMEM_PolyhedronArray.hxx } MEDMEMTest_PolyhedronArray.cxx +// #47: MEDMEM_PorflowMeshDriver.hxx } MEDMEMTest_PorflowMeshDriver.cxx +// #48: MEDMEM_RCBase.hxx } MEDMEMTest.cxx (-) +// #49: MEDMEM_SetInterlacingType.hxx } MEDMEMTest.cxx (-) +// #50: MEDMEM_SkyLineArray.hxx } MEDMEMTest_SkyLineArray.cxx +// #51: MEDMEM_STRING.hxx } MEDMEMTest.cxx +// #52: MEDMEM_Support.hxx } MEDMEMTest_Support.cxx +// #53: MEDMEM_Tags.hxx } MEDMEMTest.cxx (-) +// #54: MEDMEM_TopLevel.hxx } MEDMEMTest_TopLevel.cxx +// #55: MEDMEM_TypeMeshDriver.hxx } MEDMEMTest.cxx +// #56: MEDMEM_Unit.hxx } MEDMEMTest_Unit.cxx +// #57: MEDMEM_VtkFieldDriver.hxx } MEDMEMTest_VtkFieldDriver.cxx +// #58: MEDMEM_VtkMedDriver.hxx } MEDMEMTest_VtkMedDriver.cxx +// #59: MEDMEM_VtkMeshDriver.hxx } MEDMEMTest_VtkMeshDriver.cxx +// #60: MEDMEM_medimport_src.hxx } MEDMEMTest.cxx (-) + + +/*! + * Check methods (not in spec), defined in MEDMEM_CellModel.hxx: + */ +//void MEDMEMTest::testCellModel() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_DriversDef.hxx: + */ +//void MEDMEMTest::testDriversDef() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_DriverTools.hxx: + */ +//void MEDMEMTest::testDriverTools() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (4), defined in MEDMEM_IndexCheckingPolicy.hxx: + * class IndexCheckPolicy { + * (+) void checkMoreThanZero(const std::string & classname, int index) const; + * (+) void checkLessOrEqualThan(const std::string & classname, int max, int index) const; + * (+) void checkInInclusiveRange(const std::string & classname, int min, int max, int index) const; + * (+) void checkEquality(const std::string & classname, int a, int b) const; + * } + * class NoIndexCheckPolicy { + * (+) void checkMoreThanZero(const string &classname, int index) const; + * (+) void checkLessOrEqualThan(const std::string & classname, int max, int index) const; + * (+) void checkInInclusiveRange(const std::string & classname, int min, int max, int index) const; + * (+) void checkEquality(const std::string & classname, int a, int b) const; + * } + */ +void MEDMEMTest::testIndexCheckingPolicy() +{ + MEDMEM::IndexCheckPolicy do_check; + MEDMEM::NoIndexCheckPolicy no_check; + + int min = 3; + int max = 10; + + string aClassName ("MEDMEMTest::testIndexCheckingPolicy"); + + // IndexCheckPolicy: throw, if index does not satisfy criteria + CPPUNIT_ASSERT_THROW(do_check.checkMoreThanZero(aClassName, -1), MEDMEM::MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(do_check.checkLessOrEqualThan(aClassName, max, 13), MEDMEM::MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(do_check.checkInInclusiveRange(aClassName, min, max, 1), MEDMEM::MEDEXCEPTION); + // checkEquality() check that values are not equal + CPPUNIT_ASSERT_THROW(do_check.checkEquality(aClassName, 21, 21), MEDMEM::MEDEXCEPTION); + + // NoIndexCheckPolicy: do not throw, if index does not satisfy criteria + CPPUNIT_ASSERT_NO_THROW(no_check.checkMoreThanZero(aClassName, -1)); + CPPUNIT_ASSERT_NO_THROW(no_check.checkLessOrEqualThan(aClassName, max, 13)); + CPPUNIT_ASSERT_NO_THROW(no_check.checkInInclusiveRange(aClassName, min, max, 1)); + CPPUNIT_ASSERT_NO_THROW(no_check.checkEquality(aClassName, 21, 21)); + + // IndexCheckPolicy: do not throw, if index satisfy criteria + CPPUNIT_ASSERT_NO_THROW(do_check.checkMoreThanZero(aClassName, 5)); + CPPUNIT_ASSERT_NO_THROW(do_check.checkLessOrEqualThan(aClassName, max, 7)); + CPPUNIT_ASSERT_NO_THROW(do_check.checkInInclusiveRange(aClassName, min, max, 6)); + CPPUNIT_ASSERT_NO_THROW(do_check.checkEquality(aClassName, 21, 28)); + + // NoIndexCheckPolicy: do not throw, if index satisfy criteria + CPPUNIT_ASSERT_NO_THROW(no_check.checkMoreThanZero(aClassName, 5)); + CPPUNIT_ASSERT_NO_THROW(no_check.checkLessOrEqualThan(aClassName, max, 7)); + CPPUNIT_ASSERT_NO_THROW(no_check.checkInInclusiveRange(aClassName, min, max, 6)); + CPPUNIT_ASSERT_NO_THROW(no_check.checkEquality(aClassName, 21, 28)); +} + +/*! + * Check initialization, done in MEDMEM_Init.cxx: + * (-) MEDMEM::INIT init; + */ +void MEDMEMTest::testInit() +{ + // We cannot check here effect of initialization, done in MEDMEM_Init.cxx, + // because environment variable, set there, is visible only in libmedmem.la + // and its child processes (if any). + + // Check effect of MEDMEM_Init.cxx + //char* traceKind = getenv("SALOME_trace"); + //CPPUNIT_ASSERT(traceKind); +} + +/*! + * Check methods (not in spec), defined in MEDMEM_InterlacingPolicy.hxx: + */ +//void MEDMEMTest::testInterlacingPolicy() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_InterlacingTraits.hxx: + */ +//void MEDMEMTest::testInterlacingTraits() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_MedFieldDriver.hxx: + */ +//void MEDMEMTest::testMedFieldDriver() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_MedMedDriver.hxx: + */ +//void MEDMEMTest::testMedMedDriver() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_MEDMEMchampLire.hxx: + */ +//void MEDMEMTest::testMEDMEMchampLire() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_MEDMEMgaussEcr.hxx: + */ +//void MEDMEMTest::testMEDMEMgaussEcr() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_MEDMEMprofilEcr.hxx: + */ +//void MEDMEMTest::testMEDMEMprofilEcr() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_MedMeshDriver.hxx: + */ +//void MEDMEMTest::testMedMeshDriver() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_RCBase.hxx: + * class RCBASE { + * (reference counter presently disconnected in C++) virtual void addReference() const = 0; + * (reference counter presently disconnected in C++) virtual void removeReference() const = 0; + * } + */ +//void MEDMEMTest::testRCBase() +//{ +// // nothing to test +//} + +/*! + * Check methods (not in spec), defined in MEDMEM_SetInterlacingType.hxx: + */ +//void MEDMEMTest::testSetInterlacingType() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (2), defined in MEDMEM_STRING.hxx: + * class STRING : public string { + * (+) STRING() + * (+) ~STRING() + * (+) operator const char * () const + * (+) template <class T> STRING(const T &valeur) + * (+) template <class T> STRING & operator<<(const T &valeur) + * } + */ +void MEDMEMTest::testSTRING() +{ + { + // empty constructor + MEDMEM::STRING medstr; + CPPUNIT_ASSERT(strcmp(medstr.c_str(), "") == 0); + + // template <class T> STRING & operator<<(const T &valeur) with T == char* + //medstr << <char*>"filling 1"; + medstr << "filling " << 1 << " !!!"; + CPPUNIT_ASSERT(strcmp(medstr.c_str(), "filling 1 !!!") == 0); + + // operator const char * () + CPPUNIT_ASSERT(strcmp((const char *)medstr, "filling 1 !!!") == 0); + CPPUNIT_ASSERT(strcmp( medstr, "filling 1 !!!") == 0); + } + + MEDMEM::MESH * aMesh1 = MEDMEMTest_createTestMesh(); + ostringstream ostr; + ostr << *aMesh1; + + { + // template <class T> STRING & operator<<(const T &valeur) with T == MEDMEM::MESH + MEDMEM::STRING medstr; + //medstr << <char*>"filling 1"; + medstr << *aMesh1; + CPPUNIT_ASSERT(strcmp(medstr, ostr.str().c_str()) == 0); + } + + { + // Constructor STRING(const T &valeur) with T == char* + //MEDMEM::STRING medstr<char*>("filling 2"); + MEDMEM::STRING medstr ("filling 2"); + CPPUNIT_ASSERT(strcmp(medstr.c_str(), "filling 2") == 0); + CPPUNIT_ASSERT(strcmp(medstr, "filling 2") == 0); + } + + { + // Constructor STRING(const T &valeur) with T == MEDMEM::MESH + MEDMEM::STRING medstr (*aMesh1); + CPPUNIT_ASSERT(strcmp(medstr, ostr.str().c_str()) == 0); + } + + delete aMesh1; +} + +/*! + * Check methods (not in spec), defined in MEDMEM_Tags.hxx: + */ +//void MEDMEMTest::testTags() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +/*! + * Check methods (15), defined in MEDMEM_TypeMeshDriver.hxx: + * class TYPE_MESH_DRIVER : public GENDRIVER { + * (-) TYPE_MESH_DRIVER(); + * (-) TYPE_MESH_DRIVER(const string & fileName, MESH * ptrMesh, med_mode_acces accessMode); + * (-) TYPE_MESH_DRIVER(const TYPE_MESH_DRIVER & driver); + * (-) virtual ~TYPE_MESH_DRIVER(); + * (-) void open() throw (MEDEXCEPTION); + * (-) void close() throw (MEDEXCEPTION); + * (-) virtual void write(void) const = 0; + * (-) virtual void read (void) = 0; + * (-) void setMeshName(const string & meshName); + * (-) string getMeshName() const; + * } + * class TYPE_MESH_RDONLY_DRIVER : public virtual TYPE_MESH_DRIVER { + * (-) TYPE_MESH_RDONLY_DRIVER(); + * (-) TYPE_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh); + * (-) TYPE_MESH_RDONLY_DRIVER(const TYPE_MESH_RDONLY_DRIVER & driver); + * (-) virtual ~TYPE_MESH_RDONLY_DRIVER(); + * (-) void write(void) const throw (MEDEXCEPTION); + * (-) void read (void) throw (MEDEXCEPTION); + * } + * class TYPE_MESH_WRONLY_DRIVER : public virtual TYPE_MESH_DRIVER { + * (-) TYPE_MESH_WRONLY_DRIVER(); + * (-) TYPE_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh); + * (-) TYPE_MESH_WRONLY_DRIVER(const TYPE_MESH_WRONLY_DRIVER & driver); + * (-) virtual ~TYPE_MESH_WRONLY_DRIVER(); + * (-) void write(void) const throw (MEDEXCEPTION); + * (-) void read (void) throw (MEDEXCEPTION); + * } + * class TYPE_MESH_RDWR_DRIVER : public TYPE_MESH_RDONLY_DRIVER, public TYPE_MESH_WRONLY_DRIVER { + * (-) TYPE_MESH_RDWR_DRIVER(); + * (-) TYPE_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh); + * (-) TYPE_MESH_RDWR_DRIVER(const TYPE_MESH_RDWR_DRIVER & driver); + * (-) ~TYPE_MESH_RDWR_DRIVER(); + * (-) void write(void) const throw (MEDEXCEPTION); + * (-) void read (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testTypeMeshDriver() +{ + CPPUNIT_FAIL("TYPE_MESH_DRIVER: not implemented"); +} + +/*! + * Check methods (not in spec), defined in MEDMEM_medimport_src.hxx: + */ +//void MEDMEMTest::testmedimport_src() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} + +//60 +//21 not in spec + +////////////////////////////////////// +// HELP METHODS, used in many tests // +////////////////////////////////////// + +/*! + * Create a mesh with certain filling + * .n4 + * | + * | + * n16,n12,n8.---------.n7,n11,n15 + * | | | + * | | | + * n5.----|----.----|----.n3 + * | | | + * | | | + * n17,n13,n9.---------.n10,n14,n18 + * | + * | + * .n6 + * + * .n19 (0,0,5) + * | + * | + * | + * | + * n16.--|-.----.n15 + * / |/ / + * . . . + * / /| / + * n17.----.----.n18 + * | + * | + * n12.--|-.----.n11 + * / |/ / + * . . . + * / /| / + * n13.----.----.n14 + * | + * | + * n8.--|-.----.n7 + * / |/ / + * . . . + * / /| / + * n9.----.----.n10 + * | .n4 (0,2,1) + * | / + * | . + * |/ + * n5.----.----.----.----.n3 (2,0,1) + * (-2,0,1) /n2 (0,0,1) + * . | + * / | + * .n6 | + * | + * | + * .n1 (0,0,0) + */ +MEDMEM::MESH * MEDMEMTest_createTestMesh () +{ + // MESH DATA + int SpaceDimension = 3; + int meshDimension = SpaceDimension; // because there 3D cells in the mesh + + // coordinates + int NumberOfNodes = 19; + + string Names[3] = { "X","Y","Z" }; + string Units[3] = { "cm","cm","cm" }; + + double Coordinates[57] = { + 0.0, 0.0, 0.0, // n1 + 0.0, 0.0, 1.0, // n2 + 2.0, 0.0, 1.0, // n3 + 0.0, 2.0, 1.0, // n4 + -2.0, 0.0, 1.0, // n5 + 0.0, -2.0, 1.0, // n6 + 1.0, 1.0, 2.0, // n7 + -1.0, 1.0, 2.0, // n8 + -1.0, -1.0, 2.0, // n9 + 1.0, -1.0, 2.0, // n10 + 1.0, 1.0, 3.0, // n11 + -1.0, 1.0, 3.0, // n12 + -1.0, -1.0, 3.0, // n13 + 1.0, -1.0, 3.0, // n14 + 1.0, 1.0, 4.0, // n15 + -1.0, 1.0, 4.0, // n16 + -1.0, -1.0, 4.0, // n17 + 1.0, -1.0, 4.0, // n18 + 0.0, 0.0, 5.0 // n19 + }; + + // cells connectivities + const int NumberOfCellTypes = 3; + MED_EN::medGeometryElement CellTypes[NumberOfCellTypes] = + {MED_EN::MED_TETRA4, MED_EN::MED_PYRA5, MED_EN::MED_HEXA8}; + const int NumberOfCells[NumberOfCellTypes] = {12, 2, 2}; + + int ConnectivityTetra[12 * 4] = { + 1,2,3,6, + 1,2,4,3, + 1,2,5,4, + 1,2,6,5, + 2,7,4,3, + 2,8,5,4, + 2,9,6,5, + 2,10,3,6, + 2,7,3,10, + 2,8,4,7, + 2,9,5,8, + 2,10,6,9 + }; + + int ConnectivityPyra[2 * 5] = { + 7,8,9,10,2, + 15,18,17,16,19 + }; + + int ConnectivityHexa[2 * 8] = { + 11,12,13,14,7,8,9,10, + 15,16,17,18,11,12,13,14 + }; + + // faces connectivities + const int NumberOfFaceTypes = 2; + MED_EN::medGeometryElement FaceTypes[NumberOfFaceTypes] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4}; + const int NumberOfFaces[NumberOfFaceTypes] = {4, 4}; + + int ConnectivityTria[4 * 3] = { + 1,4,3, + 1,5,4, + 1,6,5, + 1,3,6 + }; + + int ConnectivityQua[4 * 4] = { + 7,8,9,10, + 11,12,13,14, + 11,7,8,12, + 12,8,9,13 + }; + + + // CREATE THE MESH + MEDMEM::MESHING* myMeshing = new MEDMEM::MESHING; + + myMeshing->setName("meshing"); + + myMeshing->setCoordinates(SpaceDimension, NumberOfNodes, Coordinates, + "CARTESIAN", MED_EN::MED_FULL_INTERLACE); + myMeshing->setCoordinatesNames(Names); + myMeshing->setCoordinatesUnits(Units); + + // define connectivities + myMeshing->setNumberOfTypes(NumberOfCellTypes, MED_EN::MED_CELL); + myMeshing->setTypes(CellTypes, MED_EN::MED_CELL); + myMeshing->setNumberOfElements(NumberOfCells, MED_EN::MED_CELL); + + myMeshing->setConnectivity(ConnectivityTetra, MED_EN::MED_CELL, MED_EN::MED_TETRA4); + myMeshing->setConnectivity(ConnectivityPyra, MED_EN::MED_CELL, MED_EN::MED_PYRA5); + myMeshing->setConnectivity(ConnectivityHexa, MED_EN::MED_CELL, MED_EN::MED_HEXA8); + + myMeshing->setNumberOfTypes(NumberOfFaceTypes, MED_EN::MED_FACE); + myMeshing->setTypes(FaceTypes, MED_EN::MED_FACE); + myMeshing->setNumberOfElements(NumberOfFaces, MED_EN::MED_FACE); + + myMeshing->setConnectivity(ConnectivityTria, MED_EN::MED_FACE, MED_EN::MED_TRIA3); + myMeshing->setConnectivity(ConnectivityQua, MED_EN::MED_FACE, MED_EN::MED_QUAD4); + + // mesh dimension + myMeshing->setMeshDimension(meshDimension); + + // edges connectivities + // not yet implemented : if set, results are unpredictable. + + // groups of nodes + { + MEDMEM::GROUP myGroup; + myGroup.setName("SomeNodes"); + myGroup.setMesh(myMeshing); + myGroup.setEntity(MED_EN::MED_NODE); + myGroup.setNumberOfGeometricType(1); + MED_EN::medGeometryElement myTypes[1] = {MED_EN::MED_NONE}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {4}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,5}; + const int value[4] = {1,4,5,7}; + myGroup.setNumber(index,value); + myMeshing->addGroup(myGroup); + } + { + MEDMEM::GROUP myGroup; + myGroup.setName("OtherNodes"); + myGroup.setMesh(myMeshing); + myGroup.setEntity(MED_EN::MED_NODE); + myGroup.setNumberOfGeometricType(1); + MED_EN::medGeometryElement myTypes[1] = {MED_EN::MED_NONE}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {3}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,4}; + const int value[3] = {2,3,6}; + myGroup.setNumber(index,value); + myMeshing->addGroup(myGroup); + } + + // groups of cells + { + MEDMEM::GROUP myGroup; + myGroup.setName("SomeCells"); + myGroup.setMesh(myMeshing); + myGroup.setEntity(MED_EN::MED_CELL); + myGroup.setNumberOfGeometricType(3); + MED_EN::medGeometryElement myTypes[3] = {MED_EN::MED_TETRA4,MED_EN::MED_PYRA5,MED_EN::MED_HEXA8}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[3] = {4,1,2}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[3+1] = {1,5,6,8}; + const int value[4+1+2] = {2,7,8,12, 13, 15,16}; + myGroup.setNumber(index,value); + myMeshing->addGroup(myGroup); + } + { + MEDMEM::GROUP myGroup; + myGroup.setName("OtherCells"); + myGroup.setMesh(myMeshing); + myGroup.setEntity(MED_EN::MED_CELL); + myGroup.setNumberOfGeometricType(2); + MED_EN::medGeometryElement myTypes[] = {MED_EN::MED_TETRA4,MED_EN::MED_PYRA5}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[] = {4,1}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[2+1] = {1,5,6}; + const int value[4+1] = {3,4,5,9, 14}; + myGroup.setNumber(index,value); + myMeshing->addGroup(myGroup); + } + + // groups of faces + { + MEDMEM::GROUP myGroup; + myGroup.setName("SomeFaces"); + myGroup.setMesh(myMeshing); + myGroup.setEntity(MED_EN::MED_FACE); + myGroup.setNumberOfGeometricType(2); + MED_EN::medGeometryElement myTypes[2] = {MED_EN::MED_TRIA3,MED_EN::MED_QUAD4}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[2] = {2,3}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[2+1] = {1,3,6}; + const int value[2+3] = {2,4, 5,6,8}; + myGroup.setNumber(index,value); + myMeshing->addGroup(myGroup); + } + { + MEDMEM::GROUP myGroup; + myGroup.setName("OtherFaces"); + myGroup.setMesh(myMeshing); + myGroup.setEntity(MED_EN::MED_FACE); + myGroup.setNumberOfGeometricType(1); + MED_EN::medGeometryElement myTypes[1] = {MED_EN::MED_TRIA3}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {2}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,3}; + const int value[2] = {1,3}; + myGroup.setNumber(index,value); + myMeshing->addGroup(myGroup); + } + + return myMeshing; +} + +/*! + * Tool to remove temporary files. + * Allows automatique removal of temporary files in case of test failure. + */ +MEDMEMTest_TmpFilesRemover::~MEDMEMTest_TmpFilesRemover() +{ + set<string>::iterator it = myTmpFiles.begin(); + for (; it != myTmpFiles.end(); it++) { + if (access((*it).data(), F_OK) == 0) + remove((*it).data()); + } + myTmpFiles.clear(); + //cout << "~MEDMEMTest_TmpFilesRemover()" << endl; +} + +bool MEDMEMTest_TmpFilesRemover::Register(const string theTmpFile) +{ + return (myTmpFiles.insert(theTmpFile)).second; +} diff --git a/src/MEDMEM/Test/MEDMEMTest.hxx b/src/MEDMEM/Test/MEDMEMTest.hxx new file mode 100644 index 000000000..6d77598de --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest.hxx @@ -0,0 +1,203 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _MEDMEMTEST_HXX_ +#define _MEDMEMTEST_HXX_ + +#include <cppunit/extensions/HelperMacros.h> + +#include <set> +#include <string> +//#include <ostream> +#include <iostream> + +namespace MEDMEM { + class MESH; +}; + +class MEDMEMTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( MEDMEMTest ); + //0 + CPPUNIT_TEST( testArray ); + CPPUNIT_TEST( testArrayConvert ); + //CPPUNIT_TEST( testArrayInterface /* not in spec */ ); + //CPPUNIT_TEST( testAsciiFieldDriver ); + //CPPUNIT_TEST( testCellModel /* not in spec */ ); + CPPUNIT_TEST( testConnectivity ); + CPPUNIT_TEST( testCoordinate ); + CPPUNIT_TEST( testDriverFactory ); + //CPPUNIT_TEST( testDriversDef /* not in spec */ ); + //10 + //CPPUNIT_TEST( testDriverTools /* not in spec */ ); + CPPUNIT_TEST( testException /* not in spec */ ); + CPPUNIT_TEST( testFamily ); + CPPUNIT_TEST( testField ); + CPPUNIT_TEST( testFieldConvert ); + CPPUNIT_TEST( testFormulae ); + CPPUNIT_TEST( testGaussLocalization ); + CPPUNIT_TEST( testGibiMeshDriver ); + //20 + CPPUNIT_TEST( testGrid ); + CPPUNIT_TEST( testGroup ); + CPPUNIT_TEST( testIndexCheckingPolicy ); + CPPUNIT_TEST( testInit /* cxx */ ); + //CPPUNIT_TEST( testInterlacingPolicy /* not in spec */ ); + //CPPUNIT_TEST( testInterlacingTraits /* not in spec */ ); + CPPUNIT_TEST( testMedFieldDriver21 ); + CPPUNIT_TEST( testMedFieldDriver22 ); + //CPPUNIT_TEST( testMedFieldDriver /* not in spec */ ); + CPPUNIT_TEST( testMed ); + //30 + CPPUNIT_TEST( testMedMedDriver21 ); + CPPUNIT_TEST( testMedMedDriver22 ); + //CPPUNIT_TEST( testMedMedDriver /* not in spec */ ); + //CPPUNIT_TEST( testMEDMEMchampLire /* not in spec */ ); + //CPPUNIT_TEST( testMEDMEMgaussEcr /* not in spec */ ); + //CPPUNIT_TEST( testMEDMEMprofilEcr /* not in spec */ ); + CPPUNIT_TEST( testMedMeshDriver21 ); + CPPUNIT_TEST( testMedMeshDriver22 ); + //CPPUNIT_TEST( testMedMeshDriver /* not in spec */ ); + CPPUNIT_TEST( testMedVersion ); + //40 + CPPUNIT_TEST( testMeshAndMeshing ); + CPPUNIT_TEST( testModulusArray ); + CPPUNIT_TEST( testnArray ); + CPPUNIT_TEST( testPointerOf ); + CPPUNIT_TEST( testPolyhedronArray ); + CPPUNIT_TEST( testPorflowMeshDriver ); + //CPPUNIT_TEST( testRCBase /* not in spec */ ); + //CPPUNIT_TEST( testSetInterlacingType /* not in spec */ ); + CPPUNIT_TEST( testSkyLineArray ); + //50 + CPPUNIT_TEST( testSTRING ); + CPPUNIT_TEST( testSupport ); + //CPPUNIT_TEST( testTags /* not in spec */ ); + CPPUNIT_TEST( testTopLevel ); + CPPUNIT_TEST( testTypeMeshDriver ); + CPPUNIT_TEST( testUnit ); + CPPUNIT_TEST( testVtkFieldDriver ); + CPPUNIT_TEST( testVtkMedDriver ); + CPPUNIT_TEST( testVtkMeshDriver ); + //CPPUNIT_TEST( testmedimport_src /* not in spec */ ); + //60 + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp(); + void tearDown(); + + void testArray(); + void testArrayConvert(); + //void testArrayInterface() /* not in spec */; + void testAsciiFieldDriver(); + //void testCellModel() /* not in spec */; + void testConnectivity(); + void testCoordinate(); + void testDriverFactory(); + //void testDriversDef() /* not in spec */; + //10 + //void testDriverTools() /* not in spec */; + void testException() /* not in spec */; + void testFamily(); + void testField(); + void testFieldConvert(); + void testFormulae(); + void testGaussLocalization(); + void testGibiMeshDriver(); + //20 + void testGrid(); + void testGroup(); + void testIndexCheckingPolicy(); + void testInit() /* cxx */; + //void testInterlacingPolicy() /* not in spec */; + //void testInterlacingTraits() /* not in spec */; + void testMedFieldDriver21(); + void testMedFieldDriver22(); + //void testMedFieldDriver /* not in spec */(); + void testMed(); + //30 + void testMedMedDriver21(); + void testMedMedDriver22(); + //void testMedMedDriver() /* not in spec */; + //void testMEDMEMchampLire() /* not in spec */; + //void testMEDMEMgaussEcr() /* not in spec */; + //void testMEDMEMprofilEcr() /* not in spec */; + void testMedMeshDriver21(); + void testMedMeshDriver22(); + //void testMedMeshDriver() /* not in spec */; + void testMedVersion(); + //40 + void testMeshAndMeshing(); + void testModulusArray(); + void testnArray(); + void testPointerOf(); + void testPolyhedronArray(); + void testPorflowMeshDriver(); + //void testRCBase() /* not in spec */; + //void testSetInterlacingType /* not in spec */(); + void testSkyLineArray(); + //50 + void testSTRING(); + void testSupport(); + //void testTags() /* not in spec */; + void testTopLevel(); + void testTypeMeshDriver(); + void testUnit(); + void testVtkFieldDriver(); + void testVtkMedDriver(); + void testVtkMeshDriver(); + //void testmedimport_src() /* not in spec */; + //60 +}; + +// to create a mesh with certain filling +MEDMEM::MESH * MEDMEMTest_createTestMesh(); + +// to automatically remove temporary files from disk +class MEDMEMTest_TmpFilesRemover +{ +public: + MEDMEMTest_TmpFilesRemover() {} + ~MEDMEMTest_TmpFilesRemover(); + bool Register(const std::string theTmpFile); + +private: + std::set<std::string> myTmpFiles; +}; + +/*! + * Tool to print array to stream. + */ +template<class T> +void MEDMEMTest_DumpArray (std::ostream & stream, const T* array, const int length, const std::string text) +{ + stream << text << ": {"; + if (length > 0) { + stream << array[0]; + for (int i = 1; i < length; i++) { + stream << ", " << array[i]; + } + } + stream << "}" << std::endl; +}; + +#endif diff --git a/src/MEDMEM/Test/MEDMEMTest_Array.cxx b/src/MEDMEM/Test/MEDMEMTest_Array.cxx new file mode 100644 index 000000000..a83e40157 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Array.cxx @@ -0,0 +1,673 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_nArray.hxx" +#include "MEDMEM_ArrayConvert.hxx" +#include "MEDMEM_Array.hxx" +//#include "MEDMEM_ArrayInterface.hxx" +#include "MEDMEM_STRING.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #1,2,3: MEDMEMTest_Array.cxx +// Check methods from MEDMEM_Array.hxx, MEDMEM_ArrayConvert.hxx, MEDMEM_ArrayInterface.hxx + +/*! + * Check methods (20), defined in MEDMEM_Array.hxx: + * template <class T> class MEDARRAY { + * (+) inline MEDARRAY(); + * (+) inline ~MEDARRAY(); + * (+) MEDARRAY (const int ld_values, const int length_values, + * const MED_EN::medModeSwitch mode=MED_EN::MED_FULL_INTERLACE); + * (+) MEDARRAY (T* values, const int ld_values, + * const int length_values, const MED_EN::medModeSwitch mode=MED_EN::MED_FULL_INTERLACE, + * bool shallowCopy=false, bool ownershipOfValues=false); + * (+) MEDARRAY (MEDARRAY const &m); + * (+) MEDARRAY (MEDARRAY const &m, bool copyOther); + * (+) MEDARRAY & operator = (const MEDARRAY & m); + * (+) MEDARRAY & shallowCopy(const MEDARRAY & m); + * (+) inline int getLeadingValue() const; + * (+) inline int getLengthValue() const; + * (+) const T * get (const MED_EN::medModeSwitch mode); + * (+) const T * getRow (const int i); + * (+) const T * getColumn (const int j); + * (+) const T getIJ (const int i, const int j) const; + * (+) inline MED_EN::medModeSwitch getMode() const; + * (+) void set (const MED_EN::medModeSwitch mode,const T* value); + * (+) void setI (const int i, const T* value); + * (+) void setJ (const int j, const T* value); + * (+) void setIJ (const int i, const int j, const T value); + * (+) void calculateOther(); + * (+) bool isOtherCalculated() const {return (const T*)_valuesOther != NULL;} + * (+) void clearOtherMode(); + * } + * + * Use code of MEDMEM/tests/testUArray.cxx, + * MEDMEM/test_MEDMEM_Array.cxx + */ +void MEDMEMTest::testArray() +{ + int SpaceDimension = 3; + int NumberOfNodes = 4; + + //////////// + // TEST 1 // + //////////// + + /* ---------------------------------------------------------- */ + /* */ + /* INITIALISATION */ + /* */ + /* - constructeur new MEDARRAY<int>(int,int,mode) */ + /* - get sur le pointeur MED_FULL_INTERLACE */ + /* - initialisation des valeurs (coordonnĂ©es ieme elt = I+1) */ + /* - get sur le pointeur MED_NO_INTERLACE */ + /* ---------------------------------------------------------- */ + + MEDARRAY<int> * myArrayfull = + new MEDARRAY<int> (SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE); + CPPUNIT_ASSERT(myArrayfull != NULL); + + const int * myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE); + CPPUNIT_ASSERT(myValues != NULL); + + for (int i = 0; i < NumberOfNodes; i++) { + for (int k = 0; k < SpaceDimension; k++) { + myArrayfull->setIJ(i+1, k+1, i+1); + } + } + + const int * myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE); + CPPUNIT_ASSERT(myOthers != NULL); + + MEDARRAY<int> * myArrayno = new MEDARRAY<int>(SpaceDimension, NumberOfNodes, MED_EN::MED_NO_INTERLACE); + CPPUNIT_ASSERT(myArrayno != NULL); + const int * myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE); + CPPUNIT_ASSERT(myValuesno != NULL); + + for (int k = 0; k < SpaceDimension; k++) { + for (int i = 0; i < NumberOfNodes; i++) { + myArrayno->setIJ(i+1, k+1, k+1); + } + } + + const int * myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE); + CPPUNIT_ASSERT(myOthersno != NULL); + + /* ---------------------------------------------------------- */ + /* */ + /* Tests des Fonctions Set */ + /* */ + /* - setI sur l'element 1 avec des coordonnees a 100 */ + /* - setJ sur l'element 1 avec des coordonnees a 100 */ + /* - setIJ sur (1,2) avec une coordonnee = 1992 */ + /* - set avec l ensemble des coordonnes remises Ă  i */ + /* ---------------------------------------------------------- */ + + int * myNewLine = new int[SpaceDimension]; + for (int i = 0; i < SpaceDimension; i++) + myNewLine[i] = myValues[i] * 100; + try + { + myArrayfull->setI(1, myNewLine); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception in myArrayfull->setI()"); + } + + delete [] myNewLine; + + int * myNewCol = new int[NumberOfNodes]; + for (int i = 0; i < NumberOfNodes; i++) + myNewCol[i] = 100; + try + { + myArrayno->setJ(1, myNewCol); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception in myArrayno->setJ()"); + } + + delete [] myNewCol; + + try + { + myArrayfull->setIJ(1, 2, 1992); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception in myArrayfull->setIJ()"); + } + + try + { + myArrayno->setIJ(1, 2, 1992); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception in myArrayno->setIJ()"); + } + + int * mynewvalues = new int [ NumberOfNodes*SpaceDimension ]; + for (int i = 0; i < NumberOfNodes*SpaceDimension; i++) { + mynewvalues[i] = i; + } + try + { + myArrayfull->set(MED_EN::MED_FULL_INTERLACE, mynewvalues); + myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE); + myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myArrayno->set(MED_EN::MED_FULL_INTERLACE, mynewvalues); + myValuesno = myArrayfull->get(MED_EN::MED_FULL_INTERLACE); + myOthersno = NULL; + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + /* ---------------------------------------------------------- */ + /* */ + /* Tests des constructeurs */ + /* Tests des Fonctions Get */ + /* */ + /* ---------------------------------------------------------- */ + + // check sharing + MEDARRAY<int> * myArrayShare = new MEDARRAY<int>(*myArrayfull); + const int * sharevalues = myArrayShare->get(MED_EN::MED_FULL_INTERLACE); + const int * shareno = myArrayShare->get(MED_EN::MED_NO_INTERLACE); + + myArrayfull->setIJ(1, 2, 1993); + CPPUNIT_ASSERT(myArrayShare->getIJ(1,2) == 1993); + + myArrayShare->setIJ(1, 2, 1995); + CPPUNIT_ASSERT(myArrayfull->getIJ(1,2) == 1995); + + delete myArrayShare; + + // check no sharing + MEDARRAY<int> * myArrayShare2 = new MEDARRAY<int>(*myArrayfull, true); + sharevalues = myArrayShare2->get(MED_EN::MED_FULL_INTERLACE); + shareno = myArrayShare2->get(MED_EN::MED_NO_INTERLACE); + + myArrayfull->setIJ(1, 2, 18); + CPPUNIT_ASSERT(myArrayShare2->getIJ(1,2) == 1995); + myArrayShare2->setIJ(1, 2, 19); + CPPUNIT_ASSERT(myArrayfull->getIJ(1,2) == 18); + + // check myArrayno + myArrayno->set(MED_EN::MED_NO_INTERLACE, mynewvalues); + myArrayno->setIJ(2, 1, 1); + myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE); + myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE); + + MEDARRAY<int> * myArrayShare3 = new MEDARRAY<int>(*myArrayno); + sharevalues = myArrayShare3->get(MED_EN::MED_FULL_INTERLACE); + shareno = myArrayShare3->get(MED_EN::MED_NO_INTERLACE); + + myArrayno->setIJ(1, 2, 1992); + CPPUNIT_ASSERT(myArrayShare3->getIJ(1,2) == 1992); + + myArrayShare3->setIJ(1, 2, 1995); + CPPUNIT_ASSERT(myArrayno->getIJ(1,2) == 1995); + + delete myArrayno; + delete [] mynewvalues; + delete myArrayfull; + delete myArrayShare2; + delete myArrayShare3; + + + //////////// + // TEST 2 // + //////////// + + MEDARRAY<int> * myArray = + new MEDARRAY<int> (SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE); + + // - 1 1 1 + // - 2 2 2 + // - 3 3 3 + // - 4 4 4 + for (int i = 1; i <= NumberOfNodes; i++) + for (int j = 1; j <= SpaceDimension; j++) + myArray->setIJ(i, j, i); + + CPPUNIT_ASSERT(myArray->getLengthValue() == NumberOfNodes); + CPPUNIT_ASSERT(myArray->getLeadingValue() == SpaceDimension); + + int numberof = myArray->getLeadingValue(); // nb. of columns ~ space dimension + for (int i = 1; i <= myArray->getLengthValue(); i++) { + const int * node = myArray->getRow(i); + for (int j = 0; j < numberof; j++) { + CPPUNIT_ASSERT(node[j] == i); + } + } + + numberof = myArray->getLengthValue(); // nb. of rows ~ nb. of nodes + for (int i = 1; i <= myArray->getLeadingValue(); i++) { + const int * node = myArray->getColumn(i); + for (int j = 0; j < numberof; j++) { + CPPUNIT_ASSERT(node[j] == j + 1); + } + } + + numberof = myArray->getLeadingValue(); + for (int i = 1; i <= myArray->getLengthValue(); i++) { + for (int j = 1; j < numberof + 1; j++) { + CPPUNIT_ASSERT(myArray->getIJ(i,j) == i); + } + } + + numberof = myArray->getLeadingValue(); + int length = myArray->getLengthValue(); + const int * NoInterlaceArray = myArray->get(MED_EN::MED_NO_INTERLACE); + for (int i = 0; i < length; i++) { + for (int j = 0; j < numberof; j++) { + CPPUNIT_ASSERT(NoInterlaceArray[j*length+i] == i + 1); + } + } + + delete myArray; + + + //////////// + // TEST 3 // + //////////// + + // MEDARRAY (T* values, const int ld_values, + // const int length_values, const MED_EN::medModeSwitch mode=MED_EN::MED_FULL_INTERLACE, + // bool shallowCopy=false, bool ownershipOfValues=false); + + int ld = 7, nb = 4; + double rr = 13.0, h0 = 7.0; + double * aValues = new double [ld * nb]; + for (int nn = 0; nn < nb; nn++) { + aValues[nn*ld + 0] = nn; + aValues[nn*ld + 1] = rr * cos(nn * M_PI/4.); + aValues[nn*ld + 2] = rr * sin(nn * M_PI/4.); + aValues[nn*ld + 3] = h0 + nn; + aValues[nn*ld + 4] = 2.0 * rr * cos(nn * M_PI/4.); + aValues[nn*ld + 5] = 2.0 * rr * sin(nn * M_PI/4.); + aValues[nn*ld + 6] = h0 - nn; + } + + MEDARRAY<double> * aSpiral = + new MEDARRAY<double> (aValues, ld, nb, MED_EN::MED_FULL_INTERLACE, + /*shallowCopy=*/false, /*ownershipOfValues=*/false); + ///*shallowCopy=*/true, /*ownershipOfValues=*/true); + + if (aSpiral->isOtherCalculated()) + aSpiral->clearOtherMode(); + CPPUNIT_ASSERT(!aSpiral->isOtherCalculated()); + + CPPUNIT_ASSERT(aSpiral->getMode() == MED_EN::MED_FULL_INTERLACE); + aSpiral->calculateOther(); + CPPUNIT_ASSERT(aSpiral->getMode() == MED_EN::MED_FULL_INTERLACE); + CPPUNIT_ASSERT(aSpiral->getLeadingValue() == ld); + CPPUNIT_ASSERT(aSpiral->getLengthValue() == nb); + + //CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta); + double delta = 0.000001; + const double* comp5 = aSpiral->getColumn(5); + for (int nn = 0; nn < nb; nn++) { + const double* pnt = aSpiral->getRow(nn + 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0 * rr * cos(nn * M_PI/4.), pnt[4], delta); + CPPUNIT_ASSERT_DOUBLES_EQUAL(comp5[nn], pnt[4], delta); + } + + // Check operator= and method shallowCopy() + double c7n3 = aSpiral->getIJ(3, 7); + MEDARRAY<double> shc, cpy; + +// #ifdef ENABLE_FAULTS +// // (BUG) MEDARRAY<T>::shallowCopy() usage leads to memory leaks, +// // because on attemp to free both arrays we have Segmentation Fault +// shc.shallowCopy(*aSpiral); + +// // hangs up +// //MEDARRAY<double> arr (10, 10); +// //MEDARRAY<double> shc; +// //shc.shallowCopy(arr); + +// // Segmentation fault +// //MEDARRAY<double>* arr = new MEDARRAY<double> (10, 10); +// //MEDARRAY<double>* shc = new MEDARRAY<double> (10, 10); +// //shc->shallowCopy(*arr); +// //delete arr; +// //delete shc; +// #endif +// #ifdef ENABLE_FORCED_FAILURES +// CPPUNIT_FAIL("MEDARRAY<T>::shallowCopy(): wrong memory management"); +// #endif + + cpy = *aSpiral; + + aSpiral->setIJ(3, 7, c7n3 * 2.0); + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_DOUBLES_EQUAL(c7n3 * 2.0, shc.getIJ(3, 7), delta); +#endif + + //CPPUNIT_ASSERT_DOUBLES_EQUAL(c7n3 * 2.0, cpy.getIJ(3, 7), delta); + CPPUNIT_ASSERT_DOUBLES_EQUAL(c7n3, cpy.getIJ(3, 7), delta); + +// #ifdef ENABLE_FORCED_FAILURES +// // Comments to deep copy constructor do not correspond to actual implementation +// CPPUNIT_FAIL("Comments to MEDARRAY<T> deep copy constructor do not correspond to actual implementation"); +// #endif + + aSpiral->clearOtherMode(); + //CPPUNIT_ASSERT_THROW(MEDARRAY<double> co (*aSpiral, true), MEDEXCEPTION); + CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> co (*aSpiral, true)); + + // invalid cases + //double arr3 [3] = {1., 2., 3.}; + double arr4 [4] = {1., 2., 3., 4.}; + double arr7 [7] = {1., 2., 3., 4., 5., 6., 7.}; + CPPUNIT_ASSERT_THROW(aSpiral->getRow(0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->getRow(nb + 1), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->getColumn(0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->getColumn(ld + 1), MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(aSpiral->set(MED_EN::MED_FULL_INTERLACE, NULL), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->setI(-1, arr7), MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(aSpiral->setI(1, NULL), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->setJ(-1, arr4), MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(aSpiral->setJ(1, NULL), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->setIJ(-1, -1, 13.), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSpiral->setIJ(1, 0, 13.), MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(aSpiral->setI(1, arr3), MEDEXCEPTION); // user must control itself + + delete aSpiral; + + // check empty array + + MEDARRAY<double> anEmptyArray; + //CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> anArr1 (anEmptyArray)); // INTERRUPTION + //CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> anArr2 (anEmptyArray, false)); // fails + //CPPUNIT_ASSERT_NO_THROW(MEDARRAY<double> anArr4 = anEmptyArray); // INTERRUPTION + //MEDARRAY<double> anArr5; + //CPPUNIT_ASSERT_NO_THROW(anArr5.shallowCopy(anEmptyArray)); + + // invalid cases + CPPUNIT_ASSERT_THROW(anEmptyArray.get(MED_EN::MED_FULL_INTERLACE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.get(MED_EN::MED_NO_INTERLACE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.getRow(0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.getRow(5), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.getColumn(0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.getIJ(0, 0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.getIJ(1, 1), MEDEXCEPTION); + CPPUNIT_ASSERT_NO_THROW(anEmptyArray.set(MED_EN::MED_FULL_INTERLACE, aValues)); + CPPUNIT_ASSERT_THROW(anEmptyArray.setI(1, aValues), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.setIJ(0, 0, 3.), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyArray.setIJ(1, 1, 3.), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(MEDARRAY<double> bad (-1, 10), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(MEDARRAY<double> bad (10, -1), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(MEDARRAY<double> bad (-1, -1), MEDEXCEPTION); + + delete [] aValues; + + // construction with taking ownership of values + int ld1 = 7, nb1 = 4; + double * val1 = new double [ld * nb]; + for (int nn = 0; nn < nb1; nn++) { + for (int cc = 0; cc < ld1; cc++) { + val1[nn*ld1 + cc] = nn; + } + } + MEDARRAY<double> * arr1 = + new MEDARRAY<double> (val1, ld1, nb1, MED_EN::MED_FULL_INTERLACE, + /*shallowCopy=*/true, /*ownershipOfValues=*/true); + for (int nn = 1; nn <= nb1; nn++) { + for (int cc = 1; cc <= ld1; cc++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(nn - 1, arr1->getIJ(nn, cc), delta); + } + } + delete arr1; +} + +/*! + * Check methods (4), defined in MEDMEM_ArrayConvert.hxx: + * + * (+) Gauss NoInterlace->FullInterlace: + * template <class T, class CHECKING_POLICY > + * MEDMEM_Array<T, FullInterlaceGaussPolicy, CHECKING_POLICY> * + * ArrayConvert(const MEDMEM_Array< T, NoInterlaceGaussPolicy, CHECKING_POLICY > &array, T* values=0) + * + * (+) Gauss FullInterlace->NoInterlace: + * template <class T, class CHECKING_POLICY> + * MEDMEM_Array<T, NoInterlaceGaussPolicy, CHECKING_POLICY> * + * ArrayConvert(const MEDMEM_Array< T, FullInterlaceGaussPolicy, CHECKING_POLICY > &array, T* values=0) + * + * (+) NoGauss FullInterlace->NoInterlace: + * template <class T, class CHECKING_POLICY> + * MEDMEM_Array<T, NoInterlaceNoGaussPolicy, CHECKING_POLICY> * + * ArrayConvert(const MEDMEM_Array< T, FullInterlaceNoGaussPolicy, CHECKING_POLICY > &array, T* values=0) + * + * (+) NoGauss NoInterlace->FullInterlace: + * template <class T, class CHECKING_POLICY> + * MEDMEM_Array<T, FullInterlaceNoGaussPolicy, CHECKING_POLICY> * + * ArrayConvert(const MEDMEM_Array< T, NoInterlaceNoGaussPolicy, CHECKING_POLICY > &array, T* values=0) + * + * Use code of MEDMEM/test_MEDMEM_nArray.cxx + */ +void MEDMEMTest::testArrayConvert() +{ + // TEST n°1 : FullInterlaceNoGaussPolicy -> NoInterlaceNoGaussPolicy + + const int mdim = 2; + const int nbelem1 = 20; + + const double array1Ref[] = { 11 , 12 , 21 , 22 , 31 , 32 , 41 , 42 , 51 , 52 , + 61 , 62 , 71 , 72 , 81 , 82 , 91 , 92 , 101, 102, + 111, 112, 121, 122, 131, 132, 141, 142, 151, 152, + 161, 162, 171, 172, 181, 182, 191, 192, 201, 202 }; + + const double array2Ref[] = { 11 , 21 , 31 , 41 , 51 , 61 , 71 , 81 , 91 , 101, + 111, 121, 131, 141, 151, 161, 171, 181, 191, 201, + 12 , 22 , 32 , 42 , 52 , 62 , 72 , 82 , 92 , 102, + 112, 122, 132, 142, 152, 162, 172, 182, 192, 202 }; + + MEDMEM_Array<double> myArray1 (mdim, nbelem1); + + for (int i = 1; i <= nbelem1; i++) + for (int j = 1; j <= mdim; j++) + myArray1.setIJ(i, j, i*10+j); + + const double * myArray1Ptr = myArray1.getPtr(); + for (int i = 0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT(myArray1Ptr[i] == array1Ref[i]); + + MEDMEM_Array<double, NoInterlaceNoGaussPolicy> * myArray1cin = ArrayConvert(myArray1); + myArray1Ptr = myArray1cin->getPtr(); + int elemno = 0; + for (int j = 1; j <= mdim; j++) { + for (int i = 1; i <= nbelem1; i++) { + CPPUNIT_ASSERT(myArray1cin->getIJ(i,j) == array2Ref[elemno]); + CPPUNIT_ASSERT(myArray1Ptr[elemno] == array2Ref[elemno]); + elemno++; + } + } + + // TEST n°2 : NoInterlaceNoGaussPolicy -> FullInterlaceNoGaussPolicy + + MEDMEM_Array<double, NoInterlaceNoGaussPolicy> myArray2 (mdim, nbelem1); + + for (int i = 1; i <= nbelem1; i++) + for (int j = 1; j <= mdim; j++) + myArray2.setIJ(i, j, i*10+j); + + const double * myArray2Ptr = myArray2.getPtr(); + for (int i = 0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT(myArray2Ptr[i] == array2Ref[i]); + + MEDMEM_Array<double, FullInterlaceNoGaussPolicy> * myArray2cin = ArrayConvert(myArray2); + myArray2Ptr = myArray2cin->getPtr(); + elemno = 0; + for (int i = 1; i <= nbelem1; i++) { + for (int j = 1; j <= mdim; j++) { + CPPUNIT_ASSERT(myArray2cin->getIJ(i,j) == array1Ref[elemno]); + CPPUNIT_ASSERT(myArray2Ptr[elemno] == array1Ref[elemno]); + elemno++; + } + } + + // TEST n°3 : FullInterlaceGaussPolicy -> NoInterlaceGaussPolicy + + const int nbelem2 = 5; + const int nbtypegeo = 2; + const int nbelgeoc[nbtypegeo+1] = {1,3,6}; + const int nbgaussgeo[nbtypegeo+1] = {-1,2,3}; + + const double * myArray3Ptr = 0; + const double array3Ref[] = { 1.11, 1.12, 1.21, 1.22, + 2.11, 2.12, 2.21, 2.22, + 13.11, 13.12, 13.21, 13.22, 13.31, 13.32, + 14.11, 14.12, 14.21, 14.22, 14.31, 14.32, + 15.11, 15.12, 15.21, 15.22, 15.31, 15.32 }; + + const double array4Ref[] = { 1.11, 1.21, 2.11, 2.21, + 13.11, 13.21, 13.31, 14.11, 14.21, 14.31, + 15.11, 15.21, 15.31, + 1.12, 1.22, 2.12, 2.22, + 13.12, 13.22, 13.32, 14.12, 14.22, 14.32, + 15.12, 15.22, 15.32 }; + + MEDMEM_Array<double, FullInterlaceGaussPolicy> myArray3 + (mdim, nbelem2, nbtypegeo, nbelgeoc, nbgaussgeo); + + elemno = 1; + for (int ntyp = 1; ntyp <= nbtypegeo; ntyp++) { + for (int i = 0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]); i++) { + for (int k = 1; k <= nbgaussgeo[ntyp]; k++) { + for (int j = 1; j <= mdim; j++) { + myArray3.setIJK(elemno, j, k, elemno+(ntyp-1)*10+0.1*k+0.01*j); + } + } + elemno++; + } + } + myArray3Ptr = myArray3.getPtr(); + for (int i = 0; i < myArray3.getArraySize(); i++) + CPPUNIT_ASSERT(myArray3Ptr[i] == array3Ref[i]); + + MEDMEM_Array<double, NoInterlaceGaussPolicy> * myArray3cin = ArrayConvert(myArray3); + myArray3Ptr = myArray3cin->getPtr(); + elemno = 0; + for (int j = 1; j <= mdim; j++) + for (int i = 1; i < nbelgeoc[nbtypegeo]; i++) + for (int k = 1; k <= myArray3cin->getNbGauss(i); k++) { + CPPUNIT_ASSERT(myArray3cin->getIJK(i,j,k) == array4Ref[elemno]); + CPPUNIT_ASSERT(myArray3Ptr[elemno] == array4Ref[elemno]); + elemno++; + } + + // TEST n°4 : NoInterlaceGaussPolicy -> FullInterlaceGaussPolicy + + const double * myArray4Ptr = 0; + + MEDMEM_Array<double, NoInterlaceGaussPolicy> myArray4 + (mdim, nbelem2, nbtypegeo, nbelgeoc, nbgaussgeo); + + elemno = 1; + for (int ntyp = 1; ntyp <= nbtypegeo; ntyp++) { + for (int i = 0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]); i++) { + for (int k = 1; k <= nbgaussgeo[ntyp]; k++) { + for (int j = 1; j <= mdim; j++) { + myArray4.setIJK(elemno, j, k, elemno+(ntyp-1)*10+0.1*k+0.01*j); + } + } + elemno++; + } + } + myArray4Ptr = myArray4.getPtr(); + + for (int i = 0; i < myArray4.getArraySize(); i++) + CPPUNIT_ASSERT(myArray4Ptr[i] == array4Ref[i]); + + MEDMEM_Array<double, FullInterlaceGaussPolicy> * myArray4cin = ArrayConvert(myArray4); + myArray4Ptr = myArray4cin->getPtr(); + elemno = 0; + for (int i = 1; i < nbelgeoc[nbtypegeo]; i++) + for (int k = 1; k <= myArray4cin->getNbGauss(i); k++) + for (int j = 1; j <= mdim; j++) { + CPPUNIT_ASSERT(myArray4cin->getIJK(i,j,k) == array3Ref[elemno]); + CPPUNIT_ASSERT(myArray4cin->getIJK(i,j,k) == myArray3.getIJK(i,j,k)); + CPPUNIT_ASSERT(myArray4Ptr[elemno] == array3Ref[elemno]); + elemno++; + } +} + +/*! + * Check methods (not in spec), defined in MEDMEM_ArrayInterface.hxx: + */ +//void MEDMEMTest::testArrayInterface() +//{ +// CPPUNIT_FAIL("Case Not Implemented (not in spec)"); +//} diff --git a/src/MEDMEM/Test/MEDMEMTest_Array_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Array_fault.cxx new file mode 100644 index 000000000..a74037241 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Array_fault.cxx @@ -0,0 +1,70 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEM_Array.hxx" + +#include <cmath> + +using namespace std; +using namespace MEDMEM; + +/*! + * Check method shallowCopy() + */ +int main (int argc, char** argv) +{ + int ld = 7, nb = 4; + double rr = 13.0, h0 = 7.0; + double * aValues = new double [ld * nb]; + for (int nn = 0; nn < nb; nn++) { + aValues[nn*ld + 0] = nn; + aValues[nn*ld + 1] = rr * cos(nn * M_PI/4.); + aValues[nn*ld + 2] = rr * sin(nn * M_PI/4.); + aValues[nn*ld + 3] = h0 + nn; + aValues[nn*ld + 4] = 2.0 * rr * cos(nn * M_PI/4.); + aValues[nn*ld + 5] = 2.0 * rr * sin(nn * M_PI/4.); + aValues[nn*ld + 6] = h0 - nn; + } + + MEDARRAY<double> * aSpiral = + new MEDARRAY<double> (aValues, ld, nb, MED_EN::MED_FULL_INTERLACE, + /*shallowCopy=*/false, /*ownershipOfValues=*/false); + + // Check method shallowCopy() + MEDARRAY<double> shc; + + // (BUG) MEDARRAY<T>::shallowCopy() usage leads to memory leaks, + // because on attempt to free both arrays we have Segmentation Fault + shc.shallowCopy(*aSpiral); + + delete aSpiral; + + // hangs up + //MEDARRAY<double> arr (10, 10); + //MEDARRAY<double> shc; + //shc.shallowCopy(arr); + + // Segmentation fault + //MEDARRAY<double>* arr = new MEDARRAY<double> (10, 10); + //MEDARRAY<double>* shc = new MEDARRAY<double> (10, 10); + //shc->shallowCopy(*arr); + //delete arr; + //delete shc; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_AsciiFieldDriver.cxx b/src/MEDMEM/Test/MEDMEMTest_AsciiFieldDriver.cxx new file mode 100644 index 000000000..dd94b6530 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_AsciiFieldDriver.cxx @@ -0,0 +1,282 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Compatibility21_22.hxx" +#include "MEDMEM_AsciiFieldDriver.hxx" +#include "MEDMEM_STRING.hxx" + +#include <stdio.h> + +#include <sstream> +#include <fstream.h> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #4: MEDMEM_AsciiFieldDriver.hxx } MEDMEMTest_AsciiFieldDriver.cxx + +/*! + * Check methods (8), defined in MEDMEM_AsciiFieldDriver.hxx: + * + * (+) template<int N,unsigned int CODE> void fill(double *a, const double *b) + * (+) template<int N> bool compare(const double* a, const double* b) + * (+) template<> void fill<-1,0x3>(double *a, const double *b); + * (+) template<> bool compare<-1>(const double *a, const double *b); + * + * template <class T, int SPACEDIMENSION, unsigned int SORTSTRATEGY> + * class SDForSorting { + * (+) SDForSorting(const double *coords, const T* comp, int nbComponents); + * (+) SDForSorting(const SDForSorting& other); + * (+) ~SDForSorting(); + * (+) bool operator< (const SDForSorting<T,SPACEDIMENSION,SORTSTRATEGY>& other) const; + * (+) void writeLine(ofstream& file) const; + * } + * + * template <class T> + * class ASCII_FIELD_DRIVER : public GENDRIVER { + * + * //MUST BE PRIVATE as there is no possibility to set _ptrField after this constructor usage + * (-) template <class INTERLACING_TAG> ASCII_FIELD_DRIVER(); + * + * (+) template <class INTERLACING_TAG> + * ASCII_FIELD_DRIVER(const string & fileName, FIELD<T,INTERLACING_TAG> * ptrField, + * MED_EN::med_sort_direc direction=MED_EN::ASCENDING, const char *priority=""); + * (+) ASCII_FIELD_DRIVER(const ASCII_FIELD_DRIVER<T>& other); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) GENDRIVER* copy() const; + * } + */ +void MEDMEMTest::testAsciiFieldDriver() +{ + // read a mesh from a MED file + string datadir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + string fieldname = "fieldcelldouble"; + + if (tmp_dir == "") + tmp_dir = "/tmp"; + string anyfile1 = tmp_dir + "/anyfile1"; + string SDFfilename = tmp_dir + "/myfile"; + ofstream aFile(SDFfilename.c_str()); + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(anyfile1); + aRemover.Register(SDFfilename); + + //Test SDForSorting class + { + double coord_1[10] = { 1.0, 2.0, + -1.0, 2.0, + 3.6, -8.7, + 10.0, -10.0, + 12.3, 9.3}; + + int comp_1[5] = {1, 3, 5, 7, 9}; + SDForSorting<int, 2, 48> aSDF_1(coord_1, comp_1, 5); + + SDForSorting<int, 2, 48> aSDFCpy_1 = SDForSorting<int, 2, 48>(aSDF_1); + CPPUNIT_ASSERT_EQUAL(aSDFCpy_1 < aSDF_1, false); + CPPUNIT_ASSERT_NO_THROW(aSDF_1.writeLine(aFile)); + } + + // Why functions + // template<> void MEDMEM::fill<-1,0x3>(double *a, const double *b) + // and + // template<> bool MEDMEM::compare<-1>(const double *a, const double *b) + // declared in MEDMEM_AsciiFieldDriver.hxx, + // are implemented in MEDMEM_DriverFactory.cxx? + + // template<int N,unsigned int CODE> void fill(double *a, const double *b) + { + // 0x3 = 110000 + double aa[3]; + double bb[3] = {1,2,3}; + + fill<2,198>(aa, bb); // ZYX // 11000110 // 012 + //MEDMEMTest_DumpArray<double>(cout, aa, 3, "aa filled with ZYX"); + CPPUNIT_ASSERT_EQUAL(aa[0], bb[0]); + CPPUNIT_ASSERT_EQUAL(aa[1], bb[1]); + CPPUNIT_ASSERT_EQUAL(aa[2], bb[2]); + + fill<2,210>(aa, bb); // ZXY // 11010010 // 102 + //MEDMEMTest_DumpArray<double>(cout, aa, 3, "aa filled with ZXY"); + CPPUNIT_ASSERT_EQUAL(aa[0], bb[1]); + CPPUNIT_ASSERT_EQUAL(aa[1], bb[0]); + CPPUNIT_ASSERT_EQUAL(aa[2], bb[2]); + + fill<2,228>(aa, bb); // XYZ // 11100100 // 210 + //MEDMEMTest_DumpArray<double>(cout, aa, 3, "aa filled with XYZ"); + CPPUNIT_ASSERT_EQUAL(aa[0], bb[2]); + CPPUNIT_ASSERT_EQUAL(aa[1], bb[1]); + CPPUNIT_ASSERT_EQUAL(aa[2], bb[0]); + } + + // template<int N> bool compare(const double* a, const double* b) + { + { + // aa < bb + double aa[8] = {1,1,1,1,1,1,1,1}; + double bb[8] = {1,1,1,1,1,1,1,2}; + CPPUNIT_ASSERT(compare<7>(aa, bb)); + } + + { + // aa < bb + double aa[8] = {1,1,1,1,1,1,1,1}; + double bb[8] = {2,1,1,1,1,1,1,1}; + CPPUNIT_ASSERT(compare<7>(aa, bb)); + } + + { + // aa > bb + double aa[8] = {2,1,1,1,1,1,1,1}; + double bb[8] = {1,1,1,1,1,1,1,1}; + CPPUNIT_ASSERT(!compare<7>(aa, bb)); + } + + { + // aa == bb + double aa[8] = {1,1,1,1,1,1,1,1}; + double bb[8] = {1,1,1,1,1,1,1,1}; + CPPUNIT_ASSERT(!compare<7>(aa, bb)); + } + + { + // compare<-1> + double aa[8] = {2,1,1,1,1,1,1,1}; + double bb[8] = {1,1,1,1,1,1,1,1}; + CPPUNIT_ASSERT(!compare<-1>(aa, bb)); + } + } + + // Test ASCII_FIELD_DRIVER + FIELD<double> * aField1 = new FIELD<double> (MED_DRIVER, filename, fieldname); + const SUPPORT * aSupport = aField1->getSupport(); + MESH * aMesh = new MESH (MED_DRIVER, filename, aSupport->getMeshName()); + aSupport->setMesh(aMesh); + + // create an ASCII driver for a field + ASCII_FIELD_DRIVER<double> * aDriver1 = + new ASCII_FIELD_DRIVER<double> (anyfile1, aField1, MED_EN::ASCENDING, ""); + CPPUNIT_ASSERT(aDriver1); + + CPPUNIT_ASSERT(aDriver1->getFileName() == anyfile1); + CPPUNIT_ASSERT(aDriver1->getAccessMode() == MED_EN::MED_ECRI); + + // and write the field on disk + + // must throw because the file is not opened + + CPPUNIT_ASSERT_THROW(aDriver1->write(), MEDEXCEPTION); + + aDriver1->open(); + + // must throw because the file is opened + + CPPUNIT_ASSERT_THROW(aDriver1->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aDriver1->setFileName("anyfile2"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aDriver1->setFileName(anyfile1), MEDEXCEPTION); + + + // must throw because it is a writeonly driver + CPPUNIT_ASSERT_THROW(aDriver1->read(), MEDEXCEPTION); + + aDriver1->write(); + aDriver1->close(); + + // must throw because the file is not opened + + CPPUNIT_ASSERT_THROW(aDriver1->write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aDriver1->close(), MEDEXCEPTION); + + // check priority definition + int spaceDimension = aMesh->getSpaceDimension(); + if (spaceDimension == 3) { + // good + CPPUNIT_ASSERT_NO_THROW(ASCII_FIELD_DRIVER<double> aDriver2 + ("anyfile2", aField1, MED_EN::ASCENDING, "XYZ")); + // too long + CPPUNIT_ASSERT_THROW(ASCII_FIELD_DRIVER<double> aDriver3 + ("anyfile3", aField1, MED_EN::ASCENDING, "XYZX"), MEDEXCEPTION); + // too short + CPPUNIT_ASSERT_THROW(ASCII_FIELD_DRIVER<double> aDriver4 + ("anyfile4", aField1, MED_EN::ASCENDING, "XY"), MEDEXCEPTION); + // invalid +#ifdef ENABLE_FORCED_FAILURES + // (BUG) This assert fails because 'A'(and 'B', and 'C') < 'X' + CPPUNIT_ASSERT_THROW(ASCII_FIELD_DRIVER<double> aDriver5 + ("anyfile5", aField1, MED_EN::ASCENDING, "ABC"), MEDEXCEPTION); +#endif + } + else if (spaceDimension == 2) { + // good + CPPUNIT_ASSERT_NO_THROW(ASCII_FIELD_DRIVER<double> aDriver2 + ("anyfile2", aField1, MED_EN::ASCENDING, "XY")); + // too long + CPPUNIT_ASSERT_THROW(ASCII_FIELD_DRIVER<double> aDriver3 + ("anyfile3", aField1, MED_EN::ASCENDING, "XYZ"), MEDEXCEPTION); + // too short + CPPUNIT_ASSERT_THROW(ASCII_FIELD_DRIVER<double> aDriver4 + ("anyfile4", aField1, MED_EN::ASCENDING, "X"), MEDEXCEPTION); + // invalid +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Invalid string is accepted for priority + CPPUNIT_ASSERT_THROW(ASCII_FIELD_DRIVER<double> aDriver5 + ("anyfile5", aField1, MED_EN::ASCENDING, "AB"), MEDEXCEPTION); +#endif + } + else { + CPPUNIT_FAIL("Cannot test ASCII_FIELD_DRIVER because file pointe.med" + " contains mesh of wrong dimension: must be 2 or 3"); + } + + //Copy constructor + ASCII_FIELD_DRIVER<double> aDriver1_Cpy1 = ASCII_FIELD_DRIVER<double> (*aDriver1); + + //Test copy() function + ASCII_FIELD_DRIVER<double> *aDriver1_Cpy2 = (ASCII_FIELD_DRIVER<double>*)aDriver1->copy(); + + //Compare objects +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_EQUAL(aDriver1_Cpy1, *aDriver1); + CPPUNIT_ASSERT_EQUAL(*aDriver1_Cpy2, *aDriver1); +#endif + + // free memory + delete aDriver1; + delete aField1; + delete aMesh; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Connectivity.cxx b/src/MEDMEM/Test/MEDMEMTest_Connectivity.cxx new file mode 100644 index 000000000..a770abde7 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Connectivity.cxx @@ -0,0 +1,1745 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Connectivity.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #7: MEDMEM_Connectivity.hxx } MEDMEMTest_Connectivity.cxx + +/*! + * Check methods (56), defined in MEDMEM_Connectivity.hxx: + * class CONNECTIVITY { + * (+) friend ostream & operator<<(ostream &os, CONNECTIVITY &connectivity); + * (+) CONNECTIVITY (MED_EN::medEntityMesh Entity=MED_EN::MED_CELL); + * (+) CONNECTIVITY (int numberOfTypes, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL); + * (+) CONNECTIVITY (const CONNECTIVITY & m); + * (+) virtual ~CONNECTIVITY (); + * (+) void setConstituent (CONNECTIVITY * Constituent) throw (MEDEXCEPTION); + * (+) void setGeometricTypes (const MED_EN::medGeometryElement * Types, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setCount (const int * Count, const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setNodal (const int * Connectivity, + * const MED_EN::medEntityMesh Entity, + * const MED_EN::medGeometryElement Type) throw (MEDEXCEPTION); + * (+) inline void setNumberOfNodes(int NumberOfNodes); + * (+) inline int getEntityDimension() const; + * (+) inline void setEntityDimension(int EntityDimension); + * ----------------------------------------------------------------------------------------------------- + * (+) void setPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * const int* PolygonsConnectivity, + * const int* PolygonsConnectivityIndex, + * int ConnectivitySize, int NumberOfPolygons); + * (+) void setPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType, + * const int* PolyhedronConnectivity, + * const int* PolyhedronIndex, int ConnectivitySize, + * int NumberOfPolyhedron, + * const int* PolyhedronFacesIndex= (int*) NULL, + * int NumberOfFaces=0); + * ----------------------------------------------------------------------------------------------------- + * (+) inline bool existConnectivity (MED_EN::medConnectivity connectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) virtual bool existPolygonsConnectivity(MED_EN::medConnectivity connectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) virtual bool existPolyhedronConnectivity(MED_EN::medConnectivity connectivityType, + * MED_EN::medEntityMesh Entity) const; + * + * (+) virtual void calculateConnectivity (MED_EN::medConnectivity connectivityType, + * MED_EN::medEntityMesh Entity); + * (?) virtual void updateFamily (const vector<FAMILY*>& myFamilies); + * + * (+) inline MED_EN::medEntityMesh getEntity() const; + * ----------------------------------------------------------------------------------------------------- + * (+) inline int getNumberOfTypes (MED_EN::medEntityMesh Entity) const; + * (+) int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) const int * getConnectivityOfAnElementWithPoly + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity, int Number, int &lgth); + * (+) int getNumberOfPolyType() const; + * (+) int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) int getNumberOfElementOfPolyType(MED_EN::medEntityMesh Entity) const; + * ----------------------------------------------------------------------------------------------------- + * (+) inline const MED_EN::medGeometryElement * getGeometricTypes + * (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * (+) MED_EN::medGeometryElement * getGeometricTypesWithPoly + * (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * ----------------------------------------------------------------------------------------------------- + * (+) MED_EN::medGeometryElement getElementType (MED_EN::medEntityMesh Entity, int Number) const; + * (+) MED_EN::medGeometryElement getElementTypeWithPoly + * (MED_EN::medEntityMesh Entity, int Number) const; + * ----------------------------------------------------------------------------------------------------- + * (+) inline MED_EN::medGeometryElement getPolyTypeRelativeTo() const; + * ----------------------------------------------------------------------------------------------------- + * (+) virtual inline const int * getGlobalNumberingIndex + * (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * ----------------------------------------------------------------------------------------------------- + * (+) virtual const int * getConnectivity (MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type); + * (+) virtual int getConnectivityLength (MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type); + * (+) virtual const int * getConnectivityIndex (MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity); + * ----------------------------------------------------------------------------------------------------- + * (+) virtual const int* getPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity); + * (+) virtual const int* getPolygonsConnectivityIndex(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity); + * (+) virtual int getNumberOfPolygons(MED_EN::medEntityMesh Entity=MED_EN::MED_ALL_ENTITIES) const; + * ----------------------------------------------------------------------------------------------------- + * (+) virtual const int* getPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType) const; + * (+) virtual const int* getPolyhedronFacesIndex() const; + * (+) virtual const int* getPolyhedronIndex(MED_EN::medConnectivity ConnectivityType) const; + * (+) virtual int getNumberOfPolyhedronFaces() const; + * (+) virtual int getNumberOfPolyhedron() const; + * (+) int *getNodesOfPolyhedron(int polyhedronId, int& lgthOfTab) const; + * (+) int **getNodesPerFaceOfPolyhedron(int polyhedronId, int& nbOfFaces, + * int* & nbOfNodesPerFaces) const; + * ----------------------------------------------------------------------------------------------------- + * (+) const CELLMODEL & getType (MED_EN::medGeometryElement Type) const; + * (+) const CELLMODEL * getCellsTypes (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * (+) string * getCellTypeNames (MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * (+) int getNumberOfNodesInType (MED_EN::medGeometryElement Type) const; + * (+) int getNumberOfSubCellInType (MED_EN::medGeometryElement Type) const; + * ----------------------------------------------------------------------------------------------------- + * (+) virtual int getNumberOf (MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * ----------------------------------------------------------------------------------------------------- + * (+) virtual const int* getValue (MED_EN::medConnectivity TypeConnectivity, + * MED_EN::medGeometryElement Type); + * (+) virtual const int* getValueIndex (MED_EN::medConnectivity TypeConnectivity); + * ----------------------------------------------------------------------------------------------------- + * (+) virtual inline const int* getReverseConnectivity (MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) throw (MEDEXCEPTION); + * (+) virtual inline const int* getReverseConnectivityIndex (MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) throw (MEDEXCEPTION); + * (NOT YET IMPLEMENTED!!!) const int* getNeighbourhood() const; + * (+) void invertConnectivityForAFace(int faceId, const int *nodalConnForFace, bool polygonFace=false); + * ----------------------------------------------------------------------------------------------------- + * (+) bool deepCompare(const CONNECTIVITY& other) const; + * + * Use code of MEDMEM/test_MEDMEM_PolyConnectivity.cxx + * MEDMEM/test_copie_connectivity.cxx + * } + */ +void showConnectivity(CONNECTIVITY * myConnectivity, + int MeshDimension, int NumberOfNodes, MED_EN::medEntityMesh Entity, + int NumberOfTypes) +{ + int entityDim = myConnectivity->getEntityDimension(); + CPPUNIT_ASSERT_EQUAL(MeshDimension, entityDim); //? + + //int nodesNb = myConnectivity->getNumberOfElements(MED_EN::MED_NODE, MED_EN::MED_NONE); + int nodesNb = myConnectivity->getNumberOfElementsWithPoly(MED_EN::MED_NODE, MED_EN::MED_NONE); + CPPUNIT_ASSERT_EQUAL(NumberOfNodes, nodesNb); //? + + // MED_EN::MED_CELL + MED_EN::medEntityMesh entity = myConnectivity->getEntity(); + CPPUNIT_ASSERT_EQUAL(Entity, entity); + + int typesNb = myConnectivity->getNumberOfTypes(Entity); + CPPUNIT_ASSERT_EQUAL(NumberOfTypes, typesNb); + + const MED_EN::medGeometryElement * Types = myConnectivity->getGeometricTypes(Entity); + + // Show Nodal Connectivity + cout << "Show Nodal Connectivity :" << endl; + for (int i = 0; i < NumberOfTypes; i++) { + cout << "For type " << Types[i] << " : " << endl; + int NumberOfElements = myConnectivity->getNumberOf(Entity, Types[i]); + const int * connectivity = + myConnectivity->getConnectivity(MED_EN::MED_NODAL, Entity, Types[i]); + int NomberOfNodesPerCell = Types[i]%100; + for (int j = 0; j < NumberOfElements; j++) { + cout << "Element " << j+1 << " : "; + for (int k = 0; k < NomberOfNodesPerCell; k++) { + cout << connectivity[j*NomberOfNodesPerCell + k] << " "; + } + cout << endl; + } + } + + // Show Reverse Nodal Connectivity + cout << "Show Reverse Nodal Connectivity :" << endl; + const int * ReverseNodalConnectivity = + myConnectivity->getReverseConnectivity(MED_EN::MED_NODAL, Entity); + const int * ReverseNodalConnectivityIndex = + myConnectivity->getReverseConnectivityIndex(MED_EN::MED_NODAL, Entity); + for (int i = 0; i < NumberOfNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + // Show Descending Connectivity + cout << "Show Connectivity (Descending) :" << endl; + int NumberOfElements; + const int * connectivity; + const int * connectivity_index; + myConnectivity->calculateConnectivity(MED_EN::MED_DESCENDING, Entity); + try { + NumberOfElements = myConnectivity->getNumberOf(Entity, MED_EN::MED_ALL_ELEMENTS); + connectivity = myConnectivity->getConnectivity(MED_EN::MED_DESCENDING, Entity, + MED_EN::MED_ALL_ELEMENTS); + connectivity_index = myConnectivity->getConnectivityIndex(MED_EN::MED_DESCENDING, Entity); + } + catch (MEDEXCEPTION m) { + CPPUNIT_FAIL(m.what()); + } + + for (int j = 0; j < NumberOfElements; j++) { + cout << "Element " << j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + + // Get constituent entity type and quantity + int NumberOfConstituents = 0; + string constituent; + MED_EN::medEntityMesh constituentEntity; + + if (MeshDimension == 3) { + constituent = "Face"; + constituentEntity = MED_EN::MED_FACE; + } + + if (MeshDimension == 2) { + constituent = "Edge"; + constituentEntity = MED_EN::MED_EDGE; + } + + if (MeshDimension == 1) { + MESSAGE("ERROR : MeshDimension = 1 !"); + MESSAGE("We could not see Reverse Descending Connectivity."); + return; + } + + // Show Reverse Descending Connectivity + cout << "Show Reverse Descending Connectivity :" << endl; + const int * ReverseDescendingConnectivity = + myConnectivity->getReverseConnectivity(MED_EN::MED_DESCENDING, Entity); + const int * ReverseDescendingConnectivityIndex = + myConnectivity->getReverseConnectivityIndex(MED_EN::MED_DESCENDING, Entity); + + NumberOfConstituents = myConnectivity->getNumberOf(constituentEntity, MED_EN::MED_ALL_ELEMENTS); + for (int i = 0; i < NumberOfConstituents; i++) { + cout << constituent << i+1 << " : "; + for (int j = ReverseDescendingConnectivityIndex[i]; + j < ReverseDescendingConnectivityIndex[i+1]; j++) { + cout << ReverseDescendingConnectivity[j-1] << " "; + } + cout << endl; + } + + // Show <constituent> Nodal Connectivity + cout << "Show " << constituent << " Connectivity (Nodal) :" << endl; + const int * face_connectivity = + myConnectivity->getConnectivity(MED_EN::MED_NODAL, constituentEntity, MED_EN::MED_ALL_ELEMENTS); + const int * face_connectivity_index = + myConnectivity->getConnectivityIndex(MED_EN::MED_NODAL, constituentEntity); + for (int i = 0; i < NumberOfConstituents; i++) { + cout << constituent << i+1 << " : "; + for (int j = face_connectivity_index[i]; j < face_connectivity_index[i+1]; j++) + cout << face_connectivity[j-1] << " "; + cout << endl; + } +} + +///////////////////////////////////////// +// TEST 2: test_copie_connectivity.cxx // +///////////////////////////////////////// +void checkCopyConnectivity() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + + //Construction d'un maillage + MESH * myMesh = new MESH(); + myMesh->setName(meshname); + MED_MESH_RDONLY_DRIVER myMeshDriver (filename, myMesh); + myMeshDriver.setMeshName(meshname); + myMeshDriver.open(); + myMeshDriver.read(); //A partir d'ici la connectivitĂ© est construite + myMeshDriver.close(); + + int aMeshDimension = myMesh->getMeshDimension(); + int aNumberOfNodes = myMesh->getNumberOfNodes(); + + const CONNECTIVITY * myConnectivity0 = myMesh->getConnectivityptr(); + CONNECTIVITY * myConnectivity1 = const_cast<CONNECTIVITY *>(myConnectivity0); + + // DATA: + MED_EN::medEntityMesh anEntity0 = myConnectivity0->getEntity(); + + int nbOfTypes = myConnectivity0->getNumberOfTypes(anEntity0); + + // Show + cout << "myConnectivity1 BEGIN" << endl; + cout << *myConnectivity1 << endl; + cout << "myConnectivity1 END" << endl; + showConnectivity(myConnectivity1, aMeshDimension, aNumberOfNodes, anEntity0, nbOfTypes); + cout << "myConnectivity1 END 2" << endl; + + ostringstream ostr1; + ostr1 << *myConnectivity1; + CPPUNIT_ASSERT(ostr1.str() != ""); + + // COPY + CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity0); + + // Compare + CPPUNIT_ASSERT(myConnectivity2->deepCompare(*myConnectivity0)); + + // Compare after deleting the initial connectivity + delete myMesh; + myMesh = NULL; + myConnectivity0 = NULL; + + MED_EN::medEntityMesh anEntity2 = myConnectivity2->getEntity(); + CPPUNIT_ASSERT_EQUAL(anEntity0, anEntity2); + + cout << "myConnectivity2 BEGIN" << endl; + cout << *myConnectivity2 << endl; + cout << "myConnectivity2 END" << endl; + showConnectivity(myConnectivity2, aMeshDimension, aNumberOfNodes, anEntity0, nbOfTypes); + cout << "myConnectivity2 END 2" << endl; + + ostringstream ostr2; + ostr2 << *myConnectivity2; + CPPUNIT_ASSERT(ostr1.str() == ostr2.str()); + + // ONE MORE COPY + CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2); + delete myConnectivity2; + + MED_EN::medEntityMesh anEntity3 = myConnectivity3->getEntity(); + CPPUNIT_ASSERT_EQUAL(anEntity0, anEntity3); + + cout << "myConnectivity3 BEGIN" << endl; + cout << *myConnectivity3 << endl; + cout << "myConnectivity3 END" << endl; + showConnectivity(myConnectivity3, aMeshDimension, aNumberOfNodes, anEntity0, nbOfTypes); + cout << "myConnectivity3 END 2" << endl; + + ostringstream ostr3; + ostr3 << *myConnectivity3; + CPPUNIT_ASSERT_EQUAL(ostr1.str(), ostr3.str()); + + delete myConnectivity3; +} + +void createOrCheck (CONNECTIVITY * theC, string msg, bool create = false) +{ + // Preconditions: Entity and NumberOfTypes + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_CELL, theC->getEntity()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_CELL)); + + // EntityDimension + if (create) + // It would be good to set EntityDimension automatically for EDGEs and FACEs, + // and warn about not set EntityDimension for CELLs + // (or calculate it from given geometric types) + theC->setEntityDimension(3); + else + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 3, theC->getEntityDimension()); + + // NumberOfNodes + int nbNodes = 20; + + if (create) { + theC->setNumberOfNodes(nbNodes); + } + else { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nbNodes, theC->getNumberOfElementsWithPoly + (MED_EN::MED_NODE, MED_EN::MED_NONE)); + } + + // GeometricTypes + MED_EN::medGeometryElement aCellTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_HEXA8}; + + // this variable is needed in check mode (!create) + // because of bug with getGlobalNumberingIndex() method (see below) + bool triaFirst = true; + + if (create) { + theC->setGeometricTypes(aCellTypes, MED_EN::MED_CELL); + CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_NODE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_FACE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_EDGE), MEDEXCEPTION); + } + else { + // CELLS: theC + const MED_EN::medGeometryElement * aCellTypesBack = theC->getGeometricTypes(MED_EN::MED_CELL); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aCellTypes[0], aCellTypesBack[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aCellTypes[1], aCellTypesBack[1]); + + const CELLMODEL * aCellModels = theC->getCellsTypes(MED_EN::MED_CELL); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aCellTypes[0], aCellModels[0].getType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aCellTypes[1], aCellModels[1].getType()); + + string * aCellTypesNames = theC->getCellTypeNames(MED_EN::MED_CELL); + CPPUNIT_ASSERT_MESSAGE(msg, aCellTypesNames[0] == "MED_PYRA5"); + CPPUNIT_ASSERT_MESSAGE(msg, aCellTypesNames[1] == "MED_HEXA8"); + + // FACES: theC->_constituent + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_FACE)); + const MED_EN::medGeometryElement * aFaceTypesBack = theC->getGeometricTypes(MED_EN::MED_FACE); + triaFirst = (aFaceTypesBack[0] == MED_EN::MED_TRIA3 && aFaceTypesBack[1] == MED_EN::MED_QUAD4); + CPPUNIT_ASSERT_MESSAGE(msg, triaFirst || (aFaceTypesBack[1] == MED_EN::MED_TRIA3 && + aFaceTypesBack[0] == MED_EN::MED_QUAD4)); + + const CELLMODEL * aFaceModels = theC->getCellsTypes(MED_EN::MED_FACE); + bool case1 = (aFaceModels[0].getType() == MED_EN::MED_TRIA3 && + aFaceModels[1].getType() == MED_EN::MED_QUAD4); + bool case2 = (aFaceModels[1].getType() == MED_EN::MED_TRIA3 && + aFaceModels[0].getType() == MED_EN::MED_QUAD4); + CPPUNIT_ASSERT_MESSAGE(msg, case1 || case2); + + string * aFaceTypesNames = theC->getCellTypeNames(MED_EN::MED_FACE); + CPPUNIT_ASSERT_MESSAGE(msg, + (aFaceTypesNames[0] == "MED_TRIA3" && aFaceTypesNames[1] == "MED_QUAD4") || + (aFaceTypesNames[1] == "MED_TRIA3" && aFaceTypesNames[0] == "MED_QUAD4")); + + // EDGES: theC->_constituent->_constituent + //CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, theC->getNumberOfTypes(MED_EN::MED_EDGE)); + //const MED_EN::medGeometryElement * anEdgeTypesBack = theC->getGeometricTypes(MED_EN::MED_EDGE); + //const CELLMODEL * anEdgeModels = theC->getCellsTypes(MED_EN::MED_EDGE); + + // invalid cases + CPPUNIT_ASSERT_THROW(theC->getGeometricTypes(MED_EN::MED_NODE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getGeometricTypes(MED_EN::MED_ALL_ENTITIES), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getCellsTypes(MED_EN::MED_NODE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getCellTypeNames(MED_EN::MED_ALL_ENTITIES), MEDEXCEPTION); + } + + // Nodal Connectivity for standard types + int countCells[3] = {1, 3, 4}; // 2 PYRA5 and 1 HEXA8 + int nodesCells_PYRA5[10] = {2,3,4,5,1, 6,7,8,9,10}; + int nodesCells_HEXA8[8] = {2,3,4,5, 6,7,8,9}; + + // .1 + // + // 3.---------.4 + // /| /| + // / | / | + // / | / | + // 2.---------.5 | + // | | | | + // | 7.-----|---.8 + // | / | / + // | / | / + // |/ |/ + // 6.---------.9 + // + // .10 + + // cells index will be: {1, 6, 11, 19} + + if (create) { + theC->setCount(countCells, MED_EN::MED_CELL); + theC->setNodal(nodesCells_PYRA5, MED_EN::MED_CELL, MED_EN::MED_PYRA5); + theC->setNodal(nodesCells_HEXA8, MED_EN::MED_CELL, MED_EN::MED_HEXA8); + + // Invalid cases + CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_NODE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_EDGE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_FACE), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(theC->setNodal(nodesCells_PYRA5, MED_EN::MED_FACE, MED_EN::MED_PYRA5), MEDEXCEPTION); + } + else { + // CELLS(3D): theC + CPPUNIT_ASSERT_MESSAGE(msg, theC->existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT_MESSAGE(msg, theC->existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOf(MED_EN::MED_CELL, MED_EN::MED_PYRA5)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, theC->getNumberOf(MED_EN::MED_CELL, MED_EN::MED_HEXA8)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 3, theC->getNumberOf(MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfElementsWithPoly(MED_EN::MED_CELL, + MED_EN::MED_PYRA5)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, theC->getNumberOfElementsWithPoly(MED_EN::MED_CELL, + MED_EN::MED_HEXA8)); + + // sorted by geometric type (order is given by the typedef enum medGeometryElement) + const int * countCellsBack = theC->getGlobalNumberingIndex(MED_EN::MED_CELL); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, countCells[0], countCellsBack[0]); // 1: always + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, countCells[1], countCellsBack[1]); // 3: +2 PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, countCells[2], countCellsBack[2]); // 4: +1 HEXA8 + + // nodal connectivity length + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 18, theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 10, theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_PYRA5)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_HEXA8)); + + // nodal connectivity index + const int * connAllIndex = theC->getConnectivityIndex(MED_EN::MED_NODAL, MED_EN::MED_CELL); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, connAllIndex[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, connAllIndex[1]); // +5 nodes of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 11, connAllIndex[2]); // +5 nodes of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 19, connAllIndex[3]); // +8 nodes of HEXA8 + + // nodal connectivity + const int * connAll = theC->getConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_ALL_ELEMENTS); + const int * connPYRA5 = theC->getConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_PYRA5); + const int * connHEXA8 = theC->getConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_HEXA8); + for (int i = 0; i < 10; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_PYRA5[i], connPYRA5[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_PYRA5[i], connAll[i]); + } + for (int i = 0; i < 8; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_HEXA8[i], connHEXA8[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_HEXA8[i], connAll[10 + i]); + } + + // descending connectivity length + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 16, theC->getConnectivityLength + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 10, theC->getConnectivityLength + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_PYRA5)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, theC->getConnectivityLength + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_HEXA8)); + + // descending connectivity index + const int * descAllIndex = theC->getConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, descAllIndex[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, descAllIndex[1]); // +5 faces of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 11, descAllIndex[2]); // +5 faces of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 17, descAllIndex[3]); // +6 faces of HEXA8 + + // descending connectivity + { + const int * descAll = theC->getConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL, + MED_EN::MED_ALL_ELEMENTS); + const int * descPYRA5 = theC->getConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL, + MED_EN::MED_PYRA5); + const int * descHEXA8 = theC->getConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL, + MED_EN::MED_HEXA8); + for (int i = 0; i < 10; i++) { + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(descPYRA5[i]) && labs(descPYRA5[i]) < 16); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, descAll[i], descPYRA5[i]); + } + for (int i = 0; i < 6; i++) { + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(descHEXA8[i]) && labs(descHEXA8[i]) < 16); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, descAll[10 + i], descHEXA8[i]); + } + } + + // FACES: theC->_constituent + CPPUNIT_ASSERT_MESSAGE(msg, theC->existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE)); + //CPPUNIT_ASSERT_MESSAGE(msg, theC->existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_FACE)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, theC->getNumberOf(MED_EN::MED_FACE, MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, theC->getNumberOf(MED_EN::MED_FACE, MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 14, theC->getNumberOf(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS)); + + // sorted by geometric type + const int * countFacesBack = theC->getGlobalNumberingIndex(MED_EN::MED_FACE); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, countFacesBack[0]); // always + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 9, countFacesBack[1]); // +8 TRIA3 + + // check correspondance with types + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, triaFirst ? 9 : 7, countFacesBack[1]); // +8 TRIA3 or +6 QUAD4 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 15, countFacesBack[2]); // 1+8+6 + + // nodal connectivity length // 8*3 + 6*4 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 48, theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 24, theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 24, theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_QUAD4)); + + // nodal connectivity index + const int * connFaceAllIndex = theC->getConnectivityIndex(MED_EN::MED_NODAL, MED_EN::MED_FACE); + { + CPPUNIT_ASSERT(triaFirst); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, connFaceAllIndex[0]); + int typeChangeIndex = triaFirst ? 8 : 6; + int nbNodes1 = triaFirst ? 3 : 4; + int nbNodes2 = triaFirst ? 4 : 3; + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 25, connFaceAllIndex[typeChangeIndex]); // + 3*8 or 4*6 + for (int i = 1; i < 14; i++) { + if (i < typeChangeIndex) + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1 + i*nbNodes1, connFaceAllIndex[i]); + else + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 25 + (i-typeChangeIndex)*nbNodes2, connFaceAllIndex[i]); + } + // + 3*8 nodes of TRIA3 + 4*6 nodes of QUAD4 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 49, connFaceAllIndex[14]); + } + + // nodal connectivity + const int * connFaceAll = theC->getConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_ALL_ELEMENTS); + const int * connTRIA3 = theC->getConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_TRIA3); + const int * connQUAD4 = theC->getConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_QUAD4); + for (int i = 0; i < 24; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, connFaceAll[ i], triaFirst ? connTRIA3[i] : connQUAD4[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, connFaceAll[24+i], triaFirst ? connQUAD4[i] : connTRIA3[i]); + } + + // EDGES: theC->_constituent->_constituent + //CPPUNIT_ASSERT_MESSAGE(msg, theC->existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_EDGE)); + + // Invalid cases + CPPUNIT_ASSERT_MESSAGE(msg, !theC->existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_NODE)); + CPPUNIT_ASSERT_MESSAGE(msg, !theC->existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_EDGE)); + CPPUNIT_ASSERT_MESSAGE(msg, !theC->existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_NODE)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 0, theC->getNumberOf(MED_EN::MED_CELL, MED_EN::MED_TETRA4)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 0, theC->getNumberOfElementsWithPoly(MED_EN::MED_CELL, + MED_EN::MED_TETRA4)); + CPPUNIT_ASSERT_THROW(theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_CELL, + MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getConnectivityLength(MED_EN::MED_DESCENDING, MED_EN::MED_CELL, + MED_EN::MED_NONE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getConnectivityLength(MED_EN::MED_NODAL, MED_EN::MED_FACE, + MED_EN::MED_POLYGON), MEDEXCEPTION); + } + + // 2 POLYHEDRA + const int nbPolyhedron = 2; + const int nbPolyFaces = 14; + const int nbPolyNodes = 52; + + int aPolyhedronIndex[nbPolyhedron + 1] = {1,8,15}; + + int aPolyhedronFacesIndex[nbPolyFaces + 1] = {1,7,10,14,17,20,24, 27,33,36,40,43,46,50,53}; + + int aPolyhedronNodalConnectivity[nbPolyNodes] = { + 11,15,19,20,17,13, 11,13,14, 14,13,17,18, 18,17,20, 11,14,15, 15,14,18,19, 19,18,20, + 11,13,17,20,19,15, 11,12,13, 13,12,16,17, 17,16,20, 11,15,12, 12,15,19,16, 16,19,20}; + + // .11 + // + // 13.---------.14 + // /|\ /| + // / | \ / | + // / | \ / | + // 12.---------.15 | + // | | | | + // | 17.-----|---.18 + // | / \ | / + // | / \ | / + // |/ \|/ + // 16.---------.19 + // + // .20 + + if (create) { + theC->setPolyhedronConnectivity(MED_EN::MED_NODAL, aPolyhedronNodalConnectivity, + aPolyhedronIndex, nbPolyNodes, nbPolyhedron, + aPolyhedronFacesIndex, nbPolyFaces); + } + else { + // CELLS(3D): theC + { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, theC->getNumberOfPolyType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 3, theC->getNumberOfTypesWithPoly(MED_EN::MED_CELL)); + + { + const MED_EN::medGeometryElement * aCellTypesBack = theC->getGeometricTypesWithPoly(MED_EN::MED_CELL); + CPPUNIT_ASSERT_MESSAGE(msg, ((aCellTypesBack[0] == MED_EN::MED_PYRA5 && + aCellTypesBack[1] == MED_EN::MED_HEXA8) || + (aCellTypesBack[0] == MED_EN::MED_HEXA8 && + aCellTypesBack[1] == MED_EN::MED_PYRA5))); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_POLYHEDRA, aCellTypesBack[2]); + } + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfElementOfPolyType(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfElementsWithPoly(MED_EN::MED_CELL, + MED_EN::MED_POLYHEDRA)); + //checking that 0 is returned if polygons are asked as cells instead of faces + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 0, theC->getNumberOfElementsWithPoly(MED_EN::MED_CELL, + MED_EN::MED_POLYGON)); + + + int nbCellAll = 5; // 2 (PYRA5) + 1 (HEXA8) + 2 (POLYHEDRA) + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nbCellAll, theC->getNumberOfElementsWithPoly + (MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS)); + + + // first PYRA5 {1,2,3,4,5} + { + int len; + const int * c1 = theC->getConnectivityOfAnElementWithPoly + (MED_EN::MED_NODAL, MED_EN::MED_CELL, /*Number*/1, len); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 5, len); + for (int i = 0; i < len; i++) { + if (c1[i] < 1 || 5 < c1[i]) CPPUNIT_FAIL(msg); + } + } + + // first POLYHEDRA + // This throws "NODAL Connectivity required for a polyhedron" + // Why? Because for polyhedron this has no sence without index? + { + int len; + CPPUNIT_ASSERT_THROW(theC->getConnectivityOfAnElementWithPoly + (MED_EN::MED_NODAL, MED_EN::MED_CELL, /*Number*/4, len), MEDEXCEPTION); + } + + // cells descending connectivity + for (int i = 1; i <= nbCellAll; i++) { + int len; + const int * ci = theC->getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/i, len); + + MED_EN::medGeometryElement aCurElemTypeWithPoly = theC->getElementTypeWithPoly(MED_EN::MED_CELL, i); + + if (i <= 3) { // nb.standard cells = 3 + MED_EN::medGeometryElement aCurElemType = theC->getElementType(MED_EN::MED_CELL, i); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aCurElemType, aCurElemTypeWithPoly); + // sign of connectivity array value means element direction + for (int j = 0; j < len; j++) { + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(ci[j]) && labs(ci[j]) <= 14); // nb.standard faces = 14 + } + } + else { + CPPUNIT_ASSERT_THROW(theC->getElementType(MED_EN::MED_CELL, i), MEDEXCEPTION); + for (int j = 0; j < len; j++) { + CPPUNIT_ASSERT_MESSAGE(msg, 14 < labs(ci[j]) && labs(ci[j]) <= 27); // nb.polygons = 13 + } + } + + switch (aCurElemTypeWithPoly) { + case MED_EN::MED_PYRA5: CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 5, len); break; + case MED_EN::MED_HEXA8: CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, len); break; + case MED_EN::MED_POLYHEDRA: CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 7, len); break; + default: + CPPUNIT_FAIL(msg); // wrong element type + } + } + + // Polyhedron-specific methods + { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfPolyhedron()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 14, theC->getNumberOfPolyhedronFaces()); + + // Nodal + + // PolyhedronIndex: array of size (NumberOfPolyhedron + 1) + const int* polyhNodalIndex = theC->getPolyhedronIndex(MED_EN::MED_NODAL); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, polyhNodalIndex[0]); // always + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, polyhNodalIndex[1]); // +7 faces + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 15, polyhNodalIndex[2]); // +7 faces (= NumberOfPolyhedronFaces + 1) + + // PolyhedronFacesIndex: array of size (NumberOfPolyhedronFaces + 1) + const int* polyhFacesIndex = theC->getPolyhedronFacesIndex(); + // 1, 7,10,14,17,20,24,27, 33,36,40,43,46,50,53 + for (int i = 0; i <= 14; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aPolyhedronFacesIndex[i], polyhFacesIndex[i]); + } + + // Polyhedron Nodal Connectivity: array of size (NumberOfPolyhedronNodes) + int nbPolyhNodes = polyhFacesIndex[14] - 1; + const int* polyhNodalConn = theC->getPolyhedronConnectivity(MED_EN::MED_NODAL); + // 11,15,19,20,17,13, 11,13,14, 14,13,17,18, 18,17,20, 11,14,15, 15,14,18,19, 19,18,20, + // 11,13,17,20,19,15, 11,12,13, 13,12,16,17, 17,16,20, 11,15,12, 12,15,19,16, 16,19,20 + for (int i = 0; i < nbPolyhNodes; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aPolyhedronNodalConnectivity[i], polyhNodalConn[i]); + } + + // getNodesOfPolyhedron + int lenPolyh1nodes, lenPolyh2nodes; + int * polyh1nodes = theC->getNodesOfPolyhedron(/*polyhedronId*/3+1, lenPolyh1nodes); + int * polyh2nodes = theC->getNodesOfPolyhedron(/*polyhedronId*/3+2, lenPolyh2nodes); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, lenPolyh1nodes); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, lenPolyh2nodes); + + set<int> polyh1nodesCheck; + set<int> polyh2nodesCheck; + + polyh1nodesCheck.insert(11); + polyh1nodesCheck.insert(13); + polyh1nodesCheck.insert(14); + polyh1nodesCheck.insert(15); + polyh1nodesCheck.insert(17); + polyh1nodesCheck.insert(18); + polyh1nodesCheck.insert(19); + polyh1nodesCheck.insert(20); + + polyh2nodesCheck.insert(11); + polyh2nodesCheck.insert(12); + polyh2nodesCheck.insert(13); + polyh2nodesCheck.insert(15); + polyh2nodesCheck.insert(16); + polyh2nodesCheck.insert(17); + polyh2nodesCheck.insert(19); + polyh2nodesCheck.insert(20); + + for (int i = 0; i < 8; i++) { + CPPUNIT_ASSERT_MESSAGE(msg, polyh1nodesCheck.count(polyh1nodes[i])); + CPPUNIT_ASSERT_MESSAGE(msg, polyh2nodesCheck.count(polyh2nodes[i])); + } + delete [] polyh1nodes; + delete [] polyh2nodes; + + // getNodesPerFaceOfPolyhedron + int nbFaces1, nbFaces2; + int *nbNodes1, *nbNodes2; // len = nb.faces (7) + int ** polyh1nodesPerFace = + theC->getNodesPerFaceOfPolyhedron(/*polyhedronId*/3+1, nbFaces1, nbNodes1); + int ** polyh2nodesPerFace = + theC->getNodesPerFaceOfPolyhedron(/*polyhedronId*/3+2, nbFaces2, nbNodes2); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 7, nbFaces1); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 7, nbFaces2); + + int nbNodesCheck [7] = {6,3,4,3,3,4,3}; + for (int i = 0; i < 7; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nbNodesCheck[i], nbNodes1[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nbNodesCheck[i], nbNodes2[i]); + + int startNode1 = aPolyhedronFacesIndex[0 + i] - 1; + int startNode2 = aPolyhedronFacesIndex[7 + i] - 1; + for (int j = 0; j < nbNodesCheck[i]; j++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aPolyhedronNodalConnectivity[startNode1 + j], + polyh1nodesPerFace[i][j]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aPolyhedronNodalConnectivity[startNode2 + j], + polyh2nodesPerFace[i][j]); + } + } + + delete [] nbNodes1; + delete [] nbNodes2; + delete [] polyh1nodesPerFace; + delete [] polyh2nodesPerFace; + + // invalid polyhedron Id + + int lenPolyh3nodes; + int nbFaces3; + int *nbNodes3; + + CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(1, lenPolyh3nodes), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(3+3, lenPolyh3nodes), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron + (/*polyhedronId*/1, nbFaces3, nbNodes3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron + (/*polyhedronId*/3+3, nbFaces3, nbNodes3), MEDEXCEPTION); + + + // Descending + + // PolyhedronIndex: array of size (NumberOfPolyhedron + 1) + const int* polyhDesceIndex = theC->getPolyhedronIndex(MED_EN::MED_DESCENDING); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, polyhDesceIndex[0]); // always + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, polyhDesceIndex[1]); // +7 faces + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 15, polyhDesceIndex[2]); // +7 faces + + // Polyhedron Descending Connectivity: array of size (NumberOfPolyhedronFaces) + const int* polyhDesceConn = theC->getPolyhedronConnectivity(MED_EN::MED_DESCENDING); + // 15,16,17,18,19,20,21, -15,22,23,24,25,26,27 + for (int i = 0; i < 14; i++) { + // nb. poly faces = 13, because one face is common for two polyhedra + // nb. standard faces < poly-face id <= 27 (27 = 14 + 13) + CPPUNIT_ASSERT_MESSAGE(msg, 14 < labs(polyhDesceConn[i]) <= 27); + } + } // Polyhedron-specific methods + + // Polygon-specific methods + { + // Invalid cases: no polygons for MED_CELL in theC + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 0, theC->getNumberOfPolygons(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 0, theC->getNumberOfPolygons(/*MED_EN::MED_ALL_ENTITIES*/)); + CPPUNIT_ASSERT_THROW(theC->getPolygonsConnectivity(MED_EN::MED_DESCENDING, + MED_EN::MED_CELL), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getPolygonsConnectivity(MED_EN::MED_NODAL, + MED_EN::MED_ALL_ENTITIES), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getPolygonsConnectivityIndex(MED_EN::MED_NODAL, + MED_EN::MED_CELL), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getPolygonsConnectivityIndex(MED_EN::MED_DESCENDING, + MED_EN::MED_ALL_ENTITIES), MEDEXCEPTION); + } + } // CELLS: theC + + // FACES: theC->_constituent + { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 3, theC->getNumberOfTypesWithPoly(MED_EN::MED_FACE)); + + const MED_EN::medGeometryElement * aFaceTypesBack = theC->getGeometricTypesWithPoly(MED_EN::MED_FACE); + CPPUNIT_ASSERT_MESSAGE(msg, ((aFaceTypesBack[0] == MED_EN::MED_TRIA3 && + aFaceTypesBack[1] == MED_EN::MED_QUAD4) || + (aFaceTypesBack[0] == MED_EN::MED_QUAD4 && + aFaceTypesBack[1] == MED_EN::MED_TRIA3))); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_POLYGON, aFaceTypesBack[2]); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 13, theC->getNumberOfElementOfPolyType(MED_EN::MED_FACE)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 0, theC->getNumberOfElementsWithPoly + (MED_EN::MED_FACE, MED_EN::MED_POLYHEDRA)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 13, theC->getNumberOfElementsWithPoly + (MED_EN::MED_FACE, MED_EN::MED_POLYGON)); + + int nbFaAll = 27; // 6 (QUAD4) + 8 (TRIA3) + 13 (POLYGON) + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nbFaAll, theC->getNumberOfElementsWithPoly + (MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS)); + + + bool isHexagon = false; + for (int i = 1; i <= nbFaAll; i++) { + int len; + const int * ci = theC->getConnectivityOfAnElementWithPoly(MED_EN::MED_NODAL, + MED_EN::MED_FACE, /*Number*/i, len); + MED_EN::medGeometryElement aCurElemTypeWithPoly = theC->getElementTypeWithPoly(MED_EN::MED_FACE, i); + + if (len == 6) { + CPPUNIT_ASSERT_MESSAGE(msg, !isHexagon); // because only one hexagon must exist + + // check nodes {11,15,19,20,17,13} + int nij; + for (int j = 0; j < len; j++) { + nij = ci[j]; + CPPUNIT_ASSERT_MESSAGE(msg, nij==11 || nij==15 || nij==19 || nij==20 || nij==17 || nij==13); + } + + isHexagon = true; + } + + if (i > 14) { // nb.standard faces = 14 + CPPUNIT_ASSERT_THROW(theC->getElementType(MED_EN::MED_FACE, i), MEDEXCEPTION); + } + else { + MED_EN::medGeometryElement aCurElemType = theC->getElementType(MED_EN::MED_FACE, i); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, aCurElemType, aCurElemTypeWithPoly); + } + + switch (aCurElemTypeWithPoly) { + case MED_EN::MED_TRIA3: CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 3, len); break; + case MED_EN::MED_QUAD4: CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 4, len); break; + case MED_EN::MED_POLYGON: CPPUNIT_ASSERT_MESSAGE(msg, len == 3 || len == 4 || len == 6); break; + default: + CPPUNIT_FAIL(msg); // wrong element type + } + } + CPPUNIT_ASSERT_MESSAGE(msg, isHexagon); // hexagon must exist + + // Polygon-specific methods + { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 13, theC->getNumberOfPolygons(MED_EN::MED_FACE)); + + const int * pgIndx = theC->getPolygonsConnectivityIndex(MED_EN::MED_NODAL, MED_EN::MED_FACE); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 47, pgIndx[13]); // = length of pgConn + 1 + + const int * pgConn = theC->getPolygonsConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE); + + // face # 1: 11 15 19 20 17 13 + // face # 2: 11 13 14 + // face # 3: 14 13 17 18 + // face # 4: 18 17 20 + // face # 5: 11 14 15 + // face # 6: 15 14 18 19 + // face # 7: 19 18 20 + // face # 8: 11 12 13 + // face # 9: 13 12 16 17 + // face # 10: 17 16 20 + // face # 11: 11 15 12 + // face # 12: 12 15 19 16 + // face # 13: 16 19 20 + + for (int i = 0; i < 13; i++) { + int startNode = pgIndx[i]; + int finishNode = pgIndx[i+1]; + // check nodes uniqueness inside one polygon + set<int> curNodes; + for (int j = startNode; j < finishNode; j++) { + CPPUNIT_ASSERT_MESSAGE(msg, (curNodes.insert(pgConn[j - 1])).second); + } + } + + //CPPUNIT_ASSERT_THROW(theC->getPolygonsConnectivity(MED_EN::MED_DESCENDING, + // MED_EN::MED_FACE), MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(theC->getPolygonsConnectivityIndex(MED_EN::MED_DESCENDING, + // MED_EN::MED_FACE), MEDEXCEPTION); + } + } // FACES: theC->_constituent + + // EDGES: theC->_constituent->_constituent + //CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypesWithPoly(MED_EN::MED_EDGE)); + } + + if (create) { + // force _constituent computation + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_FACE)); + + + //N-2 Connectivity not supported in MEDMEM + //CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, theC->getNumberOfTypes(MED_EN::MED_EDGE)); + + + cout << "^^^^^" << endl; + cout << *theC << endl; + cout << "^^^^^" << endl; + } + else { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_POLYHEDRA, theC->getPolyTypeRelativeTo()); + + // The following methods are not recursive, i.e. they return types + // of this connectivity, but do not return types of _constituent. + // And these methods do not work with poly-types. + + // getType + const CELLMODEL & aPYRA5_type = theC->getType(MED_EN::MED_PYRA5); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_PYRA5, aPYRA5_type.getType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 5, aPYRA5_type.getNumberOfVertexes()); + + const CELLMODEL & aHEXA8_type = theC->getType(MED_EN::MED_HEXA8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 8, aHEXA8_type.getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 3, aHEXA8_type.getDimension()); + // nb. of sub-faces (nb. of constituents with dimension = 3 - 1) + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, aHEXA8_type.getNumberOfConstituents(1)); + + CPPUNIT_ASSERT_THROW(theC->getType(MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getType(MED_EN::MED_POLYGON), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getType(MED_EN::MED_POLYHEDRA), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getType(MED_EN::MED_NONE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getType(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION); + + // getNumberOfNodesInType + int nbNodesInPYRA5 = theC->getNumberOfNodesInType(MED_EN::MED_PYRA5); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 5, nbNodesInPYRA5); + + CPPUNIT_ASSERT_THROW(theC->getNumberOfNodesInType(MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNumberOfNodesInType(MED_EN::MED_POLYGON), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNumberOfNodesInType(MED_EN::MED_NONE), MEDEXCEPTION); + + // getNumberOfSubCellInType + int nbFacesInHEXA8 = theC->getNumberOfSubCellInType(MED_EN::MED_HEXA8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, nbFacesInHEXA8); + + CPPUNIT_ASSERT_THROW(theC->getNumberOfSubCellInType(MED_EN::MED_QUAD4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNumberOfSubCellInType(MED_EN::MED_POLYHEDRA), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNumberOfSubCellInType(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION); + + // getValueIndex + const int* nodalIndex = theC->getValueIndex(MED_EN::MED_NODAL); + const int* desceIndex = theC->getValueIndex(MED_EN::MED_DESCENDING); + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, nodalIndex[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, nodalIndex[1]); // +5 nodes of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 11, nodalIndex[2]); // +5 nodes of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 19, nodalIndex[3]); // +8 nodes of HEXA8 + + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 1, desceIndex[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 6, desceIndex[1]); // +5 faces of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 11, desceIndex[2]); // +5 faces of PYRA5 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 17, desceIndex[3]); // +6 faces of HEXA8 + + // getValue + const int* nodalValue = theC->getValue(MED_EN::MED_NODAL, MED_EN::MED_ALL_ELEMENTS); + const int* nodalPYRA5 = theC->getValue(MED_EN::MED_NODAL, MED_EN::MED_PYRA5); + const int* nodalHEXA8 = theC->getValue(MED_EN::MED_NODAL, MED_EN::MED_HEXA8); + + for (int i = 0; i < 10; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_PYRA5[i], nodalPYRA5[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_PYRA5[i], nodalValue[i]); + } + for (int i = 0; i < 8; i++) { + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_HEXA8[i], nodalHEXA8[i]); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, nodesCells_HEXA8[i], nodalValue[10 + i]); + } + + const int* desceValue = theC->getValue(MED_EN::MED_DESCENDING, MED_EN::MED_ALL_ELEMENTS); + const int* descePYRA5 = theC->getValue(MED_EN::MED_DESCENDING, MED_EN::MED_PYRA5); + const int* desceHEXA8 = theC->getValue(MED_EN::MED_DESCENDING, MED_EN::MED_HEXA8); + + for (int i = 0; i < 10; i++) { + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(descePYRA5[i]) && labs(descePYRA5[i]) < 16); + + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(desceValue[i]) && labs(desceValue[i]) < 16); + } + for (int i = 0; i < 6; i++) { + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(desceHEXA8[i]) && labs(desceHEXA8[i]) < 16); + CPPUNIT_ASSERT_MESSAGE(msg, 0 < labs(desceValue[10 + i]) && labs(desceValue[10 + i]) < 16); + } + + CPPUNIT_ASSERT_THROW(theC->getValue(MED_EN::MED_NODAL, MED_EN::MED_QUAD4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getValue(MED_EN::MED_NODAL, MED_EN::MED_POLYHEDRA), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getValue(MED_EN::MED_DESCENDING, MED_EN::MED_NONE), MEDEXCEPTION); + } +} + +void MEDMEMTest::testConnectivity() +{ + ////////////////////////////////////////////// + // TEST 1: test_MEDMEM_PolyConnectivity.cxx // + ////////////////////////////////////////////// + CONNECTIVITY myNodalConnectivity; // one type + CONNECTIVITY myDesceConnectivity; // one type + + myNodalConnectivity.setEntityDimension(3); + myDesceConnectivity.setEntityDimension(3); + + + //POLYGONS + const int NumberOfPolygons = 2; + const int ConnectivitySize = 12; + int PolygonsConnectivityIndex[NumberOfPolygons+1] = {1,7,13}; + + + + //Nodal + int PolygonsNodalConnectivity[ConnectivitySize] = {1,2,3,4,5,10,10,5,6,7,8,9}; + + // myNodalConnectivity.setPolygonsConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE, +// PolygonsNodalConnectivity, +// PolygonsConnectivityIndex, ConnectivitySize, +// NumberOfPolygons); + + //Descending + int PolygonsDescendingConnectivity[ConnectivitySize] = {1,2,3,4,11,10,11,5,6,7,8,9}; + + myDesceConnectivity.setPolygonsConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_FACE, + PolygonsDescendingConnectivity, + PolygonsConnectivityIndex, ConnectivitySize, + NumberOfPolygons); + + //POLYHEDRON + const int NumberOfPolyhedron = 2; + int PolyhedronIndex[NumberOfPolyhedron+1] = {1,10,20}; + + //Nodal + const int NumberOfFaces = 19; + const int NumberOfNodes = 74; + int PolyhedronFacesIndex[NumberOfFaces+1] = + {1,7,11,15,19,23,27,31,34,39,44,48,52,55,58,61,64,68,72,75}; + int PolyhedronNodalConnectivity[NumberOfNodes] = + {1,2,3,4,5,6,1,7,8,2,2,8,9,3,4,3,9,10,5,4, + 10,11,6,5,11,12,1,6,12,7,7,12,8,10,9,8,12,11,13,14, + 15,3,2,13,2,8,16,14,13,16,17,15,14,17,15,17,18,15,18,9, + 3,15,9,2,3,9,8,8,9,17,16,9,18,17}; + + myNodalConnectivity.setPolyhedronConnectivity(MED_EN::MED_NODAL, PolyhedronNodalConnectivity, + PolyhedronIndex, NumberOfNodes, NumberOfPolyhedron, + PolyhedronFacesIndex, NumberOfFaces); + + + //Descending + const int DescendingConnectivitySize = 19; + int PolyhedronDescendingConnectivity[DescendingConnectivitySize] = + {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,3,17,18}; + + myDesceConnectivity.setPolyhedronConnectivity(MED_EN::MED_DESCENDING, + PolyhedronDescendingConnectivity, + PolyhedronIndex, DescendingConnectivitySize, + NumberOfPolyhedron); + + cout << "Poly NodalConnectivity:" << endl; + cout << myNodalConnectivity; + cout << "Poly NodalConnectivity END" << endl; + cout << "Poly DescendingConnectivity:" << endl; + cout << myDesceConnectivity; + cout << "Poly DescendingConnectivity END" << endl; + + myNodalConnectivity.setNumberOfNodes(777); + CPPUNIT_ASSERT_EQUAL(777, myNodalConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_NODE, MED_EN::MED_NONE)); +// // Throws because _constituent is not calculated +// CPPUNIT_ASSERT_THROW(myNodalConnectivity.getNumberOfElementsWithPoly +// (MED_EN::MED_FACE, MED_EN::MED_NONE), MEDEXCEPTION); + +// // Returns zero, because EntityDimension is not set +// CPPUNIT_ASSERT_EQUAL(0, myNodalConnectivity.getNumberOfElementsWithPoly +// (MED_EN::MED_CELL, MED_EN::MED_POLYGON)); +// CPPUNIT_ASSERT_EQUAL(0, myNodalConnectivity.getNumberOfElementsWithPoly +// (MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA)); + + // Throws because entity must differ from MED_NONE and MED_ALL_ELEMENTS + CPPUNIT_ASSERT_THROW(myNodalConnectivity.getNumberOfNodesInType(MED_EN::MED_NONE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(myNodalConnectivity.getNumberOfNodesInType(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION); + + // Throws because types are not defined + CPPUNIT_ASSERT_THROW(myNodalConnectivity.getNumberOfNodesInType(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(myNodalConnectivity.getNumberOfNodesInType(MED_EN::MED_POLYGON), MEDEXCEPTION); + + + // does not throw any more exception because + // it is now possible to work on meshes with only polyhedric elements + CPPUNIT_ASSERT_NO_THROW(myNodalConnectivity.calculateConnectivity + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + + // existPolygonsConnectivity + CPPUNIT_ASSERT(!myNodalConnectivity.existPolygonsConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(myNodalConnectivity.existPolygonsConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(!myNodalConnectivity.existPolygonsConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + + CPPUNIT_ASSERT(!myDesceConnectivity.existPolygonsConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(myDesceConnectivity.existPolygonsConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(!myDesceConnectivity.existPolygonsConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + + // existPolyhedronConnectivity + CPPUNIT_ASSERT(myNodalConnectivity.existPolyhedronConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(!myNodalConnectivity.existPolyhedronConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(myNodalConnectivity.existPolyhedronConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + + CPPUNIT_ASSERT(!myDesceConnectivity.existPolyhedronConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(!myDesceConnectivity.existPolyhedronConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(myDesceConnectivity.existPolyhedronConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + + // setEntityDimension + // myNodalConnectivity and myDesceConnectivity is not good, because + // it contains cells of different dimension (2D and 3D) + // We set here EntityDimension for good work of below methods + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_POLYHEDRA, myNodalConnectivity.getPolyTypeRelativeTo()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_POLYHEDRA, myDesceConnectivity.getPolyTypeRelativeTo()); + + // Poly types + CPPUNIT_ASSERT_EQUAL(1, myNodalConnectivity.getNumberOfTypesWithPoly(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL(1, myDesceConnectivity.getNumberOfTypesWithPoly(MED_EN::MED_CELL)); + + CPPUNIT_ASSERT_EQUAL(1, myNodalConnectivity.getNumberOfTypesWithPoly(MED_EN::MED_FACE)); + CPPUNIT_ASSERT_EQUAL(0, myDesceConnectivity.getNumberOfTypesWithPoly(MED_EN::MED_EDGE)); + + CPPUNIT_ASSERT_EQUAL(1, myNodalConnectivity.getNumberOfPolyType()); + CPPUNIT_ASSERT_EQUAL(1, myDesceConnectivity.getNumberOfPolyType()); + + // getNumberOfElementsWithPoly + CPPUNIT_ASSERT_EQUAL(NumberOfPolyhedron, myNodalConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA)); + CPPUNIT_ASSERT_EQUAL(0, myNodalConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_CELL, MED_EN::MED_POLYGON)); + //Minus 1 because 2,3,8,9 is a given twice in connectivity + CPPUNIT_ASSERT_EQUAL(NumberOfFaces-1, myNodalConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_FACE, MED_EN::MED_POLYGON)); + + CPPUNIT_ASSERT_EQUAL(NumberOfPolyhedron, myDesceConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA)); + CPPUNIT_ASSERT_EQUAL(NumberOfPolygons, myDesceConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_FACE, MED_EN::MED_POLYGON)); + CPPUNIT_ASSERT_EQUAL(0, myDesceConnectivity.getNumberOfElementsWithPoly + (MED_EN::MED_CELL, MED_EN::MED_POLYGON)); + + // getNumberOfElementOfPolyType + CPPUNIT_ASSERT_EQUAL(NumberOfPolyhedron, + myNodalConnectivity.getNumberOfElementOfPolyType(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL(NumberOfFaces-1,myNodalConnectivity.getNumberOfElementOfPolyType(MED_EN::MED_FACE)); + + CPPUNIT_ASSERT_EQUAL(NumberOfPolygons, + myDesceConnectivity.getNumberOfElementOfPolyType(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL(NumberOfPolygons, myDesceConnectivity.getNumberOfElementOfPolyType(MED_EN::MED_FACE)); + + // getConnectivityOfAnElementWithPoly + { + int len_ph1; + CPPUNIT_ASSERT_THROW(myNodalConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_NODAL, MED_EN::MED_CELL, /*Number*/1, len_ph1),MEDEXCEPTION); + + int len_pg1, len_pg2, len_pg3,i; + //first polyhedron + const int * dc_pg1 = myDesceConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/1, len_pg1); // {1,2,3,4,11,10} + CPPUNIT_ASSERT_EQUAL(9, len_pg1); + //second polyhedron + const int * dc_pg2 = myDesceConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/2, len_pg2); // {11,5,6,7,8,9} + CPPUNIT_ASSERT_EQUAL(10, len_pg2); + //first polygon + const int * dc_pg3 = myDesceConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_FACE, /*Number*/2, len_pg3); // {11,5,6,7,8,9} + CPPUNIT_ASSERT_EQUAL(6, len_pg3); + + + for (i = 0; i < 6; i++) { + if (dc_pg1[i] < 1 || 10 < dc_pg1[i] || + dc_pg3[i] < 1 || 11 < dc_pg3[i]) + CPPUNIT_FAIL("Wrong connectivity returned"); + } + } + + // We reset here EntityDimension to check getConnectivityOfAnElementWithPoly() + //myNodalConnectivity.setEntityDimension(2); + //myDesceConnectivity.setEntityDimension(3); + + { + int len_pg1, len_pg2, i; + + CPPUNIT_ASSERT_THROW ( myNodalConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_NODAL, MED_EN::MED_CELL, /*Number*/1, len_pg1),MEDEXCEPTION); + + const int * nc_pg1 = myNodalConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/1, len_pg1); // {1,2,3,4,5,10} + CPPUNIT_ASSERT_EQUAL(9, len_pg1); + const int * nc_pg2 = myNodalConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/2, len_pg2); // {10,5,6,7,8,9} + CPPUNIT_ASSERT_EQUAL(10, len_pg2); + + for (i = 0; i < 9; i++) { + if (nc_pg1[i] < 1 || 18 < nc_pg1[i] || + nc_pg2[i] < -3 || 18 < nc_pg2[i]) + CPPUNIT_FAIL("Wrong connectivity returned"); + } + + int len_ph1, len_ph2; + const int * dc_ph1 = myDesceConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/1, len_ph1); // {1,2,3,4,5,6,7,8,9} + CPPUNIT_ASSERT_EQUAL(9, len_ph1); + const int * dc_ph2 = myDesceConnectivity.getConnectivityOfAnElementWithPoly + (MED_EN::MED_DESCENDING, MED_EN::MED_CELL, /*Number*/2, len_ph2); // {10,11,12,13,14,15,16,3,17,18} + CPPUNIT_ASSERT_EQUAL(10, len_ph2); + + for (i = 0; i < 9; i++) { + if (dc_ph1[i] < 1 || 9 < dc_ph1[i]) + CPPUNIT_FAIL("Wrong connectivity returned"); + } + + for (i = 0; i < 10; i++) { + if ((dc_ph2[i] != 3 && dc_ph2[i] < 10) || 18 < dc_ph2[i]) + CPPUNIT_FAIL("Wrong connectivity returned"); + } + } + + //////////// + // TEST 2 // + //////////// + checkCopyConnectivity(); + + //////////// + // TEST 3 // + //////////// + + CONNECTIVITY aCells1 (/*numberOfTypes*/2, /*Entity*/MED_EN::MED_CELL); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aCells1.getEntity()); + CPPUNIT_ASSERT_EQUAL(2, aCells1.getNumberOfTypes(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL(2, aCells1.getNumberOfTypesWithPoly(MED_EN::MED_CELL)); + + CONNECTIVITY aCells2 (/*numberOfTypes*/3/*, Entity=MED_EN::MED_CELL*/); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aCells2.getEntity()); + CPPUNIT_ASSERT_EQUAL(3, aCells2.getNumberOfTypes(MED_EN::MED_CELL)); + CPPUNIT_ASSERT_EQUAL(3, aCells2.getNumberOfTypesWithPoly(MED_EN::MED_CELL)); + + CONNECTIVITY * anEdges1 = new CONNECTIVITY(/*numberOfTypes*/1, /*Entity*/MED_EN::MED_EDGE); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_EDGE, anEdges1->getEntity()); + CPPUNIT_ASSERT_EQUAL(1, anEdges1->getNumberOfTypes(MED_EN::MED_EDGE)); + CPPUNIT_ASSERT_EQUAL(1, anEdges1->getNumberOfTypesWithPoly(MED_EN::MED_EDGE)); + + CONNECTIVITY * anEdges2 = new CONNECTIVITY(/*numberOfTypes*/2, /*Entity*/MED_EN::MED_EDGE); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_EDGE, anEdges2->getEntity()); + CPPUNIT_ASSERT_EQUAL(2, anEdges2->getNumberOfTypes(MED_EN::MED_EDGE)); + CPPUNIT_ASSERT_EQUAL(2, anEdges2->getNumberOfTypesWithPoly(MED_EN::MED_EDGE)); + + CONNECTIVITY * aFaces1 = new CONNECTIVITY(/*numberOfTypes*/4, /*Entity*/MED_EN::MED_FACE); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces1->getEntity()); + CPPUNIT_ASSERT_EQUAL(4, aFaces1->getNumberOfTypes(MED_EN::MED_FACE)); + CPPUNIT_ASSERT_EQUAL(4, aFaces1->getNumberOfTypesWithPoly(MED_EN::MED_FACE)); + + // No need to delete anEdges1 and aFaces1, because they are owned by aCells1 + // (anEdges1 is owned by aFaces1 to be precise) + // No need to delete anEdges2, because they are owned by aCells2 + + // EntityDimension + // It would be good to set EntityDimension automatically for EDGEs and FACEs, + // and warn about not set EntityDimension for CELLs + // (or calculate it by given geometric types) + aCells1.setEntityDimension(3); + aCells2.setEntityDimension(2); // for 2D mesh + anEdges1->setEntityDimension(1); + anEdges2->setEntityDimension(1); + aFaces1->setEntityDimension(2); + + CPPUNIT_ASSERT_EQUAL(3, aCells1.getEntityDimension()); + CPPUNIT_ASSERT_EQUAL(2, aCells2.getEntityDimension()); + CPPUNIT_ASSERT_EQUAL(1, anEdges1->getEntityDimension()); + CPPUNIT_ASSERT_EQUAL(1, anEdges2->getEntityDimension()); + CPPUNIT_ASSERT_EQUAL(2, aFaces1->getEntityDimension()); + + // getPolyTypeRelativeTo + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_POLYHEDRA, aCells1.getPolyTypeRelativeTo()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_POLYGON , aCells2.getPolyTypeRelativeTo()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_POLYGON , aFaces1->getPolyTypeRelativeTo()); + // because there is no poly types for edges (2D entities) + CPPUNIT_ASSERT_THROW(anEdges1->getPolyTypeRelativeTo(), MEDEXCEPTION); + + // setConstituent + CPPUNIT_ASSERT_THROW(aCells1.setConstituent(&aCells2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aCells1.setConstituent(anEdges1), MEDEXCEPTION); + + aCells1.setConstituent(aFaces1); + aCells1.setConstituent(anEdges1); + + CPPUNIT_ASSERT_EQUAL(1, aCells1.getNumberOfTypes(MED_EN::MED_EDGE)); + CPPUNIT_ASSERT_EQUAL(4, aCells1.getNumberOfTypes(MED_EN::MED_FACE)); + + aCells2.setConstituent(anEdges2); + CPPUNIT_ASSERT_EQUAL(2, aCells2.getNumberOfTypes(MED_EN::MED_EDGE)); + + // setGeometricTypes + MED_EN::medGeometryElement aCellTypes2D[3] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4, MED_EN::MED_TRIA6}; + MED_EN::medGeometryElement aCellTypes3D[2] = {MED_EN::MED_PYRA5, MED_EN::MED_HEXA8}; + MED_EN::medGeometryElement anEdgeTypes1[1] = {MED_EN::MED_SEG2}; + MED_EN::medGeometryElement anEdgeTypes2[2] = {MED_EN::MED_SEG2, MED_EN::MED_SEG3}; + MED_EN::medGeometryElement aFaceTypes4[4] = + {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4, MED_EN::MED_TRIA6, MED_EN::MED_QUAD8}; + + aCells1.setGeometricTypes(aCellTypes3D, MED_EN::MED_CELL); + aCells1.setGeometricTypes(aFaceTypes4, MED_EN::MED_FACE); + aCells1.setGeometricTypes(anEdgeTypes1, MED_EN::MED_EDGE); + CPPUNIT_ASSERT_THROW(aCells1.setGeometricTypes(anEdgeTypes1, MED_EN::MED_NODE), MEDEXCEPTION); + + aCells2.setGeometricTypes(aCellTypes2D, MED_EN::MED_CELL); + anEdges2->setGeometricTypes(anEdgeTypes2, MED_EN::MED_EDGE); + CPPUNIT_ASSERT_THROW(aCells2.setGeometricTypes(aFaceTypes4, MED_EN::MED_FACE), MEDEXCEPTION); + + // setCount + int countCell2D[4] = {1, 5, 6, 10}; + int countCell3D[3] = {1, 3, 4}; + int countEdges1[2] = {1, 21}; + int countEdges2[3] = {1, 13, 21}; + int countFaces1[5] = {1, 9, 15, 16, 17}; + + aCells1.setCount(countCell3D, MED_EN::MED_CELL); + aCells1.setCount(countEdges1, MED_EN::MED_EDGE); + aCells1.setCount(countFaces1, MED_EN::MED_FACE); + CPPUNIT_ASSERT_THROW(aCells1.setCount(countEdges1, MED_EN::MED_NODE), MEDEXCEPTION); + + aCells2.setCount(countCell2D, MED_EN::MED_CELL); + aCells2.setCount(countEdges2, MED_EN::MED_EDGE); + CPPUNIT_ASSERT_THROW(aCells2.setCount(countFaces1, MED_EN::MED_FACE), MEDEXCEPTION); + + // setNodal + + // aCells2 + int nodesCell2D_TRIA3[12] = {3,8,7, 10,7,13, 18,13,14, 11,14,8}; + int nodesCell2D_QUAD4[4] = {7,8,14,13}; + int nodesCell2D_TRIA6[24] = {1,2,3,7,10,6, 3,4,5,9,11,8, 11,15,20,19,18,14, 18,17,16,12,10,13}; + + aCells2.setNodal(nodesCell2D_TRIA3, MED_EN::MED_CELL, MED_EN::MED_TRIA3); + aCells2.setNodal(nodesCell2D_QUAD4, MED_EN::MED_CELL, MED_EN::MED_QUAD4); + aCells2.setNodal(nodesCell2D_TRIA6, MED_EN::MED_CELL, MED_EN::MED_TRIA6); + + int nodesEdges2_SEG2[24] = {3,8, 8,11, 11,14, 14,18, 18,13, 13,10, 10,7, + 7,3, 7,8, 8,14, 14,13, 13,7}; + int nodesEdges2_SEG3[24] = {1,2,3, 3,4,5, 5,9,11, 11,15,20, + 20,19,18, 18,17,16, 16,12,10, 10,6,1}; + + aCells2.setNodal(nodesEdges2_SEG2, MED_EN::MED_EDGE, MED_EN::MED_SEG2); + aCells2.setNodal(nodesEdges2_SEG3, MED_EN::MED_EDGE, MED_EN::MED_SEG3); + + // aCells1 + int nodesCell3D_PYRA5[10] = {1,2,3,4,5, 10,6,7,8,9}; + int nodesCell3D_HEXA8[8] = {2,3,4,5, 6,7,8,9}; + + aCells1.setNodal(nodesCell3D_PYRA5, MED_EN::MED_CELL, MED_EN::MED_PYRA5); + aCells1.setNodal(nodesCell3D_HEXA8, MED_EN::MED_CELL, MED_EN::MED_HEXA8); + + int nodesFaces1_TRIA3[24] = {1,2,3, 1,3,4, 1,4,5, 1,5,2, + 10,7,6, 10,8,7, 10,9,8, 10,6,9}; + int nodesFaces1_QUAD4[24] = {2,3,4,5, 6,7,8,9, 2,3,7,6, 5,4,8,9, 2,5,9,6, 3,4,8,7}; + int nodesFaces1_TRIA6[6] = {11,12,13,14,15,16}; + int nodesFaces1_QUAD8[8] = {15,14,13,17,18,19,20,21}; + + aCells1.setNodal(nodesFaces1_TRIA3, MED_EN::MED_FACE, MED_EN::MED_TRIA3); + aCells1.setNodal(nodesFaces1_QUAD4, MED_EN::MED_FACE, MED_EN::MED_QUAD4); + aCells1.setNodal(nodesFaces1_TRIA6, MED_EN::MED_FACE, MED_EN::MED_TRIA6); + aCells1.setNodal(nodesFaces1_QUAD8, MED_EN::MED_FACE, MED_EN::MED_QUAD8); + + int nodesEdges1_SEG2[40] = {1,2, 1,3, 1,4, 1,5, 10,6, 10,7, 10,8, 10,9, + 2,3, 3,4, 4,5, 5,2, 6,7, 7,8, 8,9, 9,6, + 2,6, 3,7, 4,8, 5,9}; + + aCells1.setNodal(nodesEdges1_SEG2, MED_EN::MED_EDGE, MED_EN::MED_SEG2); + + // setNumberOfNodes + aCells2.setNumberOfNodes(20); + anEdges2->setNumberOfNodes(20); + + aCells1.setNumberOfNodes(21); + anEdges1->setNumberOfNodes(21); + aFaces1->setNumberOfNodes(21); + + // existConnectivity + CPPUNIT_ASSERT(aCells1.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(aCells1.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(aCells1.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_EDGE)); + CPPUNIT_ASSERT(!aCells1.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_NODE)); + + CPPUNIT_ASSERT(!aCells1.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(!aCells1.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(!aCells1.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_EDGE)); + CPPUNIT_ASSERT(!aCells1.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_NODE)); + + CPPUNIT_ASSERT(aCells2.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(!aCells2.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(aCells2.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_EDGE)); + CPPUNIT_ASSERT(!aCells2.existConnectivity(MED_EN::MED_NODAL, MED_EN::MED_NODE)); + + CPPUNIT_ASSERT(!aCells2.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL)); + CPPUNIT_ASSERT(!aCells2.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_FACE)); + CPPUNIT_ASSERT(!aCells2.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_EDGE)); + CPPUNIT_ASSERT(!aCells2.existConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_NODE)); + + // getNumberOfPolyType + CPPUNIT_ASSERT_EQUAL(0, aCells1.getNumberOfPolyType()); + CPPUNIT_ASSERT_EQUAL(0, aCells2.getNumberOfPolyType()); + + // getConnectivityOfAnElementWithPoly + { + int len_e1, len_e2, i; + const int * nc_e1 = aCells1.getConnectivityOfAnElementWithPoly + (MED_EN::MED_NODAL, MED_EN::MED_CELL, /*Number*/1, len_e1); + CPPUNIT_ASSERT_EQUAL(5, len_e1); // PYRA5 {1,2,3,4,5} + for (i = 0; i < len_e1; i++) { + if (nc_e1[i] < 1 || 5 < nc_e1[i]) + CPPUNIT_FAIL("Wrong node in element"); + } + + const int * nc_e2 = aCells2.getConnectivityOfAnElementWithPoly + (MED_EN::MED_NODAL, MED_EN::MED_CELL, /*Number*/2, len_e2); + CPPUNIT_ASSERT_EQUAL(3, len_e2); // TRIA3 {7,10,13} + for (i = 0; i < len_e2; i++) { + if (nc_e2[i] != 7 && nc_e2[i] != 10 && nc_e2[i] != 13) + CPPUNIT_FAIL("Wrong node in element"); + } + } + + //cout << "aCells2: " << endl; + //cout << aCells2 << endl; + + //cout << "aCells1:" << endl; + //cout << aCells1 << endl; + + // aCells1 (2 types) | + // | | + // aFaces1 (4 types) | aCells2 (3 types) + // | | | + // anEdges1 (1 type) | anEdges2 (2 types) + + // updateFamily + { + FAMILY aFamilyOnFaces; + aFamilyOnFaces.setEntity(MED_EN::MED_FACE); + aFamilyOnFaces.setMeshName("Mesh 1"); + aFamilyOnFaces.setName("Support On Faces 1"); + //aFamilyOnFaces.setAll(true); + + int nbTypesFam1 = 4; + MED_EN::medGeometryElement aSCTypes[4] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4, + MED_EN::MED_TRIA6, MED_EN::MED_QUAD8}; + int nbEltsSC[4] = {8,6,1,1}; + int indexSC[5] = {1,9,15,16,17}; // length = nb.types + 1 + int valueSC[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; // length = total nb. of elements + //int nbTypesFam1 = 1; + //MED_EN::medGeometryElement aSCTypes[1] = {MED_EN::MED_TRIA3}; + //int nbEltsSC[1] = {8}; + //int indexSC[2] = {1,9}; // length = nb.types + 1 + //int valueSC[8] = {1,3,5,7,9,11,13,15}; // length = total nb. of elements + + aFamilyOnFaces.setNumberOfGeometricType(nbTypesFam1); + aFamilyOnFaces.setGeometricType(aSCTypes); + aFamilyOnFaces.setNumberOfElements(nbEltsSC); + aFamilyOnFaces.setNumber(indexSC, valueSC); + + vector<FAMILY*> aFamsOnFaces (1); + aFamsOnFaces[0] = &aFamilyOnFaces; + +#ifdef ENABLE_UPDATE_FAMILY + // Attention!!! By default ENABLE_UPDATE_FAMILY is not defined!!! + // I do not undestand, what this method should do + // and what I must give to it to obtain good result + + //cout << "aCells1:" << endl; + //cout << aCells1 << endl; + CPPUNIT_ASSERT_NO_THROW(aCells1.updateFamily(aFamsOnFaces)); + //cout << "aCells1:" << endl; + //cout << aCells1 << endl; +#endif + } + + //////////// + // TEST 4 // + //////////// + CONNECTIVITY * c1 = new CONNECTIVITY(/*numberOfTypes*/2, MED_EN::MED_CELL); + createOrCheck(c1, "Creation", /*create*/true); + createOrCheck(c1, "Check just created", /*create*/false); + + CONNECTIVITY * c2 = new CONNECTIVITY(*c1); + createOrCheck(c2, "Check copy constructor", /*create*/false); + + // invertConnectivityForAFace + int nbFacesC2 = c2->getNumberOf(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS); + for (int faceId = 1; faceId <= nbFacesC2; faceId++) { + //cout << "^^^^^ not inverted ^^^^^" << endl; + //showConnectivity(c2, 3, 20, MED_EN::MED_CELL, 2); + //cout << *c2 << endl; + //cout << "^^^^^ not inverted ^^^^^" << endl; + + // this face nodal connectivity before inversion: + int oldLen, newLen; + const int * oldConn = c2->getConnectivityOfAnElementWithPoly(MED_EN::MED_NODAL, + MED_EN::MED_FACE, faceId, oldLen); + + // descending connectivity before inversion: + int before_NumberOfElements = c2->getNumberOf(MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + const int * before_connectivity_shared = + c2->getConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + const int * before_connectivity_index = + c2->getConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + + // copy connectivity, because the pointer, returned by getConnectivity, + // will point to the same memory before and after inversion + int lenDC = before_connectivity_index[before_NumberOfElements] - 1; + int * before_connectivity = new int[lenDC]; + for (int i = 0; i < lenDC; i++) + before_connectivity[i] = before_connectivity_shared[i]; + + // reverse descending connectivity before inversion: + const int * before_ReverseDescendingConnectivity_shared = + c2->getReverseConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + const int * before_ReverseDescendingConnectivityIndex = + c2->getReverseConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + + int lenRDC = before_ReverseDescendingConnectivityIndex[nbFacesC2] - 1; + int * before_ReverseDescendingConnectivity = new int[lenRDC]; + for (int i = 0; i < lenRDC; i++) + before_ReverseDescendingConnectivity[i] = before_ReverseDescendingConnectivity_shared[i]; + + // perform inversion + int * newNodesForFace = new int[oldLen]; + if (oldLen == 3) { + newNodesForFace[0] = oldConn[1]; + newNodesForFace[1] = oldConn[0]; + newNodesForFace[2] = oldConn[2]; + } else { + newNodesForFace[0] = oldConn[2]; + newNodesForFace[1] = oldConn[1]; + newNodesForFace[2] = oldConn[0]; + newNodesForFace[3] = oldConn[3]; + } + c2->invertConnectivityForAFace(faceId, newNodesForFace, /*polygonFace*/false); + + //cout << "^^^^^ inverted ^^^^^" << endl; + //showConnectivity(c2, 3, 20, MED_EN::MED_CELL, 2); + //cout << *c2 << endl; + //cout << "^^^^^ inverted ^^^^^" << endl; + + // reverse descending connectivity after inversion: + const int * after_ReverseDescendingConnectivity = + c2->getReverseConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + const int * after_ReverseDescendingConnectivityIndex = + c2->getReverseConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + + // Faces, which are on bound (have one neighbouring), are not inverted. + bool isOnBound = false; + + //cout << "faceId = " << faceId << endl; + //cout << "oldLen = " << oldLen << endl; + for (int i = 0; i < nbFacesC2; i++) { + //cout << "i = " << i << endl; + int plus = after_ReverseDescendingConnectivityIndex[i] - 1; + // always two neighbourings + if ((i + 1) == faceId) { + // no second neighbouring + isOnBound = (before_ReverseDescendingConnectivity[plus + 1] == 0); + } + if ((i + 1) == faceId && oldLen == 4 && !isOnBound) { + CPPUNIT_ASSERT_EQUAL(before_ReverseDescendingConnectivity[plus + 0], + after_ReverseDescendingConnectivity[plus + 1]); + CPPUNIT_ASSERT_EQUAL(before_ReverseDescendingConnectivity[plus + 1], + after_ReverseDescendingConnectivity[plus + 0]); + } + else { + CPPUNIT_ASSERT_EQUAL(before_ReverseDescendingConnectivity[plus + 0], + after_ReverseDescendingConnectivity[plus + 0]); + CPPUNIT_ASSERT_EQUAL(before_ReverseDescendingConnectivity[plus + 1], + after_ReverseDescendingConnectivity[plus + 1]); + } + } + + // descending connectivity after inversion: + int after_NumberOfElements = c2->getNumberOf(MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + const int * after_connectivity = + c2->getConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + const int * after_connectivity_index = + c2->getConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); + + CPPUNIT_ASSERT_EQUAL(before_NumberOfElements, after_NumberOfElements); + + for (int j = 0; j < before_NumberOfElements; j++) { + for (int k = after_connectivity_index[j]; k < after_connectivity_index[j+1]; k++) { + if (labs(before_connectivity[k-1]) == faceId && !isOnBound) { + CPPUNIT_ASSERT_EQUAL(before_connectivity[k-1], - after_connectivity[k-1]); + } + else { + CPPUNIT_ASSERT_EQUAL(before_connectivity[k-1], after_connectivity[k-1]); + } + } + } + + // this face nodal connectivity after inversion: + if (!isOnBound) { + const int * newConn = c2->getConnectivityOfAnElementWithPoly(MED_EN::MED_NODAL, + MED_EN::MED_FACE, faceId, newLen); + CPPUNIT_ASSERT_EQUAL(oldLen, newLen); + for (int i = 0; i < newLen; i++) { + CPPUNIT_ASSERT_EQUAL(newNodesForFace[i], newConn[i]); + } + } + delete [] newNodesForFace; + + delete [] before_connectivity; + delete [] before_ReverseDescendingConnectivity; + + // ATTENTION: invertConnectivityForAFace() is not tested on polygons!!! + } + + + delete c1; + delete c2; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Connectivity_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Connectivity_fault.cxx new file mode 100644 index 000000000..e13a05364 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Connectivity_fault.cxx @@ -0,0 +1,139 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Connectivity.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +using namespace std; +using namespace MEDMEM; + +void createOrCheck (CONNECTIVITY * theC, string msg, bool create = false) +{ + // Preconditions: Entity and NumberOfTypes + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, MED_EN::MED_CELL, theC->getEntity()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_CELL)); + + // EntityDimension + if (create) + theC->setEntityDimension(3); + + // NumberOfNodes + int nbNodes = 20; + + if (create) { + theC->setNumberOfNodes(nbNodes); + } + + // GeometricTypes + MED_EN::medGeometryElement aCellTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_HEXA8}; + + // this variable is needed in check mode (!create) + // because of bug with getGlobalNumberingIndex() method (see below) + bool triaFirst = true; + + if (create) { + theC->setGeometricTypes(aCellTypes, MED_EN::MED_CELL); + CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_NODE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_FACE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setGeometricTypes(aCellTypes, MED_EN::MED_EDGE), MEDEXCEPTION); + } + + // Nodal Connectivity for standard types + int countCells[3] = {1, 3, 4}; // 2 PYRA5 and 1 HEXA8 + int nodesCells_PYRA5[10] = {2,3,4,5,1, 6,7,8,9,10}; + int nodesCells_HEXA8[8] = {2,3,4,5, 6,7,8,9}; + + if (create) { + theC->setCount(countCells, MED_EN::MED_CELL); + theC->setNodal(nodesCells_PYRA5, MED_EN::MED_CELL, MED_EN::MED_PYRA5); + theC->setNodal(nodesCells_HEXA8, MED_EN::MED_CELL, MED_EN::MED_HEXA8); + + // Invalid cases + CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_NODE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_EDGE), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->setCount(countCells, MED_EN::MED_FACE), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(theC->setNodal(nodesCells_PYRA5, MED_EN::MED_FACE, MED_EN::MED_PYRA5), MEDEXCEPTION); + } + + // 2 POLYHEDRA + const int nbPolyhedron = 2; + const int nbPolyFaces = 14; + const int nbPolyNodes = 52; + + int aPolyhedronIndex[nbPolyhedron + 1] = {1,8,15}; + + int aPolyhedronFacesIndex[nbPolyFaces + 1] = {1,7,10,14,17,20,24, 27,33,36,40,43,46,50,53}; + + int aPolyhedronNodalConnectivity[nbPolyNodes] = { + 11,15,19,20,17,13, 11,13,14, 14,13,17,18, 18,17,20, 11,14,15, 15,14,18,19, 19,18,20, + 11,13,17,20,19,15, 11,12,13, 13,12,16,17, 17,16,20, 11,15,12, 12,15,19,16, 16,19,20}; + + if (create) { + theC->setPolyhedronConnectivity(MED_EN::MED_NODAL, aPolyhedronNodalConnectivity, + aPolyhedronIndex, nbPolyNodes, nbPolyhedron, + aPolyhedronFacesIndex, nbPolyFaces); + } + else { + // CELLS(3D): theC + { + // Polyhedron-specific methods + { + // invalid polyhedron Id +#ifdef ENABLE_FAULTS + int lenPolyh3nodes; + int nbFaces3; + int *nbNodes3; + // (BUG) Segmentation fault instead of MEDEXCEPTION + CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(1, lenPolyh3nodes), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNodesOfPolyhedron(3+3, lenPolyh3nodes), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron + (/*polyhedronId*/1, nbFaces3, nbNodes3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theC->getNodesPerFaceOfPolyhedron + (/*polyhedronId*/3+3, nbFaces3, nbNodes3), MEDEXCEPTION); +#endif + } // Polyhedron-specific methods + } // CELLS: theC + } + + if (create) { + // force _constituent computation + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, 2, theC->getNumberOfTypes(MED_EN::MED_FACE)); + } +} + +int main (int argc, char** argv) +{ + CONNECTIVITY * c1 = new CONNECTIVITY(/*numberOfTypes*/2, MED_EN::MED_CELL); + createOrCheck(c1, "Creation", /*create*/true); + createOrCheck(c1, "Check just created", /*create*/false); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Coordinate.cxx b/src/MEDMEM/Test/MEDMEMTest_Coordinate.cxx new file mode 100644 index 000000000..0d70c22d8 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Coordinate.cxx @@ -0,0 +1,410 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Array.hxx" +#include "MEDMEM_Coordinate.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #8: MEDMEM_Coordinate.hxx } MEDMEMTest_Coordinate.cxx + +/*! + * Check methods (23), defined in MEDMEM_Coordinate.hxx: + * class COORDINATE { + * (+) COORDINATE(); + * (+) COORDINATE(int SpaceDimension, int NumberOfNodes, MED_EN::medModeSwitch Mode); + * (+) COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit); + * (+) COORDINATE(const COORDINATE & m); + * (+) virtual ~COORDINATE(); + * (+) void setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy=false); + * (+) void setCoordinates(const MED_EN::medModeSwitch Mode, const double *Coordinate); + * (+) void setCoordinatesNames(const string * CoordinateName); + * (+) void setCoordinateName(const string CoordinateName, const int i); + * (+) void setCoordinatesUnits(const string * CoordinateUnit); + * (+) void setCoordinateUnit(const string CoordinateUnit, const int i); + * (+) void setCoordinatesSystem(const string CoordinateSystem); + * (+) void setNodesNumbers(const int * NodeNumber); + * (+) int getSpaceDimension() const; + * (+) int getNumberOfNodes() const; + * (+) virtual const int* getNodesNumbers() const; + * (+) string getCoordinatesSystem() const; + * (+) virtual const double * getCoordinates(MED_EN::medModeSwitch Mode); + * (+) virtual double getCoordinate(int Number,int Axis); + * (+) virtual const double * getCoordinateAxis(int Axis); + * (+) const string * getCoordinatesNames() const; + * (+) string getCoordinateName(int Axis) const; + * (+) const string * getCoordinatesUnits() const; + * (+) string getCoordinateUnit(int Axis) const; + * } + * + * Use code of MEDMEM/tests/testUCoordinate.cxx + * MEDMEM/test_copie_coordinate.cxx + */ +void MEDMEMTest::testCoordinate() +{ + ////////////////////////////////////////////// + // TEST 1: MEDMEM/tests/testUCoordinate.cxx // + ////////////////////////////////////////////// + { + const double pouieme = 0.009; + + int SpaceDim = 3; + int NbOfNodes = 5; + + string * noms = new string[3]; + noms[0] = " X "; + noms[1] = " Y "; + noms[2] = " Z "; + + string units[3]; + units[0] = " m "; + units[1] = " m "; + units[2] = " m "; + + int * numbers = new int[5]; + for (int i = 0; i < 5; i++) numbers[i] = 10 + i; + + double coor[15] = {0,0,0,0,0,1,0,1,0,1,0,0,0.5,0.5,0.5}; + CPPUNIT_ASSERT(SpaceDim * NbOfNodes == 15); + + double * coor1 = new double [SpaceDim*NbOfNodes]; + for (int k = 0; k < SpaceDim*NbOfNodes; k++) + coor1[k] = coor[k]; + + MEDARRAY<double>* CoordinateArray = + new MEDARRAY<double>(coor1, SpaceDim, NbOfNodes, MED_EN::MED_FULL_INTERLACE); + COORDINATE mycoo; + CPPUNIT_ASSERT_NO_THROW(mycoo.setCoordinates(CoordinateArray)); + + //--------------------------------------------------------------------// + // Tests des methodes // + // // + // - setCoordinatesNames // + // - setCoordinatesUnits // + // - setCoordinatesSystem // + // - setNodesNumbers // + // // + //--------------------------------------------------------------------// + + CPPUNIT_ASSERT_NO_THROW(mycoo.setCoordinatesNames(noms)); + CPPUNIT_ASSERT_NO_THROW(mycoo.setCoordinatesUnits(units)); + CPPUNIT_ASSERT_NO_THROW(mycoo.setCoordinatesSystem("cartesien")); + CPPUNIT_ASSERT_NO_THROW(mycoo.setNodesNumbers(numbers)); + + //--------------------------------------------------------------------// + // Tests des methodes // + // // + // - getCoordinatesNames // + // - getCoordinatesUnits // + // - getCoordinatesUnit // + // - getCoordinatesSystem // + // - getNodesNumbers // + // // + //--------------------------------------------------------------------// + CPPUNIT_ASSERT_NO_THROW(CPPUNIT_ASSERT(mycoo.getCoordinatesSystem() == "cartesien")); + + const string * units2; + try + { + units2 = mycoo.getCoordinatesUnits(); + for (int axe = 0; axe < SpaceDim; axe++) { + string verif = mycoo.getCoordinateUnit(axe+1); + CPPUNIT_ASSERT(verif == units2[axe]); + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const string * noms2; + try + { + noms2 = mycoo.getCoordinatesNames(); + for (int axe = 0; axe < SpaceDim; axe++) { + string verif = mycoo.getCoordinateName(axe+1); + CPPUNIT_ASSERT(verif == noms2[axe]); + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + const double * coor2 = mycoo.getCoordinates(MED_EN::MED_FULL_INTERLACE); + + for (int axe = 0; axe < SpaceDim; axe++) { + const double * coor3 = mycoo.getCoordinateAxis(axe+1); + for (int num = 0; num < NbOfNodes; num++) { + const double d = mycoo.getCoordinate(num + 1, axe + 1); + CPPUNIT_ASSERT(fabs(d - coor3[num ]) < pouieme); + CPPUNIT_ASSERT(fabs(d - coor2[(num * SpaceDim)+axe]) < pouieme); + CPPUNIT_ASSERT(fabs(d - coor [(num * SpaceDim)+axe]) < pouieme); + } + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + delete [] noms; + delete [] numbers; + delete [] coor1; + + delete CoordinateArray; + } + + ////////////////////////////////////////////// + // TEST 2: MEDMEM/test_copie_coordinate.cxx // + ////////////////////////////////////////////// + { + const int numberofNodes = 5; + const int spaceDimension = 3; + const MED_EN::medModeSwitch mode = MED_EN::MED_FULL_INTERLACE; + + //construction tableau MEDARRAY des coordonnĂ©es + MEDARRAY<double> * myMedArray = new MEDARRAY<double>(spaceDimension, numberofNodes, mode); + for (int i = 1; i <= myMedArray->getLengthValue(); i++) { + for (int j = 1; j <= myMedArray->getLeadingValue(); j++) + myMedArray->setIJ(i, j, (double) i*j); + } + + //construction noms des coordonnĂ©es + string * myCoordinatesNames = new string[spaceDimension]; + if (spaceDimension >= 1) myCoordinatesNames[0] = "x"; + if (spaceDimension >= 2) myCoordinatesNames[1] = "y"; + if (spaceDimension >= 3) myCoordinatesNames[2] = "z"; + + //construction unitĂ©s des coordonnĂ©es + string * myCoordinatesUnits = new string[spaceDimension]; + if (spaceDimension >= 1) myCoordinatesUnits[0] = "m"; + if (spaceDimension >= 2) myCoordinatesUnits[1] = "m"; + if (spaceDimension >= 3) myCoordinatesUnits[2] = "m"; + + //construction des indices des noeuds + int * myNodeNumber = new int[numberofNodes]; + for (int i = 0; i < numberofNodes; i++) + myNodeNumber[i] = numberofNodes - i - 1; + + //construction de l'objet COORDINATE + COORDINATE * myCoordinate = new COORDINATE(); + myCoordinate->setCoordinates(myMedArray); + myCoordinate->setCoordinatesNames(myCoordinatesNames); + myCoordinate->setCoordinatesUnits(myCoordinatesUnits); + myCoordinate->setNodesNumbers(myNodeNumber); + + delete myMedArray; + delete[] myCoordinatesNames; + delete[] myCoordinatesUnits; + delete[] myNodeNumber; + + COORDINATE * myCoordinate2 = new COORDINATE(* myCoordinate); + delete myCoordinate; + myCoordinate = NULL; + + // check copied coordinate + int _spaceDimension = myCoordinate2->getSpaceDimension(); + int _numberofNodes = myCoordinate2->getNumberOfNodes(); + CPPUNIT_ASSERT(_spaceDimension == spaceDimension); + CPPUNIT_ASSERT(_numberofNodes == numberofNodes); + + for (int i = 1; i <= _numberofNodes; i++) { + for (int j = 1; j <= _spaceDimension; j++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(i*j, myCoordinate2->getCoordinate(i, j), 0.000001); + } + } + + CPPUNIT_ASSERT(myCoordinate2->getCoordinateName(1) == "x"); + CPPUNIT_ASSERT(myCoordinate2->getCoordinateName(2) == "y"); + CPPUNIT_ASSERT(myCoordinate2->getCoordinateName(3) == "z"); + + CPPUNIT_ASSERT(myCoordinate2->getCoordinateUnit(1) == "m"); + CPPUNIT_ASSERT(myCoordinate2->getCoordinateUnit(2) == "m"); + CPPUNIT_ASSERT(myCoordinate2->getCoordinateUnit(3) == "m"); + + for (int i = 0; i < _numberofNodes; i++) + CPPUNIT_ASSERT(myCoordinate2->getNodesNumbers()[i] == _numberofNodes - i - 1); + + delete myCoordinate2; + } + + //////////// + // TEST 3 // + //////////// + { + // COORDINATE(int SpaceDimension, int NumberOfNodes, MED_EN::medModeSwitch Mode); + COORDINATE anEmptyC (2, 10, MED_EN::MED_FULL_INTERLACE); + CPPUNIT_ASSERT(anEmptyC.getSpaceDimension() == 2); + CPPUNIT_ASSERT(anEmptyC.getNumberOfNodes() == 10); + CPPUNIT_ASSERT(anEmptyC.getNodesNumbers() == NULL); + // ?: how to fill it with coordinates? + // 1. void setCoordinates(MEDARRAY<double> *Coordinate,bool shallowCopy=false); + // but this way we can override all three constructor parameters + // 2. void setCoordinates(const MED_EN::medModeSwitch Mode, const double *Coordinate); + // in this case we can override Mode + +#ifdef ENABLE_FAULTS + // (BUG) Incoherence between setCoordinateName() and getCoordinateName() + anEmptyC.setCoordinateName("alpha", 1); + anEmptyC.setCoordinateName("betta", 2); + // (BUG) Incoherence between setCoordinateUnit() and getCoordinateUnit() + anEmptyC.setCoordinateUnit("ttt", 1); + anEmptyC.setCoordinateUnit("sss", 2); +#else + anEmptyC.setCoordinateName("alpha", 0); + anEmptyC.setCoordinateName("betta", 1); + + anEmptyC.setCoordinateUnit("ttt", 0); + anEmptyC.setCoordinateUnit("sss", 1); +#endif +#ifdef ENABLE_FORCED_FAILURES + //CPPUNIT_FAIL("Incoherence between COORDINATE::setCoordinateName() and COORDINATE::getCoordinateName()"); + //CPPUNIT_FAIL("Incoherence between COORDINATE::setCoordinateUnit() and COORDINATE::getCoordinateUnit()"); +#endif + + int len = 10 * 2; + double * cc = new double[len]; + for (int i = 0; i < len; i++) { + cc[i] = (double)(i + 1); + } + anEmptyC.setCoordinates(MED_EN::MED_NO_INTERLACE, cc); + + CPPUNIT_ASSERT(anEmptyC.getCoordinateName(1) == "alpha"); + CPPUNIT_ASSERT(anEmptyC.getCoordinateName(2) == "betta"); + CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(1) == "ttt"); + CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(2) == "sss"); + for (int nn = 1; nn <= 10; nn++) { + for (int aa = 1; aa <= 2; aa++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(nn + (aa - 1) * 10, anEmptyC.getCoordinate(nn, aa), 0.000001); + } + } + + CPPUNIT_ASSERT_THROW(anEmptyC.getCoordinate(0, 0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyC.getCoordinate(10, 10), MEDEXCEPTION); + + MEDARRAY<double> mcc (cc, 2, 10, MED_EN::MED_FULL_INTERLACE, false, false); + anEmptyC.setCoordinates(&mcc, false); + + // coordinates names and units are not changed + CPPUNIT_ASSERT(anEmptyC.getCoordinateName(1) == "alpha"); + CPPUNIT_ASSERT(anEmptyC.getCoordinateName(2) == "betta"); + CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(1) == "ttt"); + CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(2) == "sss"); + for (int nn = 1; nn <= 10; nn++) { + for (int aa = 1; aa <= 2; aa++) { + // coordinates changed + CPPUNIT_ASSERT_DOUBLES_EQUAL((nn - 1) * 2 + aa, anEmptyC.getCoordinate(nn, aa), 0.000001); + } + } + + delete [] cc; + +#ifdef ENABLE_FAULTS + // (BUG) Segmentation Fault or Hang up after anEmptyC and mcc destruction, + // because array will be owned by two pointers (in mcc and in anEmptyC) after this call + anEmptyC.setCoordinates(&mcc, true); + // In other case (if we dynamically allocate mcc and do not free it) we will have memory leak. +#endif +#ifdef ENABLE_FORCED_FAILURES + //CPPUNIT_FAIL("Bug in COORDINATE::setCoordinates() in shallow copy mode"); +#endif + } + + //////////// + // TEST 4 // + //////////// + { + // COORDINATE(int SpaceDimension,const string * CoordinateName, const string * CoordinateUnit); + string cnames [3] = {"al", "be", "ga"}; + string cunits [3] = {"kg", "mm", "s2"}; + COORDINATE anEmptyA (3, cnames, cunits); + + CPPUNIT_ASSERT(anEmptyA.getCoordinateName(1) == "al"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateName(2) == "be"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateName(3) == "ga"); + + CPPUNIT_ASSERT(anEmptyA.getCoordinateUnit(1) == "kg"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateUnit(2) == "mm"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateUnit(3) == "s2"); + + CPPUNIT_ASSERT_EQUAL(anEmptyA.getSpaceDimension(), 0); + CPPUNIT_ASSERT_EQUAL(anEmptyA.getNumberOfNodes(), 0); + + MEDARRAY<double> mcc (3, 7, MED_EN::MED_NO_INTERLACE); + anEmptyA.setCoordinates(&mcc, false); + + CPPUNIT_ASSERT_EQUAL(anEmptyA.getSpaceDimension(), 3); + CPPUNIT_ASSERT_EQUAL(anEmptyA.getNumberOfNodes(), 7); + + CPPUNIT_ASSERT(anEmptyA.getCoordinateName(1) == "al"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateName(2) == "be"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateName(3) == "ga"); + + CPPUNIT_ASSERT(anEmptyA.getCoordinateUnit(1) == "kg"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateUnit(2) == "mm"); + CPPUNIT_ASSERT(anEmptyA.getCoordinateUnit(3) == "s2"); + + CPPUNIT_ASSERT_THROW(anEmptyA.getCoordinate(-1, 0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(anEmptyA.getCoordinate(10, 10), MEDEXCEPTION); + + // No COORDINATE::operator=, but this is compilable + // good + //COORDINATE anEmptyB; + //COORDINATE anEmptyD (3, cnames, cunits); + //anEmptyB = anEmptyD; + //CPPUNIT_ASSERT(anEmptyB.getCoordinateName(1) == "al"); + + // bad (assert fails) + //COORDINATE anEmptyB; + // Object, created in this line, is destructed right after it. + //anEmptyB = COORDINATE(3, cnames, cunits); + // Now a pointer _coordinateName inside anEmptyB points to a desallocated memory zone + //CPPUNIT_ASSERT(anEmptyB.getCoordinateName(1) == "al"); + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Coordinate_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Coordinate_fault.cxx new file mode 100644 index 000000000..7393cf56a --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Coordinate_fault.cxx @@ -0,0 +1,59 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEM_Array.hxx" +#include "MEDMEM_Coordinate.hxx" + +using namespace std; +using namespace MEDMEM; + +int main (int argc, char** argv) +{ + COORDINATE anEmptyC (2, 10, MED_EN::MED_FULL_INTERLACE); + + // (BUG) Incoherence between setCoordinateName() and getCoordinateName() + // C++ index notation is used in "set" methods, while in "get" methods indices start from 1. + anEmptyC.setCoordinateName("alpha", 1); + anEmptyC.setCoordinateName("betta", 2); + // (BUG) Incoherence between setCoordinateUnit() and getCoordinateUnit() + // C++ index notation is used in "set" methods, while in "get" methods indices start from 1. + anEmptyC.setCoordinateUnit("ttt", 1); + anEmptyC.setCoordinateUnit("sss", 2); + + //CPPUNIT_ASSERT(anEmptyC.getCoordinateName(1) == "alpha"); + //CPPUNIT_ASSERT(anEmptyC.getCoordinateName(2) == "betta"); + //CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(1) == "ttt"); + //CPPUNIT_ASSERT(anEmptyC.getCoordinateUnit(2) == "sss"); + + int len = 10 * 2; + double * cc = new double[len]; + for (int i = 0; i < len; i++) { + cc[i] = (double)(i + 1); + } + + MEDARRAY<double> mcc (cc, 2, 10, MED_EN::MED_FULL_INTERLACE, false, false); + delete [] cc; + + // (BUG) Bug in COORDINATE::setCoordinates() in shallow copy mode: + // Segmentation Fault or Hang up after anEmptyC and mcc destruction, + // because array will be owned by two pointers (in mcc and in anEmptyC) after this call + anEmptyC.setCoordinates(&mcc, true); + // In other case (if we dynamically allocate mcc and do not free it) we will have memory leak. +} diff --git a/src/MEDMEM/Test/MEDMEMTest_DriverFactory.cxx b/src/MEDMEM/Test/MEDMEMTest_DriverFactory.cxx new file mode 100644 index 000000000..cc6b63d0d --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_DriverFactory.cxx @@ -0,0 +1,920 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include "MEDMEM_DriverFactory.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_GenDriver.hxx" +#include "MEDMEM_GibiMeshDriver.hxx" +#include "MEDMEM_MedFieldDriver21.hxx" +#include "MEDMEM_MedFieldDriver22.hxx" +#include "MEDMEM_MedFieldDriver.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_MedMedDriver21.hxx" +#include "MEDMEM_MedMedDriver22.hxx" +#include "MEDMEM_MedMedDriver.hxx" +#include "MEDMEM_MedMeshDriver21.hxx" +#include "MEDMEM_MedMeshDriver22.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_PorflowMeshDriver.hxx" +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_VtkFieldDriver.hxx" +#include "MEDMEM_VtkMedDriver.hxx" +#include "MEDMEM_VtkMeshDriver.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #9: MEDMEM_DriverFactory.hxx } MEDMEMTest_DriverFactory.cxx + +/*! + * Check methods (11), defined in MEDMEM_DriverFactory.hxx: + * namespace DRIVERFACTORY { + * (+) MED_EN::medFileVersion getMedFileVersionForWriting(); + * (+) void setMedFileVersionForWriting(MED_EN::medFileVersion version); + * (+) driverTypes deduceDriverTypeFromFileName(const std::string & fileName); + * + * (+) GENDRIVER * buildDriverForMesh (driverTypes driverType, const std::string & fileName, + * MESH *mesh, const string & driverName, + * MED_EN::med_mode_acces access); + * (+) template<class T, class INTERLACING_TAG> + * GENDRIVER * buildDriverForField(driverTypes driverType, const std::string & fileName, + * FIELD<T,INTERLACING_TAG> *fielde, + * MED_EN::med_mode_acces access); + * (+) GENDRIVER * buildDriverForMed (driverTypes driverType, const std::string & fileName, + * MED *mede, + * MED_EN::med_mode_acces access); + * + * (+) GENDRIVER * buildMedDriverFromFile (const string & fileName, MED * const ptrMed, + * MED_EN::med_mode_acces access); + * (+) GENDRIVER * buildMeshDriverFromFile (const string & fileName, MESH * ptrMesh, + * MED_EN::med_mode_acces access); + * (+) template<class T, class INTERLACING_TAG> + * GENDRIVER * buildFieldDriverFromFile(const string & fileName, + * FIELD<T,INTERLACING_TAG> * ptrField, + * MED_EN::med_mode_acces access); + * + * (+) GENDRIVER * buildConcreteMedDriverForMesh(const std::string & fileName, MESH *mesh, + * const string & driverName, + * MED_EN::med_mode_acces access, + * MED_EN::medFileVersion version); + * (+) template<class T, class INTERLACING_TAG> + * GENDRIVER * buildConcreteMedDriverForField(const std::string & fileName, + * FIELD<T,INTERLACING_TAG> *fielde, + * MED_EN::med_mode_acces access, + * MED_EN::medFileVersion version); + * } + */ +void MEDMEMTest::testDriverFactory() +{ + /////////////////////////////////////////////////////////////////////// + // Test 1: getMedFileVersionForWriting & setMedFileVersionForWriting // + /////////////////////////////////////////////////////////////////////// + + // save current version preference + MED_EN::medFileVersion aVersionSaved = DRIVERFACTORY::getMedFileVersionForWriting(); + + // check version preference changing + MED_EN::medFileVersion aVersionToSet = + (aVersionSaved == MED_EN::V22) ? MED_EN::V21 : MED_EN::V22; + DRIVERFACTORY::setMedFileVersionForWriting(aVersionToSet); + CPPUNIT_ASSERT(aVersionToSet == DRIVERFACTORY::getMedFileVersionForWriting()); + + // restore default version preference + DRIVERFACTORY::setMedFileVersionForWriting(aVersionSaved); + + ////////////////////////////////////////// + // Test 2: deduceDriverTypeFromFileName // + ////////////////////////////////////////// + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("test.med") == MED_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.sauve") == GIBI_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.sauv") == GIBI_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.cnc") == PORFLOW_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.inp") == PORFLOW_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.xyz") == PORFLOW_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.vtk") == VTK_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t_st_med") == NO_DRIVER); + CPPUNIT_ASSERT(DRIVERFACTORY::deduceDriverTypeFromFileName("t.st.med1") == NO_DRIVER); + + //////////////////////////////////////////////////////// + // Test building drivers for different types of files // + //////////////////////////////////////////////////////// + GENDRIVER * aDriver = NULL; + + /////////////////////////////// + // Test 3: buildDriverForMed // + /////////////////////////////// + MED med; + + // 3.1: MED_DRIVER + + // rdonly + aDriver = DRIVERFACTORY::buildDriverForMed(MED_DRIVER, "anyfile", &med, MED_EN::MED_LECT); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) See more details below for the same problem of MED_MESH_RDONLY_DRIVER + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_LECT, aDriver->getAccessMode()); +#endif + + MED_MED_RDONLY_DRIVER * aMedRDriverForMed = dynamic_cast<MED_MED_RDONLY_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aMedRDriverForMed); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildDriverForMed(MED_DRIVER, "anyfile", &med, MED_EN::MED_ECRI); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) See more details below for the same problem of MED_MESH_RDONLY_DRIVER + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); +#endif + + MED_MED_WRONLY_DRIVER * aMedWDriverForMed = dynamic_cast<MED_MED_WRONLY_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aMedWDriverForMed); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildDriverForMed(MED_DRIVER, "anyfile", &med, MED_EN::MED_REMP); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) See more details below for the same problem of MED_MESH_RDONLY_DRIVER + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); +#endif + + MED_MED_RDWR_DRIVER * aMedRWDriverForMed = dynamic_cast<MED_MED_RDWR_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aMedRWDriverForMed); + + delete aDriver; + + // 3.2: GIBI_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(GIBI_DRIVER, "anyfile", &med, MED_EN::MED_LECT), + MED_EXCEPTION); + // wronly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(GIBI_DRIVER, "anyfile", &med, MED_EN::MED_ECRI), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(GIBI_DRIVER, "anyfile", &med, MED_EN::MED_REMP), + MED_EXCEPTION); + + // 3.3: PORFLOW_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(PORFLOW_DRIVER, "anyfile", &med, MED_EN::MED_LECT), + MED_EXCEPTION); + // wronly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(PORFLOW_DRIVER, "anyfile", &med, MED_EN::MED_ECRI), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(PORFLOW_DRIVER, "anyfile", &med, MED_EN::MED_REMP), + MED_EXCEPTION); + + // 3.4: VTK_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(VTK_DRIVER, "anyfile", &med, MED_EN::MED_LECT), + MED_EXCEPTION); + + // wronly + aDriver = DRIVERFACTORY::buildDriverForMed(VTK_DRIVER, "anyfile", &med, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + VTK_MED_DRIVER * aVtkDriverForMed = dynamic_cast<VTK_MED_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aVtkDriverForMed); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildDriverForMed(VTK_DRIVER, "anyfile", &med, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + aVtkDriverForMed = dynamic_cast<VTK_MED_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aVtkDriverForMed); + + delete aDriver; + + // 3.5: ASCII_DRIVER + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(ASCII_DRIVER, "anyfile", &med, MED_EN::MED_LECT), + MED_EXCEPTION); + + // 3.6: NO_DRIVER + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMed(NO_DRIVER, "anyfile", &med, MED_EN::MED_LECT), + MED_EXCEPTION); + + //////////////////////////////// + // Test 4: buildDriverForMesh // + //////////////////////////////// + MESH mesh; + + // 4.1: MED_DRIVER + + // rdonly + aDriver = DRIVERFACTORY::buildDriverForMesh + (MED_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + + MED_MESH_RDONLY_DRIVER * aMedRDriverForMesh = dynamic_cast<MED_MESH_RDONLY_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aMedRDriverForMesh); + CPPUNIT_ASSERT(aMedRDriverForMesh->getMeshName() == "my driver name"); + + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildDriverForMesh + (MED_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MESH_WRONLY_DRIVER * aMedWDriverForMesh = dynamic_cast<MED_MESH_WRONLY_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aMedWDriverForMesh); + CPPUNIT_ASSERT(aMedWDriverForMesh->getMeshName() == "my driver name"); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildDriverForMesh + (MED_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + + MED_MESH_RDWR_DRIVER * aMedRWDriverForMesh = dynamic_cast<MED_MESH_RDWR_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aMedRWDriverForMesh); + CPPUNIT_ASSERT(aMedRWDriverForMesh->getMeshName() == "my driver name"); + + delete aDriver; + + // 4.2: GIBI_DRIVER + + // rdonly + aDriver = DRIVERFACTORY::buildDriverForMesh + (GIBI_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + GIBI_MESH_RDONLY_DRIVER * aGibiDriverForMesh = dynamic_cast<GIBI_MESH_RDONLY_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aGibiDriverForMesh); + + delete aDriver; + + // wronly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(GIBI_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_ECRI), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(GIBI_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_REMP), + MED_EXCEPTION); + + // 4.3: PORFLOW_DRIVER + + // rdonly + aDriver = DRIVERFACTORY::buildDriverForMesh + (PORFLOW_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + PORFLOW_MESH_RDONLY_DRIVER * aPorflowDriverForMesh = dynamic_cast<PORFLOW_MESH_RDONLY_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aPorflowDriverForMesh); + + delete aDriver; + + // wronly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(PORFLOW_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_ECRI), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(PORFLOW_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_REMP), + MED_EXCEPTION); + + // 4.4: VTK_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(VTK_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_LECT), + MED_EXCEPTION); + + // wronly + aDriver = DRIVERFACTORY::buildDriverForMesh + (VTK_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + VTK_MESH_DRIVER * aVtkDriverForMesh = dynamic_cast<VTK_MESH_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aVtkDriverForMesh); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildDriverForMesh + (VTK_DRIVER, "anyfile", &mesh, "my driver name", MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + aVtkDriverForMesh = dynamic_cast<VTK_MESH_DRIVER *> (aDriver); + CPPUNIT_ASSERT(aVtkDriverForMesh); + + delete aDriver; + + // 4.5: ASCII_DRIVER + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(ASCII_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_LECT), + MED_EXCEPTION); + + // 4.6: NO_DRIVER + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForMesh(NO_DRIVER, "anyfile", &mesh, + "my driver name", MED_EN::MED_LECT), + MED_EXCEPTION); + + ///////////////////////////////// + // Test 5: buildDriverForField // + ///////////////////////////////// + FIELD<double> field; + + // 5.1: MED_DRIVER + + // rdonly + aDriver = DRIVERFACTORY::buildDriverForField(MED_DRIVER, "anyfile", &field, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_FIELD_RDONLY_DRIVER<double> * aMedRDriverForField = + dynamic_cast<MED_FIELD_RDONLY_DRIVER<double> *> (aDriver); + CPPUNIT_ASSERT(aMedRDriverForField); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildDriverForField(MED_DRIVER, "anyfile", &field, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_FIELD_WRONLY_DRIVER<double> * aMedWDriverForField = + dynamic_cast<MED_FIELD_WRONLY_DRIVER<double> *> (aDriver); + CPPUNIT_ASSERT(aMedWDriverForField); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildDriverForField(MED_DRIVER, "anyfile", &field, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Wrong access mode (MED_ECRI) passed to parent class! + // confusion between MED_DRWR (defined as MED_ECRI in MEDMEM_define.hxx) + // and MED_REMP causes confusion in MEDMEM_MedFieldDriver22.hxx + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_REMP,aDriver->getAccessMode()); +#endif + + MED_FIELD_RDWR_DRIVER<double> * aMedRWDriverForField = + dynamic_cast<MED_FIELD_RDWR_DRIVER<double> *> (aDriver); + CPPUNIT_ASSERT(aMedRWDriverForField); + + delete aDriver; + + // 5.2: GIBI_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(GIBI_DRIVER, "anyfile", &field, MED_EN::MED_LECT), + MED_EXCEPTION); + // wronly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(GIBI_DRIVER, "anyfile", &field, MED_EN::MED_ECRI), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(GIBI_DRIVER, "anyfile", &field, MED_EN::MED_REMP), + MED_EXCEPTION); + + // 5.3: PORFLOW_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(PORFLOW_DRIVER, "anyfile", + &field, MED_EN::MED_LECT), + MED_EXCEPTION); + // wronly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(PORFLOW_DRIVER, "anyfile", + &field, MED_EN::MED_ECRI), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(PORFLOW_DRIVER, "anyfile", + &field, MED_EN::MED_REMP), + MED_EXCEPTION); + + // 5.4: VTK_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(VTK_DRIVER, "anyfile", &field, MED_EN::MED_LECT), + MED_EXCEPTION); + + // wronly + aDriver = DRIVERFACTORY::buildDriverForField(VTK_DRIVER, "anyfile", &field, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + VTK_FIELD_DRIVER<double> * aVtkDriverForField = dynamic_cast<VTK_FIELD_DRIVER<double> *> (aDriver); + CPPUNIT_ASSERT(aVtkDriverForField); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildDriverForField(VTK_DRIVER, "anyfile", &field, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + aVtkDriverForField = dynamic_cast<VTK_FIELD_DRIVER<double> *> (aDriver); + CPPUNIT_ASSERT(aVtkDriverForField); + + delete aDriver; + + // 5.5: ASCII_DRIVER + + // rdonly + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", &field, MED_EN::MED_LECT), + MED_EXCEPTION); + // rdwr + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", &field, MED_EN::MED_REMP), + MED_EXCEPTION); + + // wronly + // it throws on empty field + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", &field, MED_EN::MED_ECRI), + MED_EXCEPTION); + + // now try with valid field + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + string fieldname = "fieldcelldouble"; + FIELD<double> * aField1 = new FIELD<double> (MED_DRIVER, filename, fieldname); + const SUPPORT * aSupport = aField1->getSupport(); + MESH * aMesh = new MESH (MED_DRIVER, filename, aSupport->getMeshName()); + aSupport->setMesh(aMesh); + + aDriver = DRIVERFACTORY::buildDriverForField(ASCII_DRIVER, "anyfile", aField1, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + // it works! + //aDriver->open(); + //aDriver->write(); + //aDriver->close(); + + ASCII_FIELD_DRIVER<double> * anAsciiDriverForField = + dynamic_cast<ASCII_FIELD_DRIVER<double> *> (aDriver); + CPPUNIT_ASSERT(anAsciiDriverForField); + + delete aDriver; + + delete aField1; + delete aMesh; + + // 5.6: NO_DRIVER + CPPUNIT_ASSERT_THROW(DRIVERFACTORY::buildDriverForField(NO_DRIVER, "anyfile", &field, MED_EN::MED_LECT), + MED_EXCEPTION); + + //////////////////////////////////// + // Test 6: buildMedDriverFromFile // + //////////////////////////////////// + string aFileName1 = datadir + "/MedFiles/pointe.med"; + string aFileName2 = datadir + "/MedFiles/polyedres.med"; + medFileVersion version1, version2; + + try { + version1 = getMedFileVersion(aFileName1); + } catch (MEDEXCEPTION & ex) { + version1 = DRIVERFACTORY::globalMedFileVersionForWriting; + } + + try { + version2 = getMedFileVersion(aFileName2); + } catch (MEDEXCEPTION & ex) { + version2 = DRIVERFACTORY::globalMedFileVersionForWriting; + } + + // 6.1. Med file V2.1 + string aFileName21 = aFileName1; + if (version1 == MED_EN::V21 || version2 == MED_EN::V21) { + if (version1 == MED_EN::V22) + aFileName21 = aFileName2; + + // rdonly + aDriver = DRIVERFACTORY::buildMedDriverFromFile(aFileName21, &med, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_MED_RDONLY_DRIVER21 * aMedRDriverForMed21 = dynamic_cast<MED_MED_RDONLY_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMedRDriverForMed21); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildMedDriverFromFile(aFileName21, &med, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MED_WRONLY_DRIVER21 * aMedWDriverForMed21 = dynamic_cast<MED_MED_WRONLY_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMedWDriverForMed21); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildMedDriverFromFile(aFileName21, &med, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + + MED_MED_RDWR_DRIVER21 * aMedRWDriverForMed21 = dynamic_cast<MED_MED_RDWR_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMedRWDriverForMed21); + + delete aDriver; + } + + // 6.2. Med file V2.2 + string aFileName22 = aFileName2; + if (version2 == MED_EN::V22 || version1 == MED_EN::V22) { + if (version2 == MED_EN::V21) + aFileName22 = aFileName1; + + // rdonly + aDriver = DRIVERFACTORY::buildMedDriverFromFile(aFileName22, &med, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_MED_RDONLY_DRIVER22 * aMedRDriverForMed22 = dynamic_cast<MED_MED_RDONLY_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMedRDriverForMed22); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildMedDriverFromFile(aFileName22, &med, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MED_WRONLY_DRIVER22 * aMedWDriverForMed22 = dynamic_cast<MED_MED_WRONLY_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMedWDriverForMed22); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildMedDriverFromFile(aFileName22, &med, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + + MED_MED_RDWR_DRIVER22 * aMedRWDriverForMed22 = dynamic_cast<MED_MED_RDWR_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMedRWDriverForMed22); + + delete aDriver; + } + else { + CPPUNIT_FAIL("Cannot check building of drivers from file for V2.2"); + } + if (version1 != MED_EN::V21 && version2 != MED_EN::V21) { + CPPUNIT_FAIL("Cannot check building of drivers from file for V2.1"); + } + + ///////////////////////////////////// + // Test 7: buildMeshDriverFromFile // + ///////////////////////////////////// + + // 7.1. Med file V2.1 + if (version1 == MED_EN::V21 || version2 == MED_EN::V21) { + // rdonly + aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName21, &mesh, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_MESH_RDONLY_DRIVER21 * aMeshRDriverForMed21 = dynamic_cast<MED_MESH_RDONLY_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMeshRDriverForMed21); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName21, &mesh, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MESH_WRONLY_DRIVER21 * aMeshWDriverForMed21 = dynamic_cast<MED_MESH_WRONLY_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMeshWDriverForMed21); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName21, &mesh, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_MESH_RDWR_DRIVER21 * aMeshRWDriverForMed21 = dynamic_cast<MED_MESH_RDWR_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMeshRWDriverForMed21); + + delete aDriver; + } + + // 7.2. Med file V2.2 + if (version2 == MED_EN::V22 || version1 == MED_EN::V22) { + // rdonly + aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName22, &mesh, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_MESH_RDONLY_DRIVER22 * aMeshRDriverForMed22 = dynamic_cast<MED_MESH_RDONLY_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMeshRDriverForMed22); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName22, &mesh, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MESH_WRONLY_DRIVER22 * aMeshWDriverForMed22 = dynamic_cast<MED_MESH_WRONLY_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMeshWDriverForMed22); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildMeshDriverFromFile(aFileName22, &mesh, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_MESH_RDWR_DRIVER22 * aMeshRWDriverForMed22 = dynamic_cast<MED_MESH_RDWR_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMeshRWDriverForMed22); + + delete aDriver; + } + + ////////////////////////////////////// + // Test 8: buildFieldDriverFromFile // + ////////////////////////////////////// + + // 8.1. Med file V2.1 + if (version1 == MED_EN::V21 || version2 == MED_EN::V21) { + // rdonly + aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName21, &field, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_FIELD_RDONLY_DRIVER21<double> * aFieldRDriverForMed21 = + dynamic_cast<MED_FIELD_RDONLY_DRIVER21<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRDriverForMed21); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName21, &field, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_FIELD_WRONLY_DRIVER21<double> * aFieldWDriverForMed21 = + dynamic_cast<MED_FIELD_WRONLY_DRIVER21<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldWDriverForMed21); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName21, &field, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName21); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_FIELD_RDWR_DRIVER21<double> * aFieldRWDriverForMed21 = + dynamic_cast<MED_FIELD_RDWR_DRIVER21<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRWDriverForMed21); + + delete aDriver; + } + + // 8.2. Med file V2.2 + if (version2 == MED_EN::V22 || version1 == MED_EN::V22) { + // rdonly + aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName22, &field, MED_EN::MED_LECT); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_FIELD_RDONLY_DRIVER22<double> * aFieldRDriverForMed22 = + dynamic_cast<MED_FIELD_RDONLY_DRIVER22<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRDriverForMed22); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName22, &field, MED_EN::MED_ECRI); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_FIELD_WRONLY_DRIVER22<double> * aFieldWDriverForMed22 = + dynamic_cast<MED_FIELD_WRONLY_DRIVER22<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldWDriverForMed22); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildFieldDriverFromFile(aFileName22, &field, MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getFileName() == aFileName22); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_FIELD_RDWR_DRIVER22<double> * aFieldRWDriverForMed22 = + dynamic_cast<MED_FIELD_RDWR_DRIVER22<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRWDriverForMed22); + + delete aDriver; + } + + /////////////////////////////////////////// + // Test 9: buildConcreteMedDriverForMesh // + /////////////////////////////////////////// + + // 9.1. V2.1 + + // rdonly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", &mesh, "my driver name", + MED_EN::MED_LECT, MED_EN::V21); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_MESH_RDONLY_DRIVER21 * aMeshRDriverForMed21 = dynamic_cast<MED_MESH_RDONLY_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMeshRDriverForMed21); + CPPUNIT_ASSERT(aMeshRDriverForMed21->getMeshName() == "my driver name"); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", &mesh, "my driver name", + MED_EN::MED_ECRI, MED_EN::V21); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MESH_WRONLY_DRIVER21 * aMeshWDriverForMed21 = dynamic_cast<MED_MESH_WRONLY_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMeshWDriverForMed21); + CPPUNIT_ASSERT(aMeshWDriverForMed21->getMeshName() == "my driver name"); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", &mesh, "my driver name", + MED_EN::MED_REMP, MED_EN::V21); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_MESH_RDWR_DRIVER21 * aMeshRWDriverForMed21 = dynamic_cast<MED_MESH_RDWR_DRIVER21 *> (aDriver); + CPPUNIT_ASSERT(aMeshRWDriverForMed21); + CPPUNIT_ASSERT(aMeshRWDriverForMed21->getMeshName() == "my driver name"); + + delete aDriver; + + // 9.2. V2.2 + + // rdonly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", &mesh, "my driver name", + MED_EN::MED_LECT, MED_EN::V22); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_MESH_RDONLY_DRIVER22 * aMeshRDriverForMed22 = dynamic_cast<MED_MESH_RDONLY_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMeshRDriverForMed22); + CPPUNIT_ASSERT(aMeshRDriverForMed22->getMeshName() == "my driver name"); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", &mesh, "my driver name", + MED_EN::MED_ECRI, MED_EN::V22); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_MESH_WRONLY_DRIVER22 * aMeshWDriverForMed22 = dynamic_cast<MED_MESH_WRONLY_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMeshWDriverForMed22); + CPPUNIT_ASSERT(aMeshWDriverForMed22->getMeshName() == "my driver name"); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildConcreteMedDriverForMesh("anyfile", &mesh, "my driver name", + MED_EN::MED_REMP, MED_EN::V22); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_MESH_RDWR_DRIVER22 * aMeshRWDriverForMed22 = dynamic_cast<MED_MESH_RDWR_DRIVER22 *> (aDriver); + CPPUNIT_ASSERT(aMeshRWDriverForMed22); + CPPUNIT_ASSERT(aMeshRWDriverForMed22->getMeshName() == "my driver name"); + + delete aDriver; + + ///////////////////////////////////////////// + // Test 10: buildConcreteMedDriverForField // + ///////////////////////////////////////////// + + // 10.1. V2.1 + + // rdonly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", &field, MED_EN::MED_LECT, MED_EN::V21); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_FIELD_RDONLY_DRIVER21<double> * aFieldRDriverForMed21 = + dynamic_cast<MED_FIELD_RDONLY_DRIVER21<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRDriverForMed21); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", &field, MED_EN::MED_ECRI, MED_EN::V21); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_FIELD_WRONLY_DRIVER21<double> * aFieldWDriverForMed21 = + dynamic_cast<MED_FIELD_WRONLY_DRIVER21<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldWDriverForMed21); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", &field, MED_EN::MED_REMP, MED_EN::V21); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_FIELD_RDWR_DRIVER21<double> * aFieldRWDriverForMed21 = + dynamic_cast<MED_FIELD_RDWR_DRIVER21<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRWDriverForMed21); + + delete aDriver; + + // 10.2. V2.2 + + // rdonly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", &field, MED_EN::MED_LECT, MED_EN::V22); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_LECT); + + MED_FIELD_RDONLY_DRIVER22<double> * aFieldRDriverForMed22 = + dynamic_cast<MED_FIELD_RDONLY_DRIVER22<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRDriverForMed22); + + delete aDriver; + + // wronly + aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", &field, MED_EN::MED_ECRI, MED_EN::V22); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_ECRI); + + MED_FIELD_WRONLY_DRIVER22<double> * aFieldWDriverForMed22 = + dynamic_cast<MED_FIELD_WRONLY_DRIVER22<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldWDriverForMed22); + + delete aDriver; + + // rdwr + aDriver = DRIVERFACTORY::buildConcreteMedDriverForField("anyfile", &field, MED_EN::MED_REMP, MED_EN::V22); + CPPUNIT_ASSERT(aDriver->getFileName() == "anyfile"); + //CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_REMP); + CPPUNIT_ASSERT(aDriver->getAccessMode() == MED_EN::MED_RDWR); // see MEDMEM_define.hxx + + MED_FIELD_RDWR_DRIVER22<double> * aFieldRWDriverForMed22 = + dynamic_cast<MED_FIELD_RDWR_DRIVER22<double> *> (aDriver); + CPPUNIT_ASSERT(aFieldRWDriverForMed22); + + delete aDriver; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Exception.cxx b/src/MEDMEM/Test/MEDMEMTest_Exception.cxx new file mode 100644 index 000000000..7c8f79dd5 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Exception.cxx @@ -0,0 +1,138 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_STRING.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; +using namespace MEDMEM; + +// #12: MEDMEM_Exception.hxx } MEDMEMTest_Exception.cxx + +/*! + * Check methods (not in spec), defined in MEDMEM_Exception.hxx: + * (+) #define LOCALIZED(message) static_cast<const char *> (message) , __FILE__ , __LINE__ + * class MEDEXCEPTION : public std::exception { + * (+) MEDEXCEPTION(const char *text, const char *fileName=0, const unsigned int lineNumber=0); + * (+) MEDEXCEPTION(const MEDEXCEPTION &ex); + * (+) ~MEDEXCEPTION() throw (); + * (+) friend ostream & operator<< (ostream &os, const MEDEXCEPTION &ex); + * (+) virtual const char *what(void) const throw (); + * } + * class MED_DRIVER_NOT_FOUND_EXCEPTION : public MEDEXCEPTION { + * (+) MED_DRIVER_NOT_FOUND_EXCEPTION(const char *text, const char *fileName=0, + * const unsigned int lineNumber=0); + * (+) MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex); + * (+) ~MED_DRIVER_NOT_FOUND_EXCEPTION() throw(); + * } + * + * Use code of MEDMEM/tests/testUMedException.cxx + */ +void MEDMEMTest::testException() +{ + { + // test simple constructor + MEDEXCEPTION a = MEDEXCEPTION("test med exception"); + CPPUNIT_ASSERT(a.what()); + CPPUNIT_ASSERT(strcmp(a.what(), "MED Exception : test med exception") == 0); + + // test copy constructor + MEDEXCEPTION b (a); + CPPUNIT_ASSERT(b.what()); + CPPUNIT_ASSERT(strcmp(b.what(), "MED Exception : test med exception") == 0); + + // test dumping of exception in stream + ostringstream ostr; + ostr << b; + CPPUNIT_ASSERT(ostr.str() == "MED Exception : test med exception"); + } + + { + // test constructor from three arguments + MEDEXCEPTION c ("test med exception", "<file_name>.cxx", 14); + CPPUNIT_ASSERT(c.what()); + CPPUNIT_ASSERT(strcmp(c.what(), "MED Exception in <file_name>.cxx [14] : test med exception") == 0); + } + + { + // Test macro LOCALIZED + STRING msgErr; + msgErr << "ESSAI::ESSAI()! "<< 4 << "ieme essai "; + + const char* prefix = "MED Exception"; + const char* exctxt = static_cast<const char *>(msgErr); + char* filen = __FILE__; + unsigned int linen = __LINE__ + 5; + const size_t len = strlen(prefix) + strlen(exctxt) + strlen(filen) + + (1 + int(log10(float(linen)))) + 10 + 1; + char* excmsg = new char [len]; + sprintf(excmsg, "%s in %s [%u] : %s", prefix, filen, linen, exctxt); + CPPUNIT_ASSERT(strcmp(MEDEXCEPTION(LOCALIZED(msgErr)).what(), excmsg) == 0); + + delete [] excmsg; + } + + { + // Test function STRING<< + const char * LOC = "toto"; + CPPUNIT_ASSERT(MEDEXCEPTION(LOCALIZED(STRING(LOC) << " et titi")).what()); + + // Test throw + MEDEXCEPTION d (LOCALIZED(STRING(LOC) << " et titi")); + const char* dtxt = d.what(); + try { + throw d; + } + catch (MEDEXCEPTION dc) { + CPPUNIT_ASSERT(strcmp(dc.what(), dtxt) == 0); + } + catch (...) { + CPPUNIT_FAIL("Unknown exception"); + } + } + + { + // Test MED_DRIVER_NOT_FOUND_EXCEPTION + MED_DRIVER_NOT_FOUND_EXCEPTION g ("mdnfe"); + try { + throw g; + } + catch (MED_DRIVER_NOT_FOUND_EXCEPTION mdnfe) { + CPPUNIT_ASSERT(strcmp(mdnfe.what(), g.what()) == 0); + } + catch (MEDEXCEPTION me) { + CPPUNIT_FAIL(me.what()); + } + catch (...) { + CPPUNIT_FAIL("Unknown exception"); + } + + // Copy constructor + MED_DRIVER_NOT_FOUND_EXCEPTION gcopy (g); + CPPUNIT_ASSERT(gcopy.what()); + CPPUNIT_ASSERT(strcmp(gcopy.what(), g.what()) == 0); + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Family.cxx b/src/MEDMEM/Test/MEDMEMTest_Family.cxx new file mode 100644 index 000000000..325c9065d --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Family.cxx @@ -0,0 +1,491 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Compatibility21_22.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #13: MEDMEM_Family.hxx } MEDMEMTest_Family.cxx + +/*! + * Check methods (24), defined in MEDMEM_Family.hxx: + * class FAMILY : virtual public SUPPORT { + * (+) FAMILY(); + * (+) FAMILY(MESH* Mesh, int Identifier, string Name, + * int NumberOfAttribute, int *AttributeIdentifier, + * int *AttributeValue, string AttributeDescription, + * int NumberOfGroup, string GroupName, + * int * MEDArrayNodeFamily, int ** MEDArrayCellFamily, + * int ** MEDArrayFaceFamily, int ** MEDArrayEdgeFamily); + * (+) FAMILY(const FAMILY & m); + * (+) FAMILY(const SUPPORT & s); + * (+) virtual ~FAMILY(); + * + * // Does not work (Segmentation Fault of Hang up) + * (!) FAMILY & operator=(const FAMILY &fam); + * + * (+) friend ostream & operator<<(ostream &os, FAMILY &my); + * (+) friend ostream & operator<<(ostream &os, const FAMILY &my); + * + * (+) bool build(MED_EN::medEntityMesh Entity,int **FamilyNumber); + * + * (+) inline void setIdentifier (int Identifier); + * (+) inline void setNumberOfAttributes (int NumberOfAttribute); + * (+) inline void setAttributesIdentifiers (int * AttributeIdentifier); + * (+) inline void setAttributesValues (int * AttributeValue); + * (+) inline void setAttributesDescriptions (string * AttributeDescription); + * (+) inline void setNumberOfGroups (int NumberOfGroups); + * (+) inline void setGroupsNames (string * GroupName); + * + * (+) inline int getIdentifier() const; + * (+) inline int getNumberOfAttributes() const; + * (+) inline const int * getAttributesIdentifiers() const; + * (+) inline const int * getAttributesValues() const; + * (+) inline const string * getAttributesDescriptions() const; + * (+) inline int getNumberOfGroups() const; + * (+) inline const string * getGroupsNames() const; + * + * (+) inline int getAttributeIdentifier(int i) const; + * (+) inline int getAttributeValue(int i) const; + * (+) inline string getAttributeDescription(int i) const; + * (+) inline string getGroupName(int i) const; + * } + * + * Use code of MEDMEM/test_copie_family.cxx + */ +void check_support(const SUPPORT * theSupport, + string theName, string theDescr, MED_EN::medEntityMesh theEntity, int theNbTypes) +{ + string aName = theSupport->getName(); + string aDescr = theSupport->getDescription(); + MED_EN::medEntityMesh anEntity = theSupport->getEntity(); + int aNbGeomTypes = theSupport->getNumberOfTypes(); + + CPPUNIT_ASSERT_EQUAL(theName, aName); + CPPUNIT_ASSERT_EQUAL(theDescr, aDescr); + CPPUNIT_ASSERT_EQUAL(theEntity, anEntity); + CPPUNIT_ASSERT_EQUAL(theNbTypes, aNbGeomTypes); + + cout << " - Entities list : " << endl; + if (!(theSupport->isOnAllElements())) { + cout << " - NumberOfTypes : " << aNbGeomTypes << endl; + const MED_EN::medGeometryElement * Types = theSupport->getTypes(); + for (int j = 0; j < aNbGeomTypes; j++) { + cout << " * Type " << Types[j] << " : "; + int NumberOfElements = theSupport->getNumberOfElements(Types[j]); + const int * Number = theSupport->getNumber(Types[j]); + for (int k = 0; k < NumberOfElements; k++) + cout << Number[k] << " "; + cout << endl; + } + } else + cout << " Is on all entities !" << endl; +} + +void check_famille(const FAMILY * theFamily, + string theName, string theDescr, MED_EN::medEntityMesh theEntity, int theNbTypes, + int theID, int theNbAttributes, int theNbGroups) +{ + check_support(theFamily, theName, theDescr, theEntity, theNbTypes); + + // identifier + int id = theFamily->getIdentifier(); + int nbAttributes = theFamily->getNumberOfAttributes(); + int nbGroups = theFamily->getNumberOfGroups(); + + CPPUNIT_ASSERT_EQUAL(theID, id); + CPPUNIT_ASSERT_EQUAL(theNbAttributes, nbAttributes); + CPPUNIT_ASSERT_EQUAL(theNbGroups, nbGroups); + + // attributes + cout << " - Attributes (" << nbAttributes << ") :" << endl; + for (int j = 1; j < nbAttributes + 1; j++) + cout << " * " + << theFamily->getAttributeIdentifier(j) << " : " + << theFamily->getAttributeValue(j) << ", " + << theFamily->getAttributeDescription(j).c_str() << endl; + + // groups + cout << " - Groups (" << nbGroups << ") :" << endl; + for (int j = 1; j < nbGroups + 1; j++) + cout << " * " << theFamily->getGroupName(j).c_str() << endl; +} + +void MEDMEMTest::testFamily() +{ + /////////////////////////////////// + // TEST 1: test_copie_family.cxx // + /////////////////////////////////// + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + + MESH * aMesh = new MESH(); + aMesh->setName(meshname); + MED_MESH_RDONLY_DRIVER aMeshDriver (filename, aMesh); + aMeshDriver.setMeshName(meshname); + aMeshDriver.open(); + aMeshDriver.read(); + aMeshDriver.close(); + + const FAMILY * aFamily1 = aMesh->getFamily(MED_EN::MED_NODE, 1); + + // SUPPORT attributes + string aName = aFamily1->getName(); + string aDescr = aFamily1->getDescription(); + MED_EN::medEntityMesh anEntity = aFamily1->getEntity(); + int aNbGeomTypes = aFamily1->getNumberOfTypes(); + + // FAMILY attributes + int id = aFamily1->getIdentifier(); + int nbAttributes = aFamily1->getNumberOfAttributes(); + int nbGroups = aFamily1->getNumberOfGroups(); + + // Dump + ostringstream ostr1; + ostr1 << *aFamily1; + CPPUNIT_ASSERT(ostr1.str() != ""); + + cout << "Show Family1 :" << endl; + check_famille(aFamily1, + aName, aDescr, anEntity, aNbGeomTypes, + id, nbAttributes, nbGroups); + + // Copy constructor + FAMILY * aFamily2 = new FAMILY (* aFamily1); + + // Dump + ostringstream ostr2; + ostr2 << *aFamily2; + CPPUNIT_ASSERT(ostr1.str() == ostr2.str()); + + // Compare supports + CPPUNIT_ASSERT(aFamily2->deepCompare(*aFamily1)); + + cout << "Show Family2 :" << endl; + check_famille(aFamily2, + aName, aDescr, anEntity, aNbGeomTypes, + id, nbAttributes, nbGroups); + + // One more copy + FAMILY * aFamily3 = new FAMILY (* aFamily2); + delete aFamily2; + + // Dump + ostringstream ostr3; + ostr3 << *aFamily3; + CPPUNIT_ASSERT(ostr1.str() == ostr3.str()); + + cout << "Show Family3 :" << endl; + check_famille(aFamily3, + aName, aDescr, anEntity, aNbGeomTypes, + id, nbAttributes, nbGroups); + + cout << "That's all" << endl; + + //////////// + // TEST 2 // + //////////// + { + // Prepare data + + // attributes + int newNumberOfAttribute = 3; + int * newAttributeIdentifier = new int[newNumberOfAttribute]; + int * newAttributeValue = new int[newNumberOfAttribute]; + string * newAttributeDescription = new string[newNumberOfAttribute]; + + char tmp [32]; + for (int i = 0; i < newNumberOfAttribute; i++) { + newAttributeIdentifier[i] = i+1; + newAttributeValue[i] = (i+1)*10; + sprintf(tmp, "Attribut N° %d", i+1); + newAttributeDescription[i] = tmp; + } + + // groups + int newNumberOfGroups = 4; + string * newGroups = new string[newNumberOfGroups]; + for (int i = 0; i < newNumberOfGroups; i++) { + sprintf(tmp, "Group N° %d", i+1); + newGroups[i] = tmp; + } + + // Change aFamily3 + + // attributes + aFamily3->setNumberOfAttributes(newNumberOfAttribute); + aFamily3->setAttributesIdentifiers(newAttributeIdentifier); + aFamily3->setAttributesValues(newAttributeValue); + aFamily3->setAttributesDescriptions(newAttributeDescription); + + // groups + aFamily3->setNumberOfGroups(newNumberOfGroups); + aFamily3->setGroupsNames(newGroups, /*giveOwnership = */true); + + // identifier + aFamily3->setIdentifier(77); + + // check new parameters of aFamily3 + + // attributes + CPPUNIT_ASSERT_EQUAL(newNumberOfAttribute, aFamily3->getNumberOfAttributes()); + const int * newAttributeIdentifierBack = aFamily3->getAttributesIdentifiers(); + const int * newAttributeValueBack = aFamily3->getAttributesValues(); + const string * newAttributeDescriptionBack = aFamily3->getAttributesDescriptions(); + for (int i = 1; i <= newNumberOfAttribute; i++) { + sprintf(tmp, "Attribut N° %d", i); + string descr (tmp); + + CPPUNIT_ASSERT_EQUAL(i , aFamily3->getAttributeIdentifier(i)); + CPPUNIT_ASSERT_EQUAL(i*10 , aFamily3->getAttributeValue(i)); + CPPUNIT_ASSERT_EQUAL(descr, aFamily3->getAttributeDescription(i)); + + CPPUNIT_ASSERT_EQUAL(i , newAttributeIdentifierBack[i - 1]); + CPPUNIT_ASSERT_EQUAL(i*10 , newAttributeValueBack[i - 1]); + CPPUNIT_ASSERT_EQUAL(descr, newAttributeDescriptionBack[i - 1]); + } + + delete [] newAttributeIdentifier; + delete [] newAttributeValue; + delete [] newAttributeDescription; + + // groups + CPPUNIT_ASSERT_EQUAL(newNumberOfGroups, aFamily3->getNumberOfGroups()); + const string * newGroupsBack = aFamily3->getGroupsNames(); + for (int i = 1; i <= newNumberOfGroups; i++) { + sprintf(tmp, "Group N° %d", i); + string grp (tmp); + + CPPUNIT_ASSERT_EQUAL(grp, aFamily3->getGroupName(i)); + CPPUNIT_ASSERT_EQUAL(grp, newGroupsBack[i - 1]); + } + + // identifier + CPPUNIT_ASSERT_EQUAL(77, aFamily3->getIdentifier()); + } + + ///////////////////////////////////////////////////// + // TEST 3: check default constructor and operator= // + ///////////////////////////////////////////////////// + { + FAMILY aFamily4; +#ifdef ENABLE_FAULTS + aFamily4 = (const FAMILY &)*aFamily3; +#endif +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Wrong implementation or usage of PointerOf<string>. + // Do not use memcpy() with array of std::string! + CPPUNIT_FAIL("Impossible to use FAMILY::operator= because of" + " wrong implementation or usage of PointerOf<string>"); + /*{ + int nb = 3; + string * str = new string[nb]; + + char tmp_str [32]; + for (int i = 0; i < nb; i++) { + sprintf(tmp_str, "My String N° %d", i+1); + str[i] = tmp; + } + + // bad + string* _pointer; + _pointer = new string[3]; + // This is wrong, because class string is not simple type + // and can have pointers to some data, deallocated in it's destructor, + // which (data) will not be copied by this operation. + memcpy(_pointer, str, 3*sizeof(string)); + delete [] _pointer; + + // good + //PointerOf<int> p1 (1); + //PointerOf<int> p2 (20); + //p2 = newAttributeValue; + //p1.set(3, p2); + + // bad + //PointerOf<string> p1 (1); + //PointerOf<string> p2 (20); + //p2 = str; + //p1.set(3, p2); + + delete [] str; + } + */ +#endif + } + + /////////////////////////////////////////////////// + // TEST 4: check construction from given support // + /////////////////////////////////////////////////// + { + SUPPORT s1 (*aFamily3); + FAMILY f1 (s1); + CPPUNIT_ASSERT_EQUAL(0, f1.getIdentifier()); + CPPUNIT_ASSERT_EQUAL(0, f1.getNumberOfAttributes()); + CPPUNIT_ASSERT_EQUAL(0, f1.getNumberOfGroups()); + CPPUNIT_ASSERT(s1.deepCompare(f1)); + } + + delete aFamily3; + delete aMesh; + + ///////////////////////////////////////////////////////////////// + // TEST 5: check constructor, designed to use with med driver. // + ///////////////////////////////////////////////////////////////// + { + MESH * aTestMesh = MEDMEMTest_createTestMesh(); + + // TestMesh families. Let's imagine that we would like to have + // the following nodes and elements distribution by families: + + // NumberOfNodes = 19; + int aNodeFamily[19] = {1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, 3}; + + // NumberOfCellTypes = 3; + // NumberOfCells[NumberOfCellTypes] = {12, 2, 2}; + int aCellType1Family[12] = {4,4,4,4,4,5,5,5,5,5,5,5}; + int aCellType2Family[ 2] = {5,6}; + int aCellType3Family[ 2] = {6,6}; + int * aCellFamily[3] = {aCellType1Family, aCellType2Family, aCellType3Family}; + + // NumberOfFaceTypes = 2; + // NumberOfFaces[NumberOfFaceTypes] = {4, 4}; + int aFaceType1Family[4] = {7,7,7,7}; + int aFaceType2Family[4] = {7,7,7,7}; + int * aFaceFamily[3] = {aFaceType1Family, aFaceType2Family}; + + // No edges in aTestMesh + int ** anEdgeFamily = NULL; + + // new families data + int attrId[2] = {1,2}; + int attrVa[2] = {7,8}; + + string attrDescr1 ("Attribute 1 description"); + string attrDescr2 ("Attribute 2 description"); + string attrDescrEmpty (MED_TAILLE_DESC - 23, ' '); + attrDescr1 += attrDescrEmpty; + attrDescr2 += attrDescrEmpty; + CPPUNIT_ASSERT(MED_TAILLE_DESC == attrDescr1.length()); + CPPUNIT_ASSERT(MED_TAILLE_DESC == attrDescr2.length()); + string attrDescr = attrDescr1 + attrDescr2; + + string groupName1 ("Group_1"); + string groupName2 ("Group_2"); + string groupName3 ("Group_3"); + string groupNameEmpty (MED_TAILLE_LNOM - 7, ' '); + groupName1 += groupNameEmpty; + groupName2 += groupNameEmpty; + groupName3 += groupNameEmpty; + CPPUNIT_ASSERT(MED_TAILLE_LNOM == groupName1.length()); + CPPUNIT_ASSERT(MED_TAILLE_LNOM == groupName2.length()); + CPPUNIT_ASSERT(MED_TAILLE_LNOM == groupName3.length()); + string groupNames = groupName1 + groupName2 + groupName3; + + // nodes family 1 + FAMILY aNodesF1 (aTestMesh, /*Identifier*/1, "Nodes 1", + /*NumberOfAttribute*/2, attrId, attrVa, attrDescr, + /*NumberOfGroup*/3, groupNames, + aNodeFamily, aCellFamily, aFaceFamily, anEdgeFamily); + + //cout << "Show aNodesF1 :" << endl; + //cout << aNodesF1 << endl; + + CPPUNIT_ASSERT_EQUAL(1, aNodesF1.getIdentifier()); + CPPUNIT_ASSERT(strcmp("Nodes 1", aNodesF1.getName().c_str()) == 0); + CPPUNIT_ASSERT(MED_EN::MED_NODE == aNodesF1.getEntity()); + CPPUNIT_ASSERT(!aNodesF1.isOnAllElements()); + CPPUNIT_ASSERT_EQUAL(7, aNodesF1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_EQUAL(2, aNodesF1.getNumberOfAttributes()); + CPPUNIT_ASSERT_EQUAL(1, aNodesF1.getAttributeIdentifier(1)); + CPPUNIT_ASSERT_EQUAL(2, aNodesF1.getAttributeIdentifier(2)); + CPPUNIT_ASSERT_EQUAL(7, aNodesF1.getAttributeValue(1)); + CPPUNIT_ASSERT_EQUAL(8, aNodesF1.getAttributeValue(2)); + CPPUNIT_ASSERT_EQUAL(attrDescr1, aNodesF1.getAttributeDescription(1)); + CPPUNIT_ASSERT_EQUAL(attrDescr2, aNodesF1.getAttributeDescription(2)); + + CPPUNIT_ASSERT_EQUAL(3, aNodesF1.getNumberOfGroups()); + CPPUNIT_ASSERT_EQUAL(groupName1, aNodesF1.getGroupName(1)); + CPPUNIT_ASSERT_EQUAL(groupName2, aNodesF1.getGroupName(2)); + CPPUNIT_ASSERT_EQUAL(groupName3, aNodesF1.getGroupName(3)); + + // faces family 7 + FAMILY aFacesF7 (aTestMesh, /*Identifier*/7, "Faces All", + /*NumberOfAttribute*/2, attrId, attrVa, attrDescr, + /*NumberOfGroup*/3, groupNames, + aNodeFamily, aCellFamily, aFaceFamily, anEdgeFamily); + + cout << "Show aFacesF7 :" << endl; + cout << aFacesF7 << endl; + + CPPUNIT_ASSERT_EQUAL(7, aFacesF7.getIdentifier()); + CPPUNIT_ASSERT(strcmp("Faces All", aFacesF7.getName().c_str()) == 0); + CPPUNIT_ASSERT(MED_EN::MED_FACE == aFacesF7.getEntity()); + + CPPUNIT_ASSERT_EQUAL(8, aTestMesh->getNumberOfElementsWithPoly(MED_EN::MED_FACE, + MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(8, aFacesF7.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) ? Why _isOnAllElts is set to true only for nodes and cells. What about faces? + // _isOnAllElts = true ; + // See MEDMEM_Family.cxx lines 118-119 and 386-387. + CPPUNIT_ASSERT(aFacesF7.isOnAllElements()); +#endif + + CPPUNIT_ASSERT_EQUAL(2, aFacesF7.getNumberOfAttributes()); + CPPUNIT_ASSERT_EQUAL(1, aFacesF7.getAttributeIdentifier(1)); + CPPUNIT_ASSERT_EQUAL(2, aFacesF7.getAttributeIdentifier(2)); + CPPUNIT_ASSERT_EQUAL(7, aFacesF7.getAttributeValue(1)); + CPPUNIT_ASSERT_EQUAL(8, aFacesF7.getAttributeValue(2)); + CPPUNIT_ASSERT_EQUAL(attrDescr1, aFacesF7.getAttributeDescription(1)); + CPPUNIT_ASSERT_EQUAL(attrDescr2, aFacesF7.getAttributeDescription(2)); + + CPPUNIT_ASSERT_EQUAL(3, aFacesF7.getNumberOfGroups()); + CPPUNIT_ASSERT_EQUAL(groupName1, aFacesF7.getGroupName(1)); + CPPUNIT_ASSERT_EQUAL(groupName2, aFacesF7.getGroupName(2)); + CPPUNIT_ASSERT_EQUAL(groupName3, aFacesF7.getGroupName(3)); + + delete aTestMesh; + + // Method build() is not tested directly, but it is called from constructor, tested here + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Family_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Family_fault.cxx new file mode 100644 index 000000000..37a9daa97 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Family_fault.cxx @@ -0,0 +1,89 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Mesh.hxx" + +using namespace std; +using namespace MEDMEM; + +int main (int argc, char** argv) +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + + MESH * aMesh = new MESH(); + aMesh->setName(meshname); + MED_MESH_RDONLY_DRIVER aMeshDriver (filename, aMesh); + aMeshDriver.setMeshName(meshname); + aMeshDriver.open(); + aMeshDriver.read(); + aMeshDriver.close(); + + const FAMILY * aFamily1 = aMesh->getFamily(MED_EN::MED_NODE, 1); + + // check default constructor and operator= + FAMILY aFamily4; + + // (BUG) Wrong implementation or usage of PointerOf<string>. + // Do not use memcpy() with array of std::string! + // Impossible to use FAMILY::operator=! + aFamily4 = *aFamily1; + + /*{ + int nb = 3; + string * str = new string[nb]; + + char tmp_str [32]; + for (int i = 0; i < nb; i++) { + sprintf(tmp_str, "My String N° %d", i+1); + str[i] = tmp; + } + + // bad + string* _pointer; + _pointer = new string[3]; + // This is wrong, because class string is not simple type + // and can have pointers to some data, deallocated in it's destructor, + // which (data) will not be copied by this operation. + memcpy(_pointer, str, 3*sizeof(string)); + delete [] _pointer; + + // good + //PointerOf<int> p1 (1); + //PointerOf<int> p2 (20); + //p2 = newAttributeValue; + //p1.set(3, p2); + + // bad + //PointerOf<string> p1 (1); + //PointerOf<string> p2 (20); + //p2 = str; + //p1.set(3, p2); + + delete [] str; + } + */ + + delete aMesh; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Field.cxx b/src/MEDMEM/Test/MEDMEMTest_Field.cxx new file mode 100644 index 000000000..73999c449 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Field.cxx @@ -0,0 +1,1718 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_FieldConvert.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_Support.hxx" +#include <MEDMEM_VtkMeshDriver.hxx> +#include <MEDMEM_MedMeshDriver22.hxx> + + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #14,15: MEDMEMTest_Field.cxx +// Check methods from MEDMEM_Field.hxx, MEDMEM_FieldConvert.hxx + +/*! + * Check methods (48), defined in MEDMEM_Field.hxx: + * class FIELD_ { + * (+) FIELD_(); + * (+) FIELD_(const SUPPORT * Support, const int NumberOfComponents); + * (+) FIELD_(const FIELD_ &m); + * (+) virtual ~FIELD_(); + * (+) FIELD_& operator=(const FIELD_ &m); + * + * (-) virtual void rmDriver(int index=0); + * (-) virtual int addDriver(driverTypes driverType, + * const string & fileName="Default File Name.med", + * const string & driverFieldName="Default Field Nam", + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (-) virtual int addDriver(GENDRIVER & driver); + * + * (-) virtual void read (const GENDRIVER &); + * (-) virtual void read(int index=0); + * (-) virtual void openAppend(void); + * (-) virtual void write(const GENDRIVER &); + * (-) virtual void write(int index=0, const string & driverName=""); + * (-) virtual void writeAppend(const GENDRIVER &); + * (-) virtual void writeAppend(int index=0, const string & driverName=""); + * + * (+) inline void setName(const string Name); + * (+) inline string getName() const; + * (+) inline void setDescription(const string Description); + * (+) inline string getDescription() const; + * (+) inline const SUPPORT * getSupport() const; + * (+) inline void setSupport(const SUPPORT * support); + * (+) inline void setNumberOfComponents(const int NumberOfComponents); + * (+) inline int getNumberOfComponents() const; + * (+) inline void setNumberOfValues(const int NumberOfValues); + * (+) inline int getNumberOfValues() const; + * (+) inline void setComponentsNames(const string * ComponentsNames); + * (+) inline void setComponentName(int i, const string ComponentName); + * (+) inline const string * getComponentsNames() const; + * (+) inline string getComponentName(int i) const; + * (+) inline void setComponentsDescriptions(const string * ComponentsDescriptions); + * (+) inline void setComponentDescription(int i, const string ComponentDescription); + * (+) inline const string * getComponentsDescriptions() const; + * (+) inline string getComponentDescription(int i) const; + * (+) inline void setComponentsUnits(const UNIT * ComponentsUnits); + * (+) inline const UNIT * getComponentsUnits() const; + * (+) inline const UNIT * getComponentUnit(int i) const; + * (+) inline void setMEDComponentsUnits(const string * MEDComponentsUnits); + * (+) inline void setMEDComponentUnit(int i, const string MEDComponentUnit); + * (+) inline const string * getMEDComponentsUnits() const; + * (+) inline string getMEDComponentUnit(int i) const; + * + * (+) inline void setIterationNumber(int IterationNumber); + * (+) inline int getIterationNumber() const; + * (+) inline void setTime(double Time); + * (+) inline double getTime() const; + * (+) inline void setOrderNumber(int OrderNumber); + * (+) inline int getOrderNumber() const; + * + * (+) inline MED_EN::med_type_champ getValueType () const; + * (+) inline MED_EN::medModeSwitch getInterlacingType() const; + * (-) virtual inline bool getGaussPresence() const throw (MEDEXCEPTION); + * } + * + * template <class T, class INTERLACING_TAG> class FIELD : public FIELD_ { + * (+) FIELD(); + * (+) FIELD(const FIELD &m); + * (+) FIELD(const SUPPORT * Support, const int NumberOfComponents) throw (MEDEXCEPTION); + * (+) FIELD(driverTypes driverType, + * const string & fileName, const string & fieldDriverName, + * const int iterationNumber=-1, const int orderNumber=-1) throw (MEDEXCEPTION); + * (+) FIELD(const SUPPORT * Support, driverTypes driverType, + * const string & fileName="", const string & fieldName="", + * const int iterationNumber = -1, const int orderNumber = -1) throw (MEDEXCEPTION); + * (+) ~FIELD(); + * (+) FIELD & operator=(const FIELD &m); + * + * (+) const FIELD operator+(const FIELD& m) const; + * (+) const FIELD operator-(const FIELD& m) const; + * (+) const FIELD operator*(const FIELD& m) const; + * (+) const FIELD operator/(const FIELD& m) const; + * (+) const FIELD operator-() const; + * (+) FIELD& operator+=(const FIELD& m); + * (+) FIELD& operator-=(const FIELD& m); + * (+) FIELD& operator*=(const FIELD& m); + * (+) FIELD& operator/=(const FIELD& m); + * + * (+) static FIELD* add(const FIELD& m, const FIELD& n); + * (+) static FIELD* addDeep(const FIELD& m, const FIELD& n); + * (+) static FIELD* sub(const FIELD& m, const FIELD& n); + * (+) static FIELD* subDeep(const FIELD& m, const FIELD& n); + * (+) static FIELD* mul(const FIELD& m, const FIELD& n); + * (+) static FIELD* mulDeep(const FIELD& m, const FIELD& n); + * (+) static FIELD* div(const FIELD& m, const FIELD& n); + * (+) static FIELD* divDeep(const FIELD& m, const FIELD& n); + * + * (+) double normMax() const throw (MEDEXCEPTION); + * (+) double norm2() const throw (MEDEXCEPTION); + * + * (+) void applyLin(T a, T b); + * (+) template <T T_function(T)> void applyFunc(); + * (+) void applyPow(T scalar); + * + * (+) static FIELD* scalarProduct(const FIELD& m, const FIELD& n, bool deepCheck=false); + * + * (+) double normL2(int component, const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * (+) double normL2(const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * (+) double normL1(int component, const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * (+) double normL1(const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * + * (+) FIELD* extract(const SUPPORT *subSupport) const throw (MEDEXCEPTION); + * + * (EMPTY COMMENT, EMPTY IMPLEMENTATION!!!) void init (); + * + * (+) void rmDriver(int index=0); + * (+) int addDriver(driverTypes driverType, + * const string & fileName="Default File Name.med", + * const string & driverFieldName="Default Field Name", + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (+) int addDriver(GENDRIVER & driver); + * + * (+) void allocValue(const int NumberOfComponents); + * (+) void allocValue(const int NumberOfComponents, const int LengthValue); + * (+) void deallocValue(); + * + * (+) inline void read(int index=0); + * (+) inline void read(const GENDRIVER & genDriver); + * (+) inline void write(int index=0, const string & driverName = ""); + * (+) inline void write(const GENDRIVER &); + * (+) inline void writeAppend(int index=0, const string & driverName = ""); + * (+) inline void writeAppend(const GENDRIVER &); + * + * (+) inline MEDMEM_Array_ * getArray() const throw (MEDEXCEPTION); + * (+) inline ArrayGauss * getArrayGauss() const throw (MEDEXCEPTION); + * (+) inline ArrayNoGauss * getArrayNoGauss() const throw (MEDEXCEPTION); + * (+) inline bool getGaussPresence() const throw (MEDEXCEPTION); + * + * (+) inline int getValueLength() const throw (MEDEXCEPTION); + * (+) inline const T* getValue() const throw (MEDEXCEPTION); + * (+) inline const T* getRow(int i) const throw (MEDEXCEPTION); + * (+) inline const T* getColumn(int j) const throw (MEDEXCEPTION); + * (+) inline T getValueIJ(int i,int j) const throw (MEDEXCEPTION); + * (+) inline T getValueIJK(int i,int j,int k) const throw (MEDEXCEPTION); + * (+) bool getValueOnElement(int eltIdInSup,T* retValues) const throw (MEDEXCEPTION); + * + * (+) const int getNumberOfGeometricTypes() const throw (MEDEXCEPTION); + * + * (+) const GAUSS_LOCALIZATION<INTERLACING_TAG> & getGaussLocalization + * (MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + * (+) const GAUSS_LOCALIZATION<INTERLACING_TAG> * getGaussLocalizationPtr + * (MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + * (+) void setGaussLocalization(MED_EN::medGeometryElement geomElement, + * const GAUSS_LOCALIZATION<INTERLACING_TAG> & gaussloc); + * (+) const int * getNumberOfGaussPoints() const throw (MEDEXCEPTION); + * (+) const int getNumberOfGaussPoints + * (MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + * (+) const int getNbGaussI(int i) const throw (MEDEXCEPTION); + * + * (+) const int * getNumberOfElements() const throw (MEDEXCEPTION); + * (+) const MED_EN::medGeometryElement * getGeometricTypes() const throw (MEDEXCEPTION); + * (+) bool isOnAllElements() const throw (MEDEXCEPTION); + * + * (+) inline void setArray(MEDMEM_Array_ *value) throw (MEDEXCEPTION); + * (+) inline void setValue(T* value) throw (MEDEXCEPTION); + * (+) inline void setRow(int i, T* value) throw (MEDEXCEPTION); + * (+) inline void setColumn(int i, T* value) throw (MEDEXCEPTION); + * (+) inline void setValueIJ(int i, int j, T value) throw (MEDEXCEPTION); + * + * (NOT IMPLEMENTED!!!) void getVolume() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getArea() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getLength() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getNormal() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getBarycenter() const throw (MEDEXCEPTION); + * + * (+) void fillFromAnalytic(myFuncType f) throw (MEDEXCEPTION); + * } + * + * Use code of test_operation_fieldint.cxx + * test_operation_fielddouble.cxx + * test_copie_field_.cxx + * test_copie_fieldT.cxx + */ +void compareField_(const FIELD_ * theField_1, const FIELD_ * theField_2, bool isFIELD, bool isValue) +{ + // name, description, support + CPPUNIT_ASSERT_EQUAL(theField_1->getName(), theField_2->getName()); + CPPUNIT_ASSERT_EQUAL(theField_1->getDescription(), theField_2->getDescription()); + CPPUNIT_ASSERT_EQUAL(theField_1->getSupport(), theField_2->getSupport()); + + // components information + int aNbComps = theField_1->getNumberOfComponents(); + CPPUNIT_ASSERT_EQUAL(aNbComps, theField_2->getNumberOfComponents()); + + for (int i = 1; i <= aNbComps; i++) { + CPPUNIT_ASSERT_EQUAL(theField_1->getComponentName(i), theField_2->getComponentName(i)); + CPPUNIT_ASSERT_EQUAL(theField_1->getComponentDescription(i), theField_2->getComponentDescription(i)); + CPPUNIT_ASSERT_EQUAL(theField_1->getMEDComponentUnit(i), theField_2->getMEDComponentUnit(i)); + } + + // iteration information + CPPUNIT_ASSERT_EQUAL(theField_1->getIterationNumber(), theField_2->getIterationNumber()); + CPPUNIT_ASSERT_EQUAL(theField_1->getOrderNumber(), theField_2->getOrderNumber()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(theField_1->getTime(), theField_2->getTime(), 0.0000001); + + // Value + int nbOfValues = theField_1->getNumberOfValues(); + CPPUNIT_ASSERT_EQUAL(nbOfValues, theField_2->getNumberOfValues()); + + if (isFIELD) { + // Value type and Interlacing type + CPPUNIT_ASSERT_EQUAL(theField_1->getValueType(), theField_2->getValueType()); + CPPUNIT_ASSERT_EQUAL(theField_1->getInterlacingType(), theField_2->getInterlacingType()); + + // Gauss Presence + if (isValue) { + CPPUNIT_ASSERT_EQUAL(theField_1->getGaussPresence(), theField_2->getGaussPresence()); + } + else { + CPPUNIT_ASSERT_THROW(theField_1->getGaussPresence(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_2->getGaussPresence(), MEDEXCEPTION); + } + } + else { + CPPUNIT_ASSERT_THROW(theField_1->getGaussPresence(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_2->getGaussPresence(), MEDEXCEPTION); + } +} + +void checkField_(FIELD_ * theField_, const SUPPORT * theSupport, + MED_EN::med_type_champ theValueType, + MED_EN::medModeSwitch theInterlace) +{ + // name + const string aFieldName = "a_name_of_a_field"; + theField_->setName(aFieldName); + CPPUNIT_ASSERT_EQUAL(aFieldName, theField_->getName()); + + // description + const string aFieldDescr = "a_description_of_a_field"; + theField_->setDescription(aFieldDescr); + CPPUNIT_ASSERT_EQUAL(aFieldDescr, theField_->getDescription()); + + // support + theField_->setSupport(theSupport); + CPPUNIT_ASSERT(theField_->getSupport() == theSupport); + + // components information + int aNbComps = 3; + + string aCompsNames[3] = {"Vx", "Vy", "Vz"}; + string aCompsDescs[3] = {"vitesse selon x", "vitesse selon y", "vitesse selon z"}; + string aCompsUnits[3] = {"m.s-1", "m.s-1", "m.s-1"}; + + theField_->setNumberOfComponents(aNbComps); + CPPUNIT_ASSERT_EQUAL(aNbComps, theField_->getNumberOfComponents()); + + theField_->setComponentsNames(aCompsNames); + +#ifdef ENABLE_FAULTS + try { + theField_->setNumberOfComponents(7); + // Segmentation fault here because array of components names is not resized + for (int i = 1; i <= 7; i++) { + theField_->setComponentName(i, "AnyComponent"); + } + } + catch (MEDEXCEPTION& ex) { + // Ok, it is good to have MEDEXCEPTION here + } + catch (...) { + CPPUNIT_FAIL("Unknown exception cought"); + } + // restore components names + theField_->setNumberOfComponents(aNbComps); + theField_->setComponentsNames(aCompsNames); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD_::_componentsNames bad management"); +#endif + + theField_->setComponentsDescriptions(aCompsDescs); + theField_->setMEDComponentsUnits(aCompsUnits); + + const string * aCompsNamesBack = theField_->getComponentsNames(); + const string * aCompsDescsBack = theField_->getComponentsDescriptions(); + const string * aCompsUnitsBack = theField_->getMEDComponentsUnits(); + for (int i = 1; i <= aNbComps; i++) { + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack[i-1], theField_->getComponentName(i)); + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack[i-1], aCompsNames[i-1]); + + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack[i-1], theField_->getComponentDescription(i)); + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack[i-1], aCompsDescs[i-1]); + + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack[i-1], theField_->getMEDComponentUnit(i)); + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack[i-1], aCompsUnits[i-1]); + } + + const string aCompName2 ("Name of second component"); + const string aCompDesc2 ("Description of second component"); + const string aCompUnit2 ("Unit of second MED component"); + + theField_->setComponentName(2, aCompName2); + theField_->setComponentDescription(2, aCompDesc2); + theField_->setMEDComponentUnit(2, aCompUnit2); + + const string * aCompsNamesBack2 = theField_->getComponentsNames(); + const string * aCompsDescsBack2 = theField_->getComponentsDescriptions(); + const string * aCompsUnitsBack2 = theField_->getMEDComponentsUnits(); + + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack2[1], theField_->getComponentName(2)); + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack2[1], aCompName2); + + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack2[1], theField_->getComponentDescription(2)); + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack2[1], aCompDesc2); + + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack2[1], theField_->getMEDComponentUnit(2)); + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack2[1], aCompUnit2); + +#ifdef ENABLE_FAULTS + // (BUG) No index checking + CPPUNIT_ASSERT_THROW(theField_->setComponentName(0, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setComponentName(aNbComps + 1, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setComponentDescription(0, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setComponentDescription(aNbComps + 1, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setMEDComponentUnit(0, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setMEDComponentUnit(aNbComps + 1, "str"), MEDEXCEPTION); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD::setComponentXXX() does not check component index"); +#endif + + // iteration information + int anIterNumber = 10; // set value to MED_NOPDT if undefined (default) + theField_->setIterationNumber(anIterNumber); + CPPUNIT_ASSERT_EQUAL(anIterNumber, theField_->getIterationNumber()); + + int anOrderNumber = 1; // set value to MED_NONOR if undefined (default) + theField_->setOrderNumber(anOrderNumber); + CPPUNIT_ASSERT_EQUAL(anOrderNumber, theField_->getOrderNumber()); + + double aTime = 3.435678; // in second + theField_->setTime(aTime); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aTime, theField_->getTime(), 0.0000001); + + // Value + int nbOfValues = 10; + // dangerous method, because it does not reallocate values array + theField_->setNumberOfValues(nbOfValues); + CPPUNIT_ASSERT_EQUAL(nbOfValues, theField_->getNumberOfValues()); + + // Value type and Interlacing type + CPPUNIT_ASSERT_EQUAL(theValueType, theField_->getValueType()); + CPPUNIT_ASSERT_EQUAL(theInterlace, theField_->getInterlacingType()); +} + +template<class T, class INTERLACING_TAG> +void compareField(const FIELD<T, INTERLACING_TAG> * theField_1, + const FIELD<T, INTERLACING_TAG> * theField_2, bool isValue) +{ + // compare FIELD_ part + compareField_(theField_1, theField_2, /*isFIELD = */true, isValue); + + // compare FIELD part + // TO DO +} + +template<class T, class INTERLACING_TAG> +void checkField (FIELD<T, INTERLACING_TAG> * theField, const SUPPORT * theSupport) +{ + // check FIELD_ part + MED_EN::med_type_champ aValueType = SET_VALUE_TYPE<T>::_valueType; + MED_EN::medModeSwitch anInterlace = SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType; + checkField_(theField, theSupport, aValueType, anInterlace); + + // check FIELD part + + // filling by support charackteristics (NOT IMPLEMENTED METHODS!!!): + // value type must be MED_REEL64 (i.e. a FIELD<double>) for these methods, + // nb. of components must be equal 1 (for Volume, Area, Length) or + // space dimension (for Normal, Barycenter, ) + { + MESH* aMesh = theSupport->getMesh(); + int spaceDim = 3; + if (aMesh) spaceDim = aMesh->getSpaceDimension(); + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */spaceDim + 1); + + CPPUNIT_ASSERT_THROW(theField->getVolume(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getArea(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getLength(), MEDEXCEPTION); + if (aMesh) { + CPPUNIT_ASSERT_THROW(theField->getNormal(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getBarycenter(), MEDEXCEPTION); + } + + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */1); + if (aValueType == MED_EN::MED_REEL64) { + CPPUNIT_ASSERT_NO_THROW(theField->getVolume()); + CPPUNIT_ASSERT_NO_THROW(theField->getArea()); + CPPUNIT_ASSERT_NO_THROW(theField->getLength()); + } + else { + CPPUNIT_ASSERT_THROW(theField->getVolume(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getArea(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getLength(), MEDEXCEPTION); + } + + if (aMesh) { + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */spaceDim); + if (aValueType == MED_EN::MED_REEL64) { + CPPUNIT_ASSERT_NO_THROW(theField->getNormal()); + CPPUNIT_ASSERT_NO_THROW(theField->getBarycenter()); + } + else { + CPPUNIT_ASSERT_THROW(theField->getNormal(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getBarycenter(), MEDEXCEPTION); + } + } + } + + // values + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */2); + int nbElemSupport = theSupport->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); + CPPUNIT_ASSERT_EQUAL(nbElemSupport, theField->getNumberOfValues()); + +#ifdef ENABLE_FAULTS + // (BUG) FIELD::deallocValue() does not nullify _value pointer, + // that is why there can be failures in other methods + // (even if simply call deallocValue() two times) + theField->deallocValue(); + theField->getGaussPresence(); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD::deallocValue() does not nullify _value pointer"); +#endif + + // copy constructor + FIELD<T, INTERLACING_TAG> aField_copy1 (*theField); + //compareField(theField, &aField_copy1, /*isValue = */false); + compareField(theField, &aField_copy1, /*isValue = */true); + + // operator= +#ifdef ENABLE_FAULTS + // (BUG) This fails (Segmentation fault) if not set: + // _componentsNames or _componentsDescriptions, or _componentsUnits, or _MEDComponentsUnits + FIELD<T, INTERLACING_TAG> aField_copy2; + aField_copy2 = *theField; + //compareField(theField, &aField_copy2, /*isValue = */false); + compareField(theField, &aField_copy2, /*isValue = */true); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD_::operator=() fails if _componentsUnits is not set"); +#endif +} + +template<class T> +FIELD<T> * createFieldOnGroup(MESH* theMesh, const GROUP* theGroup, + const string theName, const string theDescr) +{ + FIELD<T> * aFieldOnGroup = new FIELD<T> (theGroup, /*NumberOfComponents = */2); + + aFieldOnGroup->setName(theName); + aFieldOnGroup->setDescription(theDescr); + + string aCompsNames[2] = {"Pos", "Neg"}; + string aCompsDescs[2] = {"+", "-"}; + string aCompsUnits[2] = {"unit1", "unit2"}; + + aFieldOnGroup->setComponentsNames(aCompsNames); + aFieldOnGroup->setComponentsDescriptions(aCompsDescs); + aFieldOnGroup->setMEDComponentsUnits(aCompsUnits); + + return aFieldOnGroup; +} + +double plus13 (double val) +{ + return val + 13; +} + +// function to calculate field values from coordinates of an element +// typedef void (*myFuncType)(const double * temp, T* output); +// size of temp array = space dim = 3 +// size of output array = nb. comps = 2 +void proj2d (const double * temp, double* output) +{ + // dimetric projection with coefficients: + // 1.0 along Oy and Oz, 0.5 along Ox + // + // ^ z (y_) + // | + // | + // .----> y (x_) + // / + // L x + // + // x_ = y - x * sqrt(2.) / 4. + // y_ = z - x * sqrt(2.) / 4. + + double dx = temp[0] * std::sqrt(2.) / 4.; + output[0] = temp[1] - dx; + output[1] = temp[2] - dx; +} + +void testDrivers() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string filename_wr = tmp_dir + "/myMedFieldfile.med"; + string filename_support_wr = tmp_dir + "/myMedSupportFiledfile.med"; + string filename22_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filenamevtk_wr = tmp_dir + "/myMedFieldfile22.vtk"; + string cp_file = "cp " + filename_rd + " " + filename_wr; + + string fieldname_celldouble_rd = "fieldcelldouble"; + string fieldname_celldouble_wr = fieldname_celldouble_rd + "_cpy"; + string fieldname_nodeint_rd = "fieldnodeint"; + string fieldname_nodeint_wr = fieldname_nodeint_rd + "_cpy"; + string fieldname_nodeint_wr1 = fieldname_nodeint_rd + "_cpy1"; + string meshname = "maa1"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filenamevtk_wr); + aRemover.Register(filename_support_wr); + + //Copy file + system(cp_file.c_str()); + + FIELD<int> aInvalidField; + //must throw becase only VTK_DRIVER or MED_DRIVER may be specified as driverType for FIELD + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(NO_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(GIBI_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(PORFLOW_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(ASCII_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + + ////////////////// + //TestRead Part// + ////////////////// + FIELD<double> *aField_1 = NULL; + CPPUNIT_ASSERT_NO_THROW(aField_1 = new FIELD<double>(MED_DRIVER, filename_rd, fieldname_celldouble_rd)); + + //Test read(int index) method + int IdDriver_rd = aField_1->addDriver(MED_DRIVER,filename_rd,fieldname_celldouble_rd); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Cannot open file, but file exist + CPPUNIT_ASSERT_NO_THROW(aField_1->read(IdDriver_rd)); +#endif + + //Test read(GENDRIVER & genDriver) method + //Creation a Driver + MED_FIELD_RDONLY_DRIVER21<int> *aMedRdFieldDriver21_1 = + new MED_FIELD_RDONLY_DRIVER21<int>(); + //Creation a Field + FIELD<int> *aField_2 = new FIELD<int>(); + aField_2->setName(fieldname_nodeint_rd); + aField_2->addDriver(*aMedRdFieldDriver21_1); + aField_2->read(*aMedRdFieldDriver21_1); + + /////////////////// + //Test Write Part// + /////////////////// + int IdDriver; + MESH *aMesh = new MESH(MED_DRIVER,filename_rd,meshname); + SUPPORT *aSupport = new SUPPORT(aMesh, "aSupport",MED_CELL); + FIELD<int> *aFieldSupport; +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_NO_THROW(aFieldSupport = + new FIELD<int>(aSupport, MED_DRIVER,filename_support_wr,fieldname_nodeint_rd)); + //(BUG) Can not open file + MED_FIELD_WRONLY_DRIVER21<int> * aFieldWrDriver21 = + new MED_FIELD_WRONLY_DRIVER21<int>(filename_support_wr,aFieldSupport); + aFieldWrDriver21->setFieldName(aFieldSupport->getName() + "_copy"); + CPPUNIT_ASSERT_NO_THROW(IdDriver= aFieldSupport->addDriver(*aFieldWrDriver21)); + CPPUNIT_ASSERT_NO_THROW(aFieldSupport->write(IdDriver)); + delete aFieldSupport; + delete aFieldWrDriver21; +#endif + + //Create fileds + FIELD<double> * aField_3 = new FIELD<double>(); + MED_FIELD_RDONLY_DRIVER21<double> *aMedRdFieldDriver21_2 = + new MED_FIELD_RDONLY_DRIVER21<double>(filename_rd, aField_3); + aMedRdFieldDriver21_2->open(); + aMedRdFieldDriver21_2->setFieldName(fieldname_celldouble_rd); + aMedRdFieldDriver21_2->read(); + aMedRdFieldDriver21_2->close(); + + //Test write(int index) method + //Add drivers to FIELDs + int IdDriver1 = -1; + try + { + IdDriver1 = aField_3->addDriver(MED_DRIVER,filename_wr,fieldname_celldouble_wr); + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + //Trying call write(int index) method with incorrect index +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aField_3->write(IdDriver1+1, fieldname_celldouble_wr),MEDEXCEPTION); + // => Segmentation fault +#endif + + //Write field to file +#ifdef ENABLE_FAULTS + try + { + aField_3->write(IdDriver1, fieldname_celldouble_wr); + // => Segmentation fault + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#endif + + CPPUNIT_ASSERT_NO_THROW(aField_3->rmDriver(IdDriver1)); + + //Test write(const GENDRIVER &); + //Create a driver + MED_FIELD_WRONLY_DRIVER21<int> *aMedWrFieldDriver21 = + new MED_FIELD_WRONLY_DRIVER21<int>(); + aMedWrFieldDriver21->setFileName(filename_wr); + aField_2->setName(fieldname_nodeint_wr1); + //Add driver to a field + aField_2->addDriver(*aMedWrFieldDriver21); + + try + { + aField_2->write(*aMedWrFieldDriver21); + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test writeAppend(int index) method + //Create a vtk file + MESH * aMesh_1 = new MESH(); + MED_MESH_RDONLY_DRIVER22 *aMedMeshRdDriver22 = new MED_MESH_RDONLY_DRIVER22(filename22_rd, aMesh_1); + aMedMeshRdDriver22->open(); + aMedMeshRdDriver22->setMeshName(meshname); + aMedMeshRdDriver22->read(); + aMedMeshRdDriver22->close(); + VTK_MESH_DRIVER *aVtkDriver = new VTK_MESH_DRIVER(filenamevtk_wr, aMesh_1); + aVtkDriver->open(); + aVtkDriver->write(); + aVtkDriver->close(); + + //Create a field + FIELD<int> * aField_4 = new FIELD<int>(); + MED_FIELD_RDONLY_DRIVER22<int> *aMedRdFieldDriver22 = + new MED_FIELD_RDONLY_DRIVER22<int>(filename22_rd, aField_2); + aMedRdFieldDriver22->open(); + aMedRdFieldDriver22->setFieldName(fieldname_nodeint_rd); + aMedRdFieldDriver22->read(); + aMedRdFieldDriver22->close(); + + //Add Driver to a field + int IdDriver2; + try + { + IdDriver2 = aField_4->addDriver(VTK_DRIVER, filenamevtk_wr ,fieldname_nodeint_wr); + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#ifdef ENABLE_FAULTS + //Trying call writeAppend() method with incorrect index + CPPUNIT_ASSERT_THROW(aField_4->writeAppend(IdDriver2+1,fieldname_nodeint_wr),MEDEXCEPTION); + // => Segmentation fault +#endif + +#ifdef ENABLE_FAULTS + // (BUG) => Segmentation fault + CPPUNIT_ASSERT_NO_THROW(aField_4->writeAppend(IdDriver2, fieldname_nodeint_wr)); +#endif + + //Test writeAppend(const GENDRIVER &) method + aField_4->setName(fieldname_nodeint_wr1); + + //Add driver to a field +#ifdef ENABLE_FAULTS + //Create a driver + VTK_FIELD_DRIVER<int> *aVtkFieldDriver = new VTK_FIELD_DRIVER<int>(filenamevtk_wr, aField_4); + CPPUNIT_ASSERT_NO_THROW(aField_4->addDriver(*aVtkFieldDriver)); + //(BUG) => Segmentation fault after addDriver(const GENDRIVER &) + CPPUNIT_ASSERT_NO_THROW(aField_4->writeAppend(*aVtkFieldDriver)); +#endif + + + //Delete objects + delete aField_1; + delete aMedRdFieldDriver21_1; + delete aField_2; + delete aField_3; + delete aMedRdFieldDriver21_2; + delete aField_4; + delete aMedMeshRdDriver22; + delete aMedWrFieldDriver21; + delete aVtkDriver; + delete aMesh; + delete aMesh_1; + delete aMedRdFieldDriver22; + delete aSupport; +} + +void MEDMEMTest::testField() +{ + SUPPORT anEmptySupport; + //////////////////// + // TEST 1: FIELD_ // + //////////////////// + FIELD_ aField_; + + // check set/get methods + MED_EN::med_type_champ aValueType = MED_EN::MED_UNDEFINED_TYPE; + MED_EN::medModeSwitch anInterlace = MED_EN::MED_UNDEFINED_INTERLACE; + checkField_(&aField_, &anEmptySupport, aValueType, anInterlace); + + // copy constructor + // This fails (Segmentation fault) if not set: + // _componentsNames or _componentsDescriptions, or _MEDComponentsUnits + FIELD_ aField_copy1 (aField_); + compareField_(&aField_, &aField_copy1, /*isFIELD = */false, /*isValue = */false); + + // operator= +#ifdef ENABLE_FAULTS + // (BUG) This fails (Segmentation fault) if not set: + // _componentsNames or _componentsDescriptions, or _componentsUnits, or _MEDComponentsUnits + // (BUG) Code duplication with copyGlobalInfo(), called from copy constructor + FIELD_ aField_copy2; + aField_copy2 = aField_; + compareField_(&aField_, &aField_copy2, /*isFIELD = */false, /*isValue = */false); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD_::operator=() fails if _componentsUnits is not set"); +#endif + + // construction on a given support + { + anEmptySupport.setTotalNumberOfElements(11); + // CASE1: + FIELD_ aField_case1 (&anEmptySupport, 10); + // CASE2: + FIELD_ aField_case2; + aField_case2.setSupport(&anEmptySupport); + aField_case2.setNumberOfComponents(10); + +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_EQUAL_MESSAGE("No correspondance between CASE1 and CASE2", + aField_case1.getNumberOfValues(), + aField_case2.getNumberOfValues()); +#endif + } + + //////////////////////// + // TEST 2: FIELD<int> // + //////////////////////// + FIELD<int> aFieldInt; + checkField(&aFieldInt, &anEmptySupport); + + //////////////////////////////////////// + // TEST 3: FIELD<double, NoInterlace> // + //////////////////////////////////////// + MESH * aMesh = MEDMEMTest_createTestMesh(); + const GROUP* aGroup = aMesh->getGroup(MED_EN::MED_FACE, 1); + + FIELD<double, NoInterlace> aFieldDouble; + checkField(&aFieldDouble, aGroup); + + ////////////////////////////////////////// + // TEST 4: FIELD<double, FullInterlace> // + ////////////////////////////////////////// + FIELD<double> * aFieldOnGroup1 = createFieldOnGroup<double>(aMesh, aGroup, "Linear", "N"); + FIELD<double> * aFieldOnGroup2 = createFieldOnGroup<double>(aMesh, aGroup, "Quadratic", "N**2"); + + int nbVals = aFieldOnGroup1->getNumberOfValues(); + CPPUNIT_ASSERT(nbVals); + + // numbers of elements in group, + // they are needed in method FIELD::setValueIJ() + const int *anElems = aGroup->getnumber()->getValue(); + double eucl1 = 0., eucl2 = 0.; + + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup1->setValueIJ(anElems[i-1], 1, (double)i); + aFieldOnGroup1->setValueIJ(anElems[i-1], 2, (double)(-i)); + + aFieldOnGroup2->setValueIJ(anElems[i-1], 1, (double)i*i); + aFieldOnGroup2->setValueIJ(anElems[i-1], 2, (double)(-i*i)); + + eucl1 += 2. * i * i; + eucl2 += 2. * i * i * i * i; + } + + // out of bound (inexisting 33-th component of last element) + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->setValueIJ(anElems[nbVals-1], 33, 10.), MEDEXCEPTION); + + // normMax + CPPUNIT_ASSERT_DOUBLES_EQUAL(nbVals, aFieldOnGroup1->normMax(), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(nbVals*nbVals, aFieldOnGroup2->normMax(), 0.000001); + + // norm2 + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(eucl1), aFieldOnGroup1->norm2(), 0.000001); // 10.4881 + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(eucl2), aFieldOnGroup2->norm2(), 0.000001); // 44.2493 + + // check getXXX methods + CPPUNIT_ASSERT(!aFieldOnGroup1->getGaussPresence()); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getArrayGauss(), MEDEXCEPTION); + MEDMEM_ArrayInterface<double, FullInterlace,NoGauss>::Array * anArrayNoGauss = + aFieldOnGroup1->getArrayNoGauss(); + + MEDMEM_Array_ * aMEDMEM_Array_ = aFieldOnGroup1->getArray(); + MEDMEM_ArrayInterface<double, FullInterlace,NoGauss>::Array * aMEDMEM_Array_conv = + static_cast<MEDMEM_ArrayInterface<double, FullInterlace,NoGauss>::Array *>(aMEDMEM_Array_); + + const double * aValues = aFieldOnGroup1->getValue(); + + // out of range + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getColumn(3), MEDEXCEPTION); + // cannot get column in FullInterlace + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getColumn(1), MEDEXCEPTION); + + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , aFieldOnGroup1->getValueIJK(anElems[i-1], 1, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), aFieldOnGroup1->getValueIJK(anElems[i-1], 2, 1), 0.000001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , aValues[(i-1)*2 + 0], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), aValues[(i-1)*2 + 1], 0.000001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , anArrayNoGauss->getIJ(i, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), anArrayNoGauss->getIJ(i, 2), 0.000001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , aMEDMEM_Array_conv->getIJ(i, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), aMEDMEM_Array_conv->getIJ(i, 2), 0.000001); + + const double* row_i = aFieldOnGroup1->getRow(anElems[i-1]); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , row_i[0], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), row_i[1], 0.000001); + + double vals_i [2]; + aFieldOnGroup1->getValueOnElement(anElems[i-1], vals_i); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , vals_i[0], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), vals_i[1], 0.000001); + } + + // modify all values of aFieldOnGroup2 by formula a*x + b (a = 2, b = 3) + aFieldOnGroup2->applyLin(2., 3.); + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(3. + 2.*i*i, aFieldOnGroup2->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3. - 2.*i*i, aFieldOnGroup2->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // apply function plus13() to aFieldOnGroup1 + aFieldOnGroup1->applyFunc<plus13>(); + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // scalarProduct + FIELD<double, FullInterlace> * aScalarProduct = + FIELD<double, FullInterlace>::scalarProduct(*aFieldOnGroup1, *aFieldOnGroup2, /*deepCheck = */true); + CPPUNIT_ASSERT_EQUAL(nbVals, aScalarProduct->getNumberOfValues()); + CPPUNIT_ASSERT_EQUAL(1, aScalarProduct->getNumberOfComponents()); + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(78. + 4.*i*i*i, //(3. + 2.*i*i)*(13 + i) + (3. - 2.*i*i)*(13 - i) + aScalarProduct->getValueIJ(anElems[i-1], 1), 0.000001); + } + + // fillFromAnalytic + aFieldOnGroup2->fillFromAnalytic(proj2d); + + double bary [3]; + double outp [2]; + const SUPPORT * aSupp = aFieldOnGroup2->getSupport(); + FIELD<double,FullInterlace> * barycenter = aMesh->getBarycenter(aSupp); + for (int i = 1; i <= nbVals; i++) { + bary[0] = barycenter->getValueIJ(anElems[i-1], 1); + bary[1] = barycenter->getValueIJ(anElems[i-1], 2); + bary[2] = barycenter->getValueIJ(anElems[i-1], 3); + + proj2d(bary, outp); + + //cout << "barycenter (" << bary[0] << ", " << bary[1] << ", " << bary[2] << ")" << endl; + //cout << "proj2d (" << outp[0] << ", " << outp[1] << ")" << endl; + + //bary (-0.666667, 0.666667, 0.666667) -> outp ( 0.902369, 0.902369) + //bary ( 0.666667, -0.666667, 0.666667) -> outp (-0.902369, 0.430964) + //bary ( 0. , 0. , 2. ) -> outp ( 0. , 2. ) + //bary ( 0. , 0. , 3. ) -> outp ( 0. , 3. ) + //bary (-1. , 0. , 2.5 ) -> outp ( 0.353553, 2.85355 ) + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) in FIELD::fillFromAnalytic() in case of support, different from nodes: + // barycenterField in FullInterlace, but values extracted like from NoInterlace + CPPUNIT_ASSERT_DOUBLES_EQUAL(outp[0], aFieldOnGroup2->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(outp[1], aFieldOnGroup2->getValueIJ(anElems[i-1], 2), 0.000001); +#endif + + // currently it gives values, that are wrong: + //aFieldOnGroup2 row1 ( 0.902369, 0.235702) + //aFieldOnGroup2 row2 (-0.235702, 2.7643 ) + //aFieldOnGroup2 row3 (-0.235702, -1.2357 ) + //aFieldOnGroup2 row4 ( 1.7643 , -0.235702) + //aFieldOnGroup2 row5 ( 0.235702, 2.7357 ) + } + + // info about support (Group1) + CPPUNIT_ASSERT(!aFieldOnGroup1->isOnAllElements()); // because we build Group1 so + int nbTypes = aFieldOnGroup1->getNumberOfGeometricTypes(); + //CPPUNIT_ASSERT(nbTypes); + CPPUNIT_ASSERT_EQUAL(2, nbTypes); + const int * nbElemsInEachType = aFieldOnGroup1->getNumberOfElements(); + const MED_EN::medGeometryElement * aGeomTypes = aFieldOnGroup1->getGeometricTypes(); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aGeomTypes[0]); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aGeomTypes[1]); + + // GAUSS + + // now we have no gauss localization in aFieldOnGroup1 + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA6), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalization(MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalizationPtr(MED_EN::MED_TRIA3), MEDEXCEPTION); + + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNbGaussI(anElems[0])); + + // set a gauss localization into aFieldOnGroup1 + double cooRef[6] = {1.,1., 2.,4., 3.,9.}; // xy xy xy + double cooGauss[10] = {7.,7., 6.,6., 5.,5., 4.,3., 2.,1.}; // x1,y1 x2,y2 x3,y3 x4,y4 x5,y5 + double wg[5] = {1., 2., 3., 4., 5.}; + GAUSS_LOCALIZATION<> gl1 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg); + + aFieldOnGroup1->setGaussLocalization(MED_EN::MED_TRIA3, gl1); + + // now we have a gauss localization for MED_TRIA3 type + CPPUNIT_ASSERT_EQUAL(5, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA6), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalization(MED_EN::MED_QUAD4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalizationPtr(MED_EN::MED_QUAD4), MEDEXCEPTION); + + GAUSS_LOCALIZATION<> gl1Back = aFieldOnGroup1->getGaussLocalization(MED_EN::MED_TRIA3); + const GAUSS_LOCALIZATION<> * gl1BackPtr = aFieldOnGroup1->getGaussLocalizationPtr(MED_EN::MED_TRIA3); + + CPPUNIT_ASSERT(gl1 == gl1Back); + CPPUNIT_ASSERT(gl1 == *gl1BackPtr); + + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNbGaussI(anElems[0])); + + // sub-support of Group1 on one (first) geometric type + SUPPORT * aSubSupport1 = new SUPPORT(aMesh, "Sub-Support 1 of Group1", MED_EN::MED_FACE); + aSubSupport1->setAll(false); + + int nbTypes1 = 1; + int nbElemsInEachType1[1]; + nbElemsInEachType1[0] = nbElemsInEachType[0]; + int nbElems1 = nbElemsInEachType1[0]; + MED_EN::medGeometryElement aGeomTypes1[1]; + aGeomTypes1[0] = aGeomTypes[0]; + int * anElems1 = new int[nbElems1]; + for (int i = 0; i < nbElems1; i++) { + anElems1[i] = anElems[i]; + } + + aSubSupport1->setpartial("Support for sub-field 1 on one type of elements", + nbTypes1, nbElems1, aGeomTypes1, nbElemsInEachType1, anElems1); + + //cout << "aSubSupport1:" << endl; + //cout << *aSubSupport1 << endl; + + // extract sub-field on aSubSupport1 + FIELD<double, FullInterlace> * aSubField1 = aFieldOnGroup1->extract(aSubSupport1); + CPPUNIT_ASSERT_EQUAL(nbElems1 * /*NumberOfComponents = */2, aSubField1->getValueLength()); + + // aSubField1: + // elt\comp | 1 | 2 + //-------------------- + // 1 | 14 | 12 + // 2 | 15 | 11 + + // check normL2() and normL1() + FIELD<double>* anAreaField = aMesh->getArea(aSubSupport1); + double area1 = anAreaField->getValueIJ(anElems1[0], 1); + double area2 = anAreaField->getValueIJ(anElems1[1], 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.44949, area1, 0.00001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.44949, area2, 0.00001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(210.5, aSubField1->normL2(1), 0.00001); // (14*14 + 15*15)/2 +#ifdef ENABLE_FORCED_FAILURES + // (BUG) FIELD::normL2(int component, const FIELD * p_field_volume): + // component is not taken into account + CPPUNIT_ASSERT_DOUBLES_EQUAL(132.5, aSubField1->normL2(2), 0.00001); // (12*12 + 11*11)/2 +#endif + CPPUNIT_ASSERT_DOUBLES_EQUAL(343.0, aSubField1->normL2() , 0.00001); // 210.5 + 132.5 + + CPPUNIT_ASSERT_DOUBLES_EQUAL(14.5, aSubField1->normL1(1), 0.00001); // (14 + 15)/2 + CPPUNIT_ASSERT_DOUBLES_EQUAL(11.5, aSubField1->normL1(2), 0.00001); // (12 + 11)/2 + CPPUNIT_ASSERT_DOUBLES_EQUAL(26.0, aSubField1->normL1() , 0.00001); // 14.5 + 11.5 + + double aNewArea [2] = {1., 0.}; // only first element will be taken into account + anAreaField->setValue(aNewArea); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(196.0, aSubField1->normL2(1, anAreaField), 0.00001); // 14*14/1 +#ifdef ENABLE_FORCED_FAILURES + // (BUG) FIELD::normL2(int component, const FIELD * p_field_volume): + // component is not taken into account + CPPUNIT_ASSERT_DOUBLES_EQUAL(144.0, aSubField1->normL2(2, anAreaField), 0.00001); // 12*12/1 +#endif + CPPUNIT_ASSERT_DOUBLES_EQUAL(340.0, aSubField1->normL2(anAreaField) , 0.00001); // 196 + 144 + + CPPUNIT_ASSERT_DOUBLES_EQUAL(14.0, aSubField1->normL1(1, anAreaField), 0.00001); // 14/1 + CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, aSubField1->normL1(2, anAreaField), 0.00001); // 12/1 + CPPUNIT_ASSERT_DOUBLES_EQUAL(26.0, aSubField1->normL1(anAreaField) , 0.00001); // 14 + 12 + + // applyPow + aSubField1->applyPow(2.); + CPPUNIT_ASSERT_DOUBLES_EQUAL(196., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); // 14*14 + CPPUNIT_ASSERT_DOUBLES_EQUAL(144., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); // 12*12 + CPPUNIT_ASSERT_DOUBLES_EQUAL(225., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); // 15*15 + CPPUNIT_ASSERT_DOUBLES_EQUAL(121., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); // 11*11 + + // setArray (NoGauss) + MEDMEM_ArrayInterface<double,FullInterlace,NoGauss>::Array * aNewArrayNoGauss = + new MEDMEM_ArrayInterface<double,FullInterlace,NoGauss>::Array(/*dim*/2, /*nbelem*/2); + aNewArrayNoGauss->setIJ(1, 1, 4.); + aNewArrayNoGauss->setIJ(1, 2, 2.); + aNewArrayNoGauss->setIJ(2, 1, 5.); + aNewArrayNoGauss->setIJ(2, 2, 1.); + aSubField1->setArray(aNewArrayNoGauss); + // no need to delete aNewArrayNoGauss, because it will be deleted + // in destructor or in deallocValue() method of aSubField1 + + CPPUNIT_ASSERT_DOUBLES_EQUAL(4., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); + + // setRow + double row[2] = {-1., -3.}; + aSubField1->setRow(anElems1[0], row); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-1., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-3., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); + // out of range + CPPUNIT_ASSERT_THROW(aSubField1->setRow(3, row), MEDEXCEPTION); + + // setColumn + double col[2] = {-7., -9.}; + aSubField1->setColumn(1, col); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-7., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-3., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) in MEDMEM_Array::setColumn() + CPPUNIT_ASSERT_DOUBLES_EQUAL(-9., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); +#endif + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); + // out of range + CPPUNIT_ASSERT_THROW(aSubField1->setColumn(3, col), MEDEXCEPTION); + + // setArray (Gauss) + { + int nbelgeoc[2] = {1, 3}; // 3 - 1 = two elements for the first (and the only) type + int nbgaussgeo[2] = {-1, 1}; // one gauss point per each element + MEDMEM_ArrayInterface<double,FullInterlace,Gauss>::Array * aNewArrayGauss = + new MEDMEM_ArrayInterface<double,FullInterlace,Gauss>::Array + (/*dim*/2, /*nbelem*/2, /*nbtypegeo*/1, /*nbelgeoc*/nbelgeoc, /*nbgaussgeo*/nbgaussgeo); + +#ifdef ENABLE_FAULTS + aNewArrayGauss->setIJ(1, 1, -4.); + aNewArrayGauss->setIJ(1, 2, -2.); + aNewArrayGauss->setIJ(2, 1, -5.); + aNewArrayGauss->setIJ(2, 2, -1.); +#endif +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) in FullInterlaceGaussPolicy::getIndex(int i,int j) + // FullInterlaceGaussPolicy::getIndex(2,2) returns 4!!! + CPPUNIT_FAIL("? Bug in FullInterlaceGaussPolicy::getIndex(int i,int j) ?"); +#endif + + aNewArrayGauss->setIJK(1, 1, 1, -4.); + aNewArrayGauss->setIJK(1, 2, 1, -2.); + aNewArrayGauss->setIJK(2, 1, 1, -5.); + aNewArrayGauss->setIJK(2, 2, 1, -1.); + + aSubField1->setArray(aNewArrayGauss); + // no need to delete aNewArrayGauss, because it will be deleted + // in destructor or in deallocValue() method of aSubField1 + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_DOUBLES_EQUAL(-4., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-5., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); +#endif +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) in FullInterlaceGaussPolicy::getIndex(int i,int j) + // Must be : return _G[i-1]-1 + (j-1); + // Instead of: return _G[i-1]-1 + (j-1)*_dim; + CPPUNIT_FAIL("? Bug in FullInterlaceGaussPolicy::getIndex(int i,int j) ?"); +#endif + + CPPUNIT_ASSERT_DOUBLES_EQUAL(-4., aSubField1->getValueIJK(anElems1[0], 1, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2., aSubField1->getValueIJK(anElems1[0], 2, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-5., aSubField1->getValueIJK(anElems1[1], 1, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-1., aSubField1->getValueIJK(anElems1[1], 2, 1), 0.000001); + } + + // alloc/dealloc; compatibility of new size with support + try { + aSubField1->deallocValue(); + aSubField1->allocValue(/*NumberOfComponents*/2, /*LengthValue*/5); +#ifdef ENABLE_FAULTS + // (BUG) No compatibility between Support and allocated value + aSubField1->normL1(); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("Error: no compatibility between Support and allocated value"); +#endif + } + catch (MEDEXCEPTION & ex) { + // normal behaviour + } + catch (...) { + CPPUNIT_FAIL("Error: no compatibility between Support and allocated value"); + } + + // check that aFieldOnGroup1 is not changed after aSubField1 modifications + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // reset aFieldOnGroup2 values for simple control of operators results + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup2->setValueIJ(anElems[i-1], 1, i*i); + aFieldOnGroup2->setValueIJ(anElems[i-1], 2, -i*i); + } + + int len = aFieldOnGroup1->getValueLength(); + const double * val1 = aFieldOnGroup1->getValue(); + const double * val2 = aFieldOnGroup2->getValue(); + const double * val_res; + + // operators and add, sub, mul, div + + // + + FIELD<double> aSum = *aFieldOnGroup1 + *aFieldOnGroup2; + aSum.setName(aFieldOnGroup1->getName()); + aSum.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aSum, true, true); + val_res = aSum.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val2[i], val_res[i], 0.000001); + } + + // - + FIELD<double> aDifference = *aFieldOnGroup1 - *aFieldOnGroup2; + aDifference.setName(aFieldOnGroup1->getName()); + aDifference.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aDifference, true, true); + val_res = aDifference.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] - val2[i], val_res[i], 0.000001); + } + + // - (unary) + FIELD<double> aNegative = - *aFieldOnGroup1; + aNegative.setName(aFieldOnGroup1->getName()); + aNegative.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aNegative, true, true); + val_res = aNegative.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(- val1[i], val_res[i], 0.000001); + } + + // * + FIELD<double> aProduct = (*aFieldOnGroup1) * (*aFieldOnGroup2); + aProduct.setName(aFieldOnGroup1->getName()); + aProduct.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aProduct, true, true); + val_res = aProduct.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] * val2[i], val_res[i], 0.000001); + } + + // / + FIELD<double> aQuotient = *aFieldOnGroup1 / *aFieldOnGroup2; + aQuotient.setName(aFieldOnGroup1->getName()); + aQuotient.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aQuotient, true, true); + val_res = aQuotient.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] / val2[i], val_res[i], 0.000001); + } + + double val22 = aFieldOnGroup2->getValueIJ(anElems[2], 2); + aFieldOnGroup2->setValueIJ(anElems[2], 2, 0.); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 / *aFieldOnGroup2, MEDEXCEPTION); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) is it up to user to control validity of data to avoid division on zero? + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 /= *aFieldOnGroup2, MEDEXCEPTION); +#endif + CPPUNIT_ASSERT_THROW(FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + + // restore value + aFieldOnGroup2->setValueIJ(anElems[2], 2, val22); + + // restore values + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup1->setValueIJ(anElems[i-1], 1, 13 + i); + aFieldOnGroup1->setValueIJ(anElems[i-1], 2, 13 - i); + } + + // static methods + FIELD<double> * aPtr; + + // add + aPtr = FIELD<double>::add(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // sub + aPtr = FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] - val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // mul + aPtr = FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] * val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // div + aPtr = FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] / val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // addDeep + aPtr = FIELD<double>::addDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // subDeep + aPtr = FIELD<double>::subDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] - val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // mulDeep + aPtr = FIELD<double>::mulDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] * val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // divDeep + aPtr = FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] / val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // += + *aFieldOnGroup1 += *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i + i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i - i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // -= + *aFieldOnGroup1 -= *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // *= + *aFieldOnGroup1 *= *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( (13 + i)*i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-(13 - i)*i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // /= + *aFieldOnGroup1 /= *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // check case of different operands: support + MESH * aMeshOneMore = MEDMEMTest_createTestMesh(); + const GROUP* aGroupOneMore = aMeshOneMore->getGroup(MED_EN::MED_FACE, 1); + FIELD<double> * aFieldOnGroup3 = + createFieldOnGroup<double>(aMeshOneMore, aGroupOneMore, "Test_Diff_Mesh", "test"); + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup3->setValueIJ(anElems[i-1], 1, 2*i); + aFieldOnGroup3->setValueIJ(anElems[i-1], 2, 3*i); + } + const double * val3 = aFieldOnGroup3->getValue(); + + //CPPUNIT_ASSERT_NO_THROW(); + try { + aPtr = FIELD<double>::addDeep(*aFieldOnGroup1, *aFieldOnGroup3); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val3[i], val_res[i], 0.000001); + } + delete aPtr; + + aPtr = FIELD<double>::subDeep(*aFieldOnGroup1, *aFieldOnGroup3); + delete aPtr; + aPtr = FIELD<double>::mulDeep(*aFieldOnGroup1, *aFieldOnGroup3); + delete aPtr; + aPtr = FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup3); + delete aPtr; + } + catch (MEDEXCEPTION & ex) { + CPPUNIT_FAIL(ex.what()); + } + catch (...) { + CPPUNIT_FAIL("Unknown exception in FIELD::xxxDeep()"); + } + + CPPUNIT_ASSERT_THROW(FIELD<double>::add(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 + *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 - *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 * *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 / *aFieldOnGroup3, MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 += *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 -= *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 *= *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 /= *aFieldOnGroup3, MEDEXCEPTION); + + // check case of different operands: MEDComponentsUnits + aFieldOnGroup1->setMEDComponentUnit(1, "unit3"); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 + *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 - *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 += *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 -= *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::add(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::addDeep(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::subDeep(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + + //CPPUNIT_ASSERT_NO_THROW(); + try { + aPtr = FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + aPtr = FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + aPtr = FIELD<double>::mulDeep(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + aPtr = FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + + *aFieldOnGroup1 *= *aFieldOnGroup2; + *aFieldOnGroup1 /= *aFieldOnGroup2; + + FIELD<double> aPr = *aFieldOnGroup1 * *aFieldOnGroup2; + FIELD<double> aQu = *aFieldOnGroup1 / *aFieldOnGroup2; + } + catch (MEDEXCEPTION & ex) { + CPPUNIT_FAIL(ex.what()); + } + catch (...) { + CPPUNIT_FAIL("Unknown exception"); + } + + // restore MED units + aFieldOnGroup1->setMEDComponentUnit(1, "unit1"); + + // check case of different operands: valueType + //FIELD<int> * aFieldOnGroup4 = + // createFieldOnGroup<int>(aMeshOneMore, aGroupOneMore, "Test_Diff_Mesh", "test"); + // + //CPPUNIT_ASSERT_THROW(FIELD<double>::add(*aFieldOnGroup4, *aFieldOnGroup3), MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(*aFieldOnGroup4 - *aFieldOnGroup3, MEDEXCEPTION); + //CPPUNIT_ASSERT_THROW(*aFieldOnGroup4 *= *aFieldOnGroup3, MEDEXCEPTION); + //delete aFieldOnGroup4; + + // check case of different operands: numberOfComponents +#ifdef ENABLE_FAULTS + // (BUG) Cannot allocate value of higher dimension because of _componentsTypes reinitialization + aFieldOnGroup1->deallocValue(); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->allocValue(/*dim*/5), MEDEXCEPTION); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("Segmentation fault on attempt to allocate value of higher dimension." + " Must be MEDEXCEPTION instead. And on attempt to change nb.components" + " must be the same behaviour."); +#endif + aFieldOnGroup1->setNumberOfComponents(5); + + CPPUNIT_ASSERT_THROW(FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 * *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 /= *aFieldOnGroup2, MEDEXCEPTION); + + // check case of different operands: numberOfValues + aFieldOnGroup1->deallocValue(); + aFieldOnGroup1->allocValue(2, nbVals + 1); + // be carefull: aFieldOnGroup1 reallocated and contains random values + + CPPUNIT_ASSERT_THROW(FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 / *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 += *aFieldOnGroup2, MEDEXCEPTION); + + // restore aFieldOnGroup1 + aFieldOnGroup1->deallocValue(); + aFieldOnGroup1->allocValue(2, nbVals); + // be carefull: aFieldOnGroup1 reallocated and contains random values + + delete aSubSupport1; + delete [] anElems1; + + delete aScalarProduct; + delete aSubField1; + delete anAreaField; + delete barycenter; + delete aFieldOnGroup1; + delete aFieldOnGroup2; + delete aFieldOnGroup3; + + delete aMesh; + delete aMeshOneMore; + + ///////////////////// + // TEST 5: Drivers // + ///////////////////// + testDrivers(); +} + +/*! + * Check methods (2), defined in MEDMEM_FieldConvert.hxx: + * (+) template <class T> FIELD<T,FullInterlace> * FieldConvert(const FIELD<T,NoInterlace> & field); + * (+) template <class T> FIELD<T,NoInterlace> * FieldConvert(const FIELD<T,FullInterlace> & field); + */ +void MEDMEMTest::testFieldConvert() +{ + // create an empty integer field 2x10 + FIELD<int, FullInterlace> * aField_FING = new FIELD<int, FullInterlace> (); + + aField_FING->setName("Field_FING"); + aField_FING->setDescription("Field full interlace no gauss"); + + aField_FING->setNumberOfComponents(2); + aField_FING->setNumberOfValues(10); + + string aCompsNames[2] = {"Pos", "Neg"}; + string aCompsDescs[2] = {"+", "-"}; + string aMEDCompsUnits[2] = {"unit1", "unit2"}; + UNIT aCompsUnits[2]; + + aCompsUnits[0] = UNIT("u1", "descr1"); + aCompsUnits[1] = UNIT("u2", "descr2"); + + aField_FING->setComponentsNames(aCompsNames); + aField_FING->setComponentsDescriptions(aCompsDescs); + aField_FING->setMEDComponentsUnits(aMEDCompsUnits); + aField_FING->setComponentsUnits(aCompsUnits); + + // check UNITs (for testField()) + const UNIT * aCompsUnitsBack = aField_FING->getComponentsUnits(); + CPPUNIT_ASSERT(aCompsUnits[0].getName() == aCompsUnitsBack[0].getName()); + CPPUNIT_ASSERT(aCompsUnits[1].getName() == aCompsUnitsBack[1].getName()); + + const UNIT * aCompUnitBack1 = aField_FING->getComponentUnit(1); + const UNIT * aCompUnitBack2 = aField_FING->getComponentUnit(2); + CPPUNIT_ASSERT(aCompsUnits[0].getName() == aCompUnitBack1->getName()); + CPPUNIT_ASSERT(aCompsUnits[1].getName() == aCompUnitBack2->getName()); + + // create one more field by copy + FIELD<int, FullInterlace> * aField_FIGG = new FIELD<int, FullInterlace> (*aField_FING); + + // values + int values_FING[20] = { 7,- 7, 14,-14, 21,-21, 28,-28, 35,-35, + 42,-42, 49,-49, 56,-56, 63,-63, 70,-70}; + + ///////////////////// + // TEST 1: NoGauss // + ///////////////////// + + MEDMEM_ArrayInterface<int,FullInterlace,NoGauss>::Array * anArray_FING = + new MEDMEM_ArrayInterface<int,FullInterlace,NoGauss>::Array + (values_FING, /*dim*/2, /*nbelem*/10, /*shallowCopy*/false, /*ownershipOfValues*/false); + aField_FING->setArray(anArray_FING); + // no need to delete anArray_FING, because it will be deleted in destructor of aField_FING + + // 1. FullInterlace -> NoInterlace + FIELD<int, NoInterlace> * aField_NING = FieldConvert(*aField_FING); + const int * values_NING = aField_NING->getValue(); + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 2; j++) { + CPPUNIT_ASSERT_EQUAL(values_FING[2*i + j], values_NING[10*j + i]); + } + } + + // 2. NoInterlace -> FullInterlace + FIELD<int, FullInterlace> * aField_FING_conv = FieldConvert(*aField_NING); + const int * values_FING_conv = aField_FING_conv->getValue(); + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 2; j++) { + CPPUNIT_ASSERT_EQUAL(values_FING_conv[2*i + j], values_FING[2*i + j]); + CPPUNIT_ASSERT_EQUAL(values_FING_conv[2*i + j], values_NING[10*j + i]); + } + } + + delete aField_FING; + delete aField_NING; + delete aField_FING_conv; + + /////////////////// + // TEST 2: Gauss // + /////////////////// + int nbelgeoc[2] = {1, 11}; + int nbgaussgeo[2] = {-1, 1}; + MEDMEM_ArrayInterface<int,FullInterlace,Gauss>::Array * anArray_FIGG = + new MEDMEM_ArrayInterface<int,FullInterlace,Gauss>::Array + (values_FING, /*dim*/2, /*nbelem*/10, /*nbtypegeo*/1, /*nbelgeoc*/nbelgeoc, + /*nbgaussgeo*/nbgaussgeo, /*shallowCopy*/false, /*ownershipOfValues*/false); + aField_FIGG->setArray(anArray_FIGG); + // no need to delete anArray_FIGG, because it will be deleted in destructor of aField_FIGG + + // 1. FullInterlace -> NoInterlace + FIELD<int, NoInterlace> * aField_NIGG = FieldConvert(*aField_FIGG); + const int * values_NIGG = aField_NIGG->getValue(); + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 2; j++) { + CPPUNIT_ASSERT_EQUAL(values_FING[2*i + j], values_NIGG[10*j + i]); + } + } + + // 2. NoInterlace -> FullInterlace + FIELD<int, FullInterlace> * aField_FIGG_conv = FieldConvert(*aField_NIGG); + const int * values_FIGG_conv = aField_FIGG_conv->getValue(); + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 2; j++) { + CPPUNIT_ASSERT_EQUAL(values_FIGG_conv[2*i + j], values_FING[2*i + j]); + CPPUNIT_ASSERT_EQUAL(values_FIGG_conv[2*i + j], values_NIGG[10*j + i]); + } + } + + delete aField_FIGG; + delete aField_NIGG; + delete aField_FIGG_conv; + +#ifdef ENABLE_FAULTS + // (BUG) in FieldConvert(), concerning FIELD_::operator= + { + // create an empty integer field 2x10 + FIELD<int, FullInterlace> * aField = new FIELD<int, FullInterlace> (); + + aField->setName("aField"); + aField->setDescription("Field full interlace no gauss"); + + aField->setNumberOfComponents(2); + aField->setNumberOfValues(10); + + aField->setComponentsNames(aCompsNames); + aField->setComponentsDescriptions(aCompsDescs); + aField->setMEDComponentsUnits(aMEDCompsUnits); + + MEDMEM_ArrayInterface<int,FullInterlace,NoGauss>::Array * anArray = + new MEDMEM_ArrayInterface<int,FullInterlace,NoGauss>::Array + (values_FING, /*dim*/2, /*nbelem*/10, /*shallowCopy*/false, /*ownershipOfValues*/false); + aField->setArray(anArray); + // no need to delete anArray, because it will be deleted in destructor of aField + + FIELD<int, NoInterlace> * aField_conv = FieldConvert(*aField); + } +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FieldConvert() fails if _componentsUnits is not set, because it calls FIELD_::operator="); +#endif +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Field_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Field_fault.cxx new file mode 100644 index 000000000..59efcfc8d --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Field_fault.cxx @@ -0,0 +1,1543 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_FieldConvert.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_Support.hxx" +#include <MEDMEM_VtkMeshDriver.hxx> +#include <MEDMEM_MedMeshDriver22.hxx> + + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #14,15: MEDMEMTest_Field.cxx +// Check methods from MEDMEM_Field.hxx, MEDMEM_FieldConvert.hxx + +/*! + * Check methods (48), defined in MEDMEM_Field.hxx: + * class FIELD_ { + * (+) FIELD_(); + * (+) FIELD_(const SUPPORT * Support, const int NumberOfComponents); + * (+) FIELD_(const FIELD_ &m); + * (+) virtual ~FIELD_(); + * (+) FIELD_& operator=(const FIELD_ &m); + * + * (-) virtual void rmDriver(int index=0); + * (-) virtual int addDriver(driverTypes driverType, + * const string & fileName="Default File Name.med", + * const string & driverFieldName="Default Field Nam", + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (-) virtual int addDriver(GENDRIVER & driver); + * + * (-) virtual void read (const GENDRIVER &); + * (-) virtual void read(int index=0); + * (-) virtual void openAppend(void); + * (-) virtual void write(const GENDRIVER &); + * (-) virtual void write(int index=0, const string & driverName=""); + * (-) virtual void writeAppend(const GENDRIVER &); + * (-) virtual void writeAppend(int index=0, const string & driverName=""); + * + * (+) inline void setName(const string Name); + * (+) inline string getName() const; + * (+) inline void setDescription(const string Description); + * (+) inline string getDescription() const; + * (+) inline const SUPPORT * getSupport() const; + * (+) inline void setSupport(const SUPPORT * support); + * (+) inline void setNumberOfComponents(const int NumberOfComponents); + * (+) inline int getNumberOfComponents() const; + * (+) inline void setNumberOfValues(const int NumberOfValues); + * (+) inline int getNumberOfValues() const; + * (+) inline void setComponentsNames(const string * ComponentsNames); + * (+) inline void setComponentName(int i, const string ComponentName); + * (+) inline const string * getComponentsNames() const; + * (+) inline string getComponentName(int i) const; + * (+) inline void setComponentsDescriptions(const string * ComponentsDescriptions); + * (+) inline void setComponentDescription(int i, const string ComponentDescription); + * (+) inline const string * getComponentsDescriptions() const; + * (+) inline string getComponentDescription(int i) const; + * (+) inline void setComponentsUnits(const UNIT * ComponentsUnits); + * (+) inline const UNIT * getComponentsUnits() const; + * (+) inline const UNIT * getComponentUnit(int i) const; + * (+) inline void setMEDComponentsUnits(const string * MEDComponentsUnits); + * (+) inline void setMEDComponentUnit(int i, const string MEDComponentUnit); + * (+) inline const string * getMEDComponentsUnits() const; + * (+) inline string getMEDComponentUnit(int i) const; + * + * (+) inline void setIterationNumber(int IterationNumber); + * (+) inline int getIterationNumber() const; + * (+) inline void setTime(double Time); + * (+) inline double getTime() const; + * (+) inline void setOrderNumber(int OrderNumber); + * (+) inline int getOrderNumber() const; + * + * (+) inline MED_EN::med_type_champ getValueType () const; + * (+) inline MED_EN::medModeSwitch getInterlacingType() const; + * (-) virtual inline bool getGaussPresence() const throw (MEDEXCEPTION); + * } + * + * template <class T, class INTERLACING_TAG> class FIELD : public FIELD_ { + * (+) FIELD(); + * (+) FIELD(const FIELD &m); + * (+) FIELD(const SUPPORT * Support, const int NumberOfComponents) throw (MEDEXCEPTION); + * (+) FIELD(driverTypes driverType, + * const string & fileName, const string & fieldDriverName, + * const int iterationNumber=-1, const int orderNumber=-1) throw (MEDEXCEPTION); + * (+) FIELD(const SUPPORT * Support, driverTypes driverType, + * const string & fileName="", const string & fieldName="", + * const int iterationNumber = -1, const int orderNumber = -1) throw (MEDEXCEPTION); + * (+) ~FIELD(); + * (+) FIELD & operator=(const FIELD &m); + * + * (+) const FIELD operator+(const FIELD& m) const; + * (+) const FIELD operator-(const FIELD& m) const; + * (+) const FIELD operator*(const FIELD& m) const; + * (+) const FIELD operator/(const FIELD& m) const; + * (+) const FIELD operator-() const; + * (+) FIELD& operator+=(const FIELD& m); + * (+) FIELD& operator-=(const FIELD& m); + * (+) FIELD& operator*=(const FIELD& m); + * (+) FIELD& operator/=(const FIELD& m); + * + * (+) static FIELD* add(const FIELD& m, const FIELD& n); + * (+) static FIELD* addDeep(const FIELD& m, const FIELD& n); + * (+) static FIELD* sub(const FIELD& m, const FIELD& n); + * (+) static FIELD* subDeep(const FIELD& m, const FIELD& n); + * (+) static FIELD* mul(const FIELD& m, const FIELD& n); + * (+) static FIELD* mulDeep(const FIELD& m, const FIELD& n); + * (+) static FIELD* div(const FIELD& m, const FIELD& n); + * (+) static FIELD* divDeep(const FIELD& m, const FIELD& n); + * + * (+) double normMax() const throw (MEDEXCEPTION); + * (+) double norm2() const throw (MEDEXCEPTION); + * + * (+) void applyLin(T a, T b); + * (+) template <T T_function(T)> void applyFunc(); + * (+) void applyPow(T scalar); + * + * (+) static FIELD* scalarProduct(const FIELD& m, const FIELD& n, bool deepCheck=false); + * + * (+) double normL2(int component, const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * (+) double normL2(const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * (+) double normL1(int component, const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * (+) double normL1(const FIELD<double,FullInterlace> * p_field_volume=NULL) const; + * + * (+) FIELD* extract(const SUPPORT *subSupport) const throw (MEDEXCEPTION); + * + * (EMPTY COMMENT, EMPTY IMPLEMENTATION!!!) void init (); + * + * (+) void rmDriver(int index=0); + * (+) int addDriver(driverTypes driverType, + * const string & fileName="Default File Name.med", + * const string & driverFieldName="Default Field Name", + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (+) int addDriver(GENDRIVER & driver); + * + * (+) void allocValue(const int NumberOfComponents); + * (+) void allocValue(const int NumberOfComponents, const int LengthValue); + * (+) void deallocValue(); + * + * (+) inline void read(int index=0); + * (+) inline void read(const GENDRIVER & genDriver); + * (+) inline void write(int index=0, const string & driverName = ""); + * (+) inline void write(const GENDRIVER &); + * (+) inline void writeAppend(int index=0, const string & driverName = ""); + * (+) inline void writeAppend(const GENDRIVER &); + * + * (+) inline MEDMEM_Array_ * getArray() const throw (MEDEXCEPTION); + * (+) inline ArrayGauss * getArrayGauss() const throw (MEDEXCEPTION); + * (+) inline ArrayNoGauss * getArrayNoGauss() const throw (MEDEXCEPTION); + * (+) inline bool getGaussPresence() const throw (MEDEXCEPTION); + * + * (+) inline int getValueLength() const throw (MEDEXCEPTION); + * (+) inline const T* getValue() const throw (MEDEXCEPTION); + * (+) inline const T* getRow(int i) const throw (MEDEXCEPTION); + * (+) inline const T* getColumn(int j) const throw (MEDEXCEPTION); + * (+) inline T getValueIJ(int i,int j) const throw (MEDEXCEPTION); + * (+) inline T getValueIJK(int i,int j,int k) const throw (MEDEXCEPTION); + * (+) bool getValueOnElement(int eltIdInSup,T* retValues) const throw (MEDEXCEPTION); + * + * (+) const int getNumberOfGeometricTypes() const throw (MEDEXCEPTION); + * + * (+) const GAUSS_LOCALIZATION<INTERLACING_TAG> & getGaussLocalization + * (MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + * (+) const GAUSS_LOCALIZATION<INTERLACING_TAG> * getGaussLocalizationPtr + * (MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + * (+) void setGaussLocalization(MED_EN::medGeometryElement geomElement, + * const GAUSS_LOCALIZATION<INTERLACING_TAG> & gaussloc); + * (+) const int * getNumberOfGaussPoints() const throw (MEDEXCEPTION); + * (+) const int getNumberOfGaussPoints + * (MED_EN::medGeometryElement geomElement) const throw (MEDEXCEPTION); + * (+) const int getNbGaussI(int i) const throw (MEDEXCEPTION); + * + * (+) const int * getNumberOfElements() const throw (MEDEXCEPTION); + * (+) const MED_EN::medGeometryElement * getGeometricTypes() const throw (MEDEXCEPTION); + * (+) bool isOnAllElements() const throw (MEDEXCEPTION); + * + * (+) inline void setArray(MEDMEM_Array_ *value) throw (MEDEXCEPTION); + * (+) inline void setValue(T* value) throw (MEDEXCEPTION); + * (+) inline void setRow(int i, T* value) throw (MEDEXCEPTION); + * (+) inline void setColumn(int i, T* value) throw (MEDEXCEPTION); + * (+) inline void setValueIJ(int i, int j, T value) throw (MEDEXCEPTION); + * + * (NOT IMPLEMENTED!!!) void getVolume() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getArea() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getLength() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getNormal() const throw (MEDEXCEPTION); + * (NOT IMPLEMENTED!!!) void getBarycenter() const throw (MEDEXCEPTION); + * + * (+) void fillFromAnalytic(myFuncType f) throw (MEDEXCEPTION); + * } + * + * Use code of test_operation_fieldint.cxx + * test_operation_fielddouble.cxx + * test_copie_field_.cxx + * test_copie_fieldT.cxx + */ +void compareField_(const FIELD_ * theField_1, const FIELD_ * theField_2, bool isFIELD, bool isValue) +{ + // name, description, support + CPPUNIT_ASSERT_EQUAL(theField_1->getName(), theField_2->getName()); + CPPUNIT_ASSERT_EQUAL(theField_1->getDescription(), theField_2->getDescription()); + CPPUNIT_ASSERT_EQUAL(theField_1->getSupport(), theField_2->getSupport()); + + // components information + int aNbComps = theField_1->getNumberOfComponents(); + CPPUNIT_ASSERT_EQUAL(aNbComps, theField_2->getNumberOfComponents()); + + for (int i = 1; i <= aNbComps; i++) { + CPPUNIT_ASSERT_EQUAL(theField_1->getComponentName(i), theField_2->getComponentName(i)); + CPPUNIT_ASSERT_EQUAL(theField_1->getComponentDescription(i), theField_2->getComponentDescription(i)); + CPPUNIT_ASSERT_EQUAL(theField_1->getMEDComponentUnit(i), theField_2->getMEDComponentUnit(i)); + } + + // iteration information + CPPUNIT_ASSERT_EQUAL(theField_1->getIterationNumber(), theField_2->getIterationNumber()); + CPPUNIT_ASSERT_EQUAL(theField_1->getOrderNumber(), theField_2->getOrderNumber()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(theField_1->getTime(), theField_2->getTime(), 0.0000001); + + // Value + int nbOfValues = theField_1->getNumberOfValues(); + CPPUNIT_ASSERT_EQUAL(nbOfValues, theField_2->getNumberOfValues()); + + if (isFIELD) { + // Value type and Interlacing type + CPPUNIT_ASSERT_EQUAL(theField_1->getValueType(), theField_2->getValueType()); + CPPUNIT_ASSERT_EQUAL(theField_1->getInterlacingType(), theField_2->getInterlacingType()); + + // Gauss Presence + if (isValue) { + CPPUNIT_ASSERT_EQUAL(theField_1->getGaussPresence(), theField_2->getGaussPresence()); + } + else { + CPPUNIT_ASSERT_THROW(theField_1->getGaussPresence(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_2->getGaussPresence(), MEDEXCEPTION); + } + } + else { + CPPUNIT_ASSERT_THROW(theField_1->getGaussPresence(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_2->getGaussPresence(), MEDEXCEPTION); + } +} + +void checkField_(FIELD_ * theField_, const SUPPORT * theSupport, + MED_EN::med_type_champ theValueType, + MED_EN::medModeSwitch theInterlace) +{ + // name + const string aFieldName = "a_name_of_a_field"; + theField_->setName(aFieldName); + CPPUNIT_ASSERT_EQUAL(aFieldName, theField_->getName()); + + // description + const string aFieldDescr = "a_description_of_a_field"; + theField_->setDescription(aFieldDescr); + CPPUNIT_ASSERT_EQUAL(aFieldDescr, theField_->getDescription()); + + // support + theField_->setSupport(theSupport); + CPPUNIT_ASSERT(theField_->getSupport() == theSupport); + + // components information + int aNbComps = 3; + + string aCompsNames[3] = {"Vx", "Vy", "Vz"}; + string aCompsDescs[3] = {"vitesse selon x", "vitesse selon y", "vitesse selon z"}; + string aCompsUnits[3] = {"m.s-1", "m.s-1", "m.s-1"}; + + theField_->setNumberOfComponents(aNbComps); + CPPUNIT_ASSERT_EQUAL(aNbComps, theField_->getNumberOfComponents()); + + theField_->setComponentsNames(aCompsNames); + +#ifdef ENABLE_FAULTS + try { + theField_->setNumberOfComponents(7); + // Segmentation fault here because array of components names is not resized + for (int i = 1; i <= 7; i++) { + theField_->setComponentName(i, "AnyComponent"); + } + } + catch (MEDEXCEPTION& ex) { + // Ok, it is good to have MEDEXCEPTION here + } + catch (...) { + CPPUNIT_FAIL("Unknown exception cought"); + } + // restore components names + theField_->setNumberOfComponents(aNbComps); + theField_->setComponentsNames(aCompsNames); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD_::_componentsNames bad management"); +#endif + + theField_->setComponentsDescriptions(aCompsDescs); + theField_->setMEDComponentsUnits(aCompsUnits); + + const string * aCompsNamesBack = theField_->getComponentsNames(); + const string * aCompsDescsBack = theField_->getComponentsDescriptions(); + const string * aCompsUnitsBack = theField_->getMEDComponentsUnits(); + for (int i = 1; i <= aNbComps; i++) { + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack[i-1], theField_->getComponentName(i)); + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack[i-1], aCompsNames[i-1]); + + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack[i-1], theField_->getComponentDescription(i)); + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack[i-1], aCompsDescs[i-1]); + + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack[i-1], theField_->getMEDComponentUnit(i)); + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack[i-1], aCompsUnits[i-1]); + } + + const string aCompName2 ("Name of second component"); + const string aCompDesc2 ("Description of second component"); + const string aCompUnit2 ("Unit of second MED component"); + + theField_->setComponentName(2, aCompName2); + theField_->setComponentDescription(2, aCompDesc2); + theField_->setMEDComponentUnit(2, aCompUnit2); + + const string * aCompsNamesBack2 = theField_->getComponentsNames(); + const string * aCompsDescsBack2 = theField_->getComponentsDescriptions(); + const string * aCompsUnitsBack2 = theField_->getMEDComponentsUnits(); + + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack2[1], theField_->getComponentName(2)); + CPPUNIT_ASSERT_EQUAL(aCompsNamesBack2[1], aCompName2); + + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack2[1], theField_->getComponentDescription(2)); + CPPUNIT_ASSERT_EQUAL(aCompsDescsBack2[1], aCompDesc2); + + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack2[1], theField_->getMEDComponentUnit(2)); + CPPUNIT_ASSERT_EQUAL(aCompsUnitsBack2[1], aCompUnit2); + +#ifdef ENABLE_FAULTS + // (BUG) No index checking + CPPUNIT_ASSERT_THROW(theField_->setComponentName(0, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setComponentName(aNbComps + 1, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setComponentDescription(0, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setComponentDescription(aNbComps + 1, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setMEDComponentUnit(0, "str"), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField_->setMEDComponentUnit(aNbComps + 1, "str"), MEDEXCEPTION); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD::setComponentXXX() does not check component index"); +#endif + + // iteration information + int anIterNumber = 10; // set value to MED_NOPDT if undefined (default) + theField_->setIterationNumber(anIterNumber); + CPPUNIT_ASSERT_EQUAL(anIterNumber, theField_->getIterationNumber()); + + int anOrderNumber = 1; // set value to MED_NONOR if undefined (default) + theField_->setOrderNumber(anOrderNumber); + CPPUNIT_ASSERT_EQUAL(anOrderNumber, theField_->getOrderNumber()); + + double aTime = 3.435678; // in second + theField_->setTime(aTime); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aTime, theField_->getTime(), 0.0000001); + + // Value + int nbOfValues = 10; + // dangerous method, because it does not reallocate values array + theField_->setNumberOfValues(nbOfValues); + CPPUNIT_ASSERT_EQUAL(nbOfValues, theField_->getNumberOfValues()); + + // Value type and Interlacing type + CPPUNIT_ASSERT_EQUAL(theValueType, theField_->getValueType()); + CPPUNIT_ASSERT_EQUAL(theInterlace, theField_->getInterlacingType()); +} + +template<class T, class INTERLACING_TAG> +void compareField(const FIELD<T, INTERLACING_TAG> * theField_1, + const FIELD<T, INTERLACING_TAG> * theField_2, bool isValue) +{ + // compare FIELD_ part + compareField_(theField_1, theField_2, /*isFIELD = */true, isValue); + + // compare FIELD part + // TO DO +} + +template<class T, class INTERLACING_TAG> +void checkField (FIELD<T, INTERLACING_TAG> * theField, const SUPPORT * theSupport) +{ + // check FIELD_ part + MED_EN::med_type_champ aValueType = SET_VALUE_TYPE<T>::_valueType; + MED_EN::medModeSwitch anInterlace = SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType; + checkField_(theField, theSupport, aValueType, anInterlace); + + // check FIELD part + + // filling by support charackteristics (NOT IMPLEMENTED METHODS!!!): + // value type must be MED_REEL64 (i.e. a FIELD<double>) for these methods, + // nb. of components must be equal 1 (for Volume, Area, Length) or + // space dimension (for Normal, Barycenter, ) + { + MESH* aMesh = theSupport->getMesh(); + int spaceDim = 3; + if (aMesh) spaceDim = aMesh->getSpaceDimension(); + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */spaceDim + 1); + + CPPUNIT_ASSERT_THROW(theField->getVolume(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getArea(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getLength(), MEDEXCEPTION); + if (aMesh) { + CPPUNIT_ASSERT_THROW(theField->getNormal(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getBarycenter(), MEDEXCEPTION); + } + + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */1); + if (aValueType == MED_EN::MED_REEL64) { + CPPUNIT_ASSERT_NO_THROW(theField->getVolume()); + CPPUNIT_ASSERT_NO_THROW(theField->getArea()); + CPPUNIT_ASSERT_NO_THROW(theField->getLength()); + } + else { + CPPUNIT_ASSERT_THROW(theField->getVolume(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getArea(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getLength(), MEDEXCEPTION); + } + + if (aMesh) { + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */spaceDim); + if (aValueType == MED_EN::MED_REEL64) { + CPPUNIT_ASSERT_NO_THROW(theField->getNormal()); + CPPUNIT_ASSERT_NO_THROW(theField->getBarycenter()); + } + else { + CPPUNIT_ASSERT_THROW(theField->getNormal(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(theField->getBarycenter(), MEDEXCEPTION); + } + } + } + + // values + theField->deallocValue(); + theField->allocValue(/*NumberOfComponents = */2); + int nbElemSupport = theSupport->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); + CPPUNIT_ASSERT_EQUAL(nbElemSupport, theField->getNumberOfValues()); + +#ifdef ENABLE_FAULTS + // (BUG) FIELD::deallocValue() does not nullify _value pointer, + // that is why there can be failures in other methods + // (even if simply call deallocValue() two times) + theField->deallocValue(); + theField->getGaussPresence(); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD::deallocValue() does not nullify _value pointer"); +#endif + + // copy constructor + FIELD<T, INTERLACING_TAG> aField_copy1 (*theField); + //compareField(theField, &aField_copy1, /*isValue = */false); + compareField(theField, &aField_copy1, /*isValue = */true); + + // operator= +#ifdef ENABLE_FAULTS + // (BUG) This fails (Segmentation fault) if not set: + // _componentsNames or _componentsDescriptions, or _componentsUnits, or _MEDComponentsUnits + FIELD<T, INTERLACING_TAG> aField_copy2; + aField_copy2 = *theField; + //compareField(theField, &aField_copy2, /*isValue = */false); + compareField(theField, &aField_copy2, /*isValue = */true); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD_::operator=() fails if _componentsUnits is not set"); +#endif +} + +template<class T> +FIELD<T> * createFieldOnGroup(MESH* theMesh, const GROUP* theGroup, + const string theName, const string theDescr) +{ + FIELD<T> * aFieldOnGroup = new FIELD<T> (theGroup, /*NumberOfComponents = */2); + + aFieldOnGroup->setName(theName); + aFieldOnGroup->setDescription(theDescr); + + string aCompsNames[2] = {"Pos", "Neg"}; + string aCompsDescs[2] = {"+", "-"}; + string aCompsUnits[2] = {"unit1", "unit2"}; + + aFieldOnGroup->setComponentsNames(aCompsNames); + aFieldOnGroup->setComponentsDescriptions(aCompsDescs); + aFieldOnGroup->setMEDComponentsUnits(aCompsUnits); + + return aFieldOnGroup; +} + +double plus13 (double val) +{ + return val + 13; +} + +// function to calculate field values from coordinates of an element +// typedef void (*myFuncType)(const double * temp, T* output); +// size of temp array = space dim = 3 +// size of output array = nb. comps = 2 +void proj2d (const double * temp, double* output) +{ + // dimetric projection with coefficients: + // 1.0 along Oy and Oz, 0.5 along Ox + // + // ^ z (y_) + // | + // | + // .----> y (x_) + // / + // L x + // + // x_ = y - x * sqrt(2.) / 4. + // y_ = z - x * sqrt(2.) / 4. + + double dx = temp[0] * std::sqrt(2.) / 4.; + output[0] = temp[1] - dx; + output[1] = temp[2] - dx; +} + +void testDrivers() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string filename_wr = tmp_dir + "/myMedFieldfile.med"; + string filename_support_wr = tmp_dir + "/myMedSupportFiledfile.med"; + string filename22_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filenamevtk_wr = tmp_dir + "/myMedFieldfile22.vtk"; + string cp_file = "cp " + filename_rd + " " + filename_wr; + + string fieldname_celldouble_rd = "fieldcelldouble"; + string fieldname_celldouble_wr = fieldname_celldouble_rd + "_cpy"; + string fieldname_nodeint_rd = "fieldnodeint"; + string fieldname_nodeint_wr = fieldname_nodeint_rd + "_cpy"; + string fieldname_nodeint_wr1 = fieldname_nodeint_rd + "_cpy1"; + string meshname = "maa1"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filenamevtk_wr); + aRemover.Register(filename_support_wr); + + //Copy file + system(cp_file.c_str()); + + FIELD<int> aInvalidField; + //must throw becase only VTK_DRIVER or MED_DRIVER may be specified as driverType for FIELD + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(NO_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(GIBI_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(PORFLOW_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidField = FIELD<int>(ASCII_DRIVER, filename_rd, fieldname_nodeint_rd), + MEDEXCEPTION); + + ////////////////// + //TestRead Part// + ////////////////// + FIELD<double> *aField_1 = NULL; + CPPUNIT_ASSERT_NO_THROW(aField_1 = new FIELD<double>(MED_DRIVER, filename_rd, fieldname_celldouble_rd)); + + //Test read(int index) method + int IdDriver_rd = aField_1->addDriver(MED_DRIVER,filename_rd,fieldname_celldouble_rd); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Cannot open file, but file exist + CPPUNIT_ASSERT_NO_THROW(aField_1->read(IdDriver_rd)); +#endif + + //Test read(GENDRIVER & genDriver) method + //Creation a Driver + MED_FIELD_RDONLY_DRIVER21<int> *aMedRdFieldDriver21_1 = + new MED_FIELD_RDONLY_DRIVER21<int>(); + //Creation a Field + FIELD<int> *aField_2 = new FIELD<int>(); + aField_2->setName(fieldname_nodeint_rd); + aField_2->addDriver(*aMedRdFieldDriver21_1); + aField_2->read(*aMedRdFieldDriver21_1); + + /////////////////// + //Test Write Part// + /////////////////// + int IdDriver; + MESH *aMesh = new MESH(MED_DRIVER,filename_rd,meshname); + SUPPORT *aSupport = new SUPPORT(aMesh, "aSupport",MED_CELL); + FIELD<int> *aFieldSupport; +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_NO_THROW(aFieldSupport = + new FIELD<int>(aSupport, MED_DRIVER,filename_support_wr,fieldname_nodeint_rd)); + //(BUG) Can not open file + MED_FIELD_WRONLY_DRIVER21<int> * aFieldWrDriver21 = + new MED_FIELD_WRONLY_DRIVER21<int>(filename_support_wr,aFieldSupport); + aFieldWrDriver21->setFieldName(aFieldSupport->getName() + "_copy"); + CPPUNIT_ASSERT_NO_THROW(IdDriver= aFieldSupport->addDriver(*aFieldWrDriver21)); + CPPUNIT_ASSERT_NO_THROW(aFieldSupport->write(IdDriver)); + delete aFieldSupport; + delete aFieldWrDriver21; +#endif + + //Create fileds + FIELD<double> * aField_3 = new FIELD<double>(); + MED_FIELD_RDONLY_DRIVER21<double> *aMedRdFieldDriver21_2 = + new MED_FIELD_RDONLY_DRIVER21<double>(filename_rd, aField_3); + aMedRdFieldDriver21_2->open(); + aMedRdFieldDriver21_2->setFieldName(fieldname_celldouble_rd); + aMedRdFieldDriver21_2->read(); + aMedRdFieldDriver21_2->close(); + + //Test write(int index) method + //Add drivers to FIELDs + int IdDriver1 = -1; + try + { + IdDriver1 = aField_3->addDriver(MED_DRIVER,filename_wr,fieldname_celldouble_wr); + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + //Trying call write(int index) method with incorrect index +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aField_3->write(IdDriver1+1, fieldname_celldouble_wr),MEDEXCEPTION); + // => Segmentation fault +#endif + + //Write field to file +#ifdef ENABLE_FAULTS + try + { + aField_3->write(IdDriver1, fieldname_celldouble_wr); + // => Segmentation fault + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#endif + + CPPUNIT_ASSERT_NO_THROW(aField_3->rmDriver(IdDriver1)); + + //Test write(const GENDRIVER &); + //Create a driver + MED_FIELD_WRONLY_DRIVER21<int> *aMedWrFieldDriver21 = + new MED_FIELD_WRONLY_DRIVER21<int>(); + aMedWrFieldDriver21->setFileName(filename_wr); + aField_2->setName(fieldname_nodeint_wr1); + //Add driver to a field + aField_2->addDriver(*aMedWrFieldDriver21); + + try + { + aField_2->write(*aMedWrFieldDriver21); + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test writeAppend(int index) method + //Create a vtk file + MESH * aMesh_1 = new MESH(); + MED_MESH_RDONLY_DRIVER22 *aMedMeshRdDriver22 = new MED_MESH_RDONLY_DRIVER22(filename22_rd, aMesh_1); + aMedMeshRdDriver22->open(); + aMedMeshRdDriver22->setMeshName(meshname); + aMedMeshRdDriver22->read(); + aMedMeshRdDriver22->close(); + VTK_MESH_DRIVER *aVtkDriver = new VTK_MESH_DRIVER(filenamevtk_wr, aMesh_1); + aVtkDriver->open(); + aVtkDriver->write(); + aVtkDriver->close(); + + //Create a field + FIELD<int> * aField_4 = new FIELD<int>(); + MED_FIELD_RDONLY_DRIVER22<int> *aMedRdFieldDriver22 = + new MED_FIELD_RDONLY_DRIVER22<int>(filename22_rd, aField_2); + aMedRdFieldDriver22->open(); + aMedRdFieldDriver22->setFieldName(fieldname_nodeint_rd); + aMedRdFieldDriver22->read(); + aMedRdFieldDriver22->close(); + + //Add Driver to a field + int IdDriver2; + try + { + IdDriver2 = aField_4->addDriver(VTK_DRIVER, filenamevtk_wr ,fieldname_nodeint_wr); + } + catch(MEDEXCEPTION &e) + { + e.what(); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#ifdef ENABLE_FAULTS + //Trying call writeAppend() method with incorrect index + CPPUNIT_ASSERT_THROW(aField_4->writeAppend(IdDriver2+1,fieldname_nodeint_wr),MEDEXCEPTION); + // => Segmentation fault +#endif + +#ifdef ENABLE_FAULTS + // (BUG) => Segmentation fault + CPPUNIT_ASSERT_NO_THROW(aField_4->writeAppend(IdDriver2, fieldname_nodeint_wr)); +#endif + + //Test writeAppend(const GENDRIVER &) method + aField_4->setName(fieldname_nodeint_wr1); + + //Add driver to a field +#ifdef ENABLE_FAULTS + //Create a driver + VTK_FIELD_DRIVER<int> *aVtkFieldDriver = new VTK_FIELD_DRIVER<int>(filenamevtk_wr, aField_4); + CPPUNIT_ASSERT_NO_THROW(aField_4->addDriver(*aVtkFieldDriver)); + //(BUG) => Segmentation fault after addDriver(const GENDRIVER &) + CPPUNIT_ASSERT_NO_THROW(aField_4->writeAppend(*aVtkFieldDriver)); +#endif + + + //Delete objects + delete aField_1; + delete aMedRdFieldDriver21_1; + delete aField_2; + delete aField_3; + delete aMedRdFieldDriver21_2; + delete aField_4; + delete aMedMeshRdDriver22; + delete aMedWrFieldDriver21; + delete aVtkDriver; + delete aMesh; + delete aMesh_1; + delete aMedRdFieldDriver22; + delete aSupport; +} + +void MEDMEMTest_testField() +{ + SUPPORT anEmptySupport; + //////////////////// + // TEST 1: FIELD_ // + //////////////////// + FIELD_ aField_; + + // check set/get methods + MED_EN::med_type_champ aValueType = MED_EN::MED_UNDEFINED_TYPE; + MED_EN::medModeSwitch anInterlace = MED_EN::MED_UNDEFINED_INTERLACE; + checkField_(&aField_, &anEmptySupport, aValueType, anInterlace); + + // copy constructor + // This fails (Segmentation fault) if not set: + // _componentsNames or _componentsDescriptions, or _MEDComponentsUnits + FIELD_ aField_copy1 (aField_); + compareField_(&aField_, &aField_copy1, /*isFIELD = */false, /*isValue = */false); + + // operator= +#ifdef ENABLE_FAULTS + // (BUG) This fails (Segmentation fault) if not set: + // _componentsNames or _componentsDescriptions, or _componentsUnits, or _MEDComponentsUnits + // (BUG) Code duplication with copyGlobalInfo(), called from copy constructor + FIELD_ aField_copy2; + aField_copy2 = aField_; + compareField_(&aField_, &aField_copy2, /*isFIELD = */false, /*isValue = */false); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("FIELD_::operator=() fails if _componentsUnits is not set"); +#endif + + // construction on a given support + { + anEmptySupport.setTotalNumberOfElements(11); + // CASE1: + FIELD_ aField_case1 (&anEmptySupport, 10); + // CASE2: + FIELD_ aField_case2; + aField_case2.setSupport(&anEmptySupport); + aField_case2.setNumberOfComponents(10); + +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_EQUAL_MESSAGE("No correspondance between CASE1 and CASE2", + aField_case1.getNumberOfValues(), + aField_case2.getNumberOfValues()); +#endif + } + + //////////////////////// + // TEST 2: FIELD<int> // + //////////////////////// + FIELD<int> aFieldInt; + checkField(&aFieldInt, &anEmptySupport); + + //////////////////////////////////////// + // TEST 3: FIELD<double, NoInterlace> // + //////////////////////////////////////// + MESH * aMesh = MEDMEMTest_createTestMesh(); + const GROUP* aGroup = aMesh->getGroup(MED_EN::MED_FACE, 1); + + FIELD<double, NoInterlace> aFieldDouble; + checkField(&aFieldDouble, aGroup); + + ////////////////////////////////////////// + // TEST 4: FIELD<double, FullInterlace> // + ////////////////////////////////////////// + FIELD<double> * aFieldOnGroup1 = createFieldOnGroup<double>(aMesh, aGroup, "Linear", "N"); + FIELD<double> * aFieldOnGroup2 = createFieldOnGroup<double>(aMesh, aGroup, "Quadratic", "N**2"); + + int nbVals = aFieldOnGroup1->getNumberOfValues(); + CPPUNIT_ASSERT(nbVals); + + // numbers of elements in group, + // they are needed in method FIELD::setValueIJ() + const int *anElems = aGroup->getnumber()->getValue(); + double eucl1 = 0., eucl2 = 0.; + + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup1->setValueIJ(anElems[i-1], 1, (double)i); + aFieldOnGroup1->setValueIJ(anElems[i-1], 2, (double)(-i)); + + aFieldOnGroup2->setValueIJ(anElems[i-1], 1, (double)i*i); + aFieldOnGroup2->setValueIJ(anElems[i-1], 2, (double)(-i*i)); + + eucl1 += 2. * i * i; + eucl2 += 2. * i * i * i * i; + } + + // out of bound (inexisting 33-th component of last element) + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->setValueIJ(anElems[nbVals-1], 33, 10.), MEDEXCEPTION); + + // normMax + CPPUNIT_ASSERT_DOUBLES_EQUAL(nbVals, aFieldOnGroup1->normMax(), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(nbVals*nbVals, aFieldOnGroup2->normMax(), 0.000001); + + // norm2 + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(eucl1), aFieldOnGroup1->norm2(), 0.000001); // 10.4881 + CPPUNIT_ASSERT_DOUBLES_EQUAL(std::sqrt(eucl2), aFieldOnGroup2->norm2(), 0.000001); // 44.2493 + + // check getXXX methods + CPPUNIT_ASSERT(!aFieldOnGroup1->getGaussPresence()); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getArrayGauss(), MEDEXCEPTION); + MEDMEM_ArrayInterface<double, FullInterlace,NoGauss>::Array * anArrayNoGauss = + aFieldOnGroup1->getArrayNoGauss(); + + MEDMEM_Array_ * aMEDMEM_Array_ = aFieldOnGroup1->getArray(); + MEDMEM_ArrayInterface<double, FullInterlace,NoGauss>::Array * aMEDMEM_Array_conv = + static_cast<MEDMEM_ArrayInterface<double, FullInterlace,NoGauss>::Array *>(aMEDMEM_Array_); + + const double * aValues = aFieldOnGroup1->getValue(); + + // out of range + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getColumn(3), MEDEXCEPTION); + // cannot get column in FullInterlace + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getColumn(1), MEDEXCEPTION); + + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , aFieldOnGroup1->getValueIJK(anElems[i-1], 1, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), aFieldOnGroup1->getValueIJK(anElems[i-1], 2, 1), 0.000001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , aValues[(i-1)*2 + 0], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), aValues[(i-1)*2 + 1], 0.000001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , anArrayNoGauss->getIJ(i, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), anArrayNoGauss->getIJ(i, 2), 0.000001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , aMEDMEM_Array_conv->getIJ(i, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), aMEDMEM_Array_conv->getIJ(i, 2), 0.000001); + + const double* row_i = aFieldOnGroup1->getRow(anElems[i-1]); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , row_i[0], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), row_i[1], 0.000001); + + double vals_i [2]; + aFieldOnGroup1->getValueOnElement(anElems[i-1], vals_i); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)i , vals_i[0], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL((double)(-i), vals_i[1], 0.000001); + } + + // modify all values of aFieldOnGroup2 by formula a*x + b (a = 2, b = 3) + aFieldOnGroup2->applyLin(2., 3.); + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(3. + 2.*i*i, aFieldOnGroup2->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3. - 2.*i*i, aFieldOnGroup2->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // apply function plus13() to aFieldOnGroup1 + aFieldOnGroup1->applyFunc<plus13>(); + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // scalarProduct + FIELD<double, FullInterlace> * aScalarProduct = + FIELD<double, FullInterlace>::scalarProduct(*aFieldOnGroup1, *aFieldOnGroup2, /*deepCheck = */true); + CPPUNIT_ASSERT_EQUAL(nbVals, aScalarProduct->getNumberOfValues()); + CPPUNIT_ASSERT_EQUAL(1, aScalarProduct->getNumberOfComponents()); + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(78. + 4.*i*i*i, //(3. + 2.*i*i)*(13 + i) + (3. - 2.*i*i)*(13 - i) + aScalarProduct->getValueIJ(anElems[i-1], 1), 0.000001); + } + + // fillFromAnalytic + aFieldOnGroup2->fillFromAnalytic(proj2d); + + double bary [3]; + double outp [2]; + const SUPPORT * aSupp = aFieldOnGroup2->getSupport(); + FIELD<double,FullInterlace> * barycenter = aMesh->getBarycenter(aSupp); + for (int i = 1; i <= nbVals; i++) { + bary[0] = barycenter->getValueIJ(anElems[i-1], 1); + bary[1] = barycenter->getValueIJ(anElems[i-1], 2); + bary[2] = barycenter->getValueIJ(anElems[i-1], 3); + + proj2d(bary, outp); + + //cout << "barycenter (" << bary[0] << ", " << bary[1] << ", " << bary[2] << ")" << endl; + //cout << "proj2d (" << outp[0] << ", " << outp[1] << ")" << endl; + + //bary (-0.666667, 0.666667, 0.666667) -> outp ( 0.902369, 0.902369) + //bary ( 0.666667, -0.666667, 0.666667) -> outp (-0.902369, 0.430964) + //bary ( 0. , 0. , 2. ) -> outp ( 0. , 2. ) + //bary ( 0. , 0. , 3. ) -> outp ( 0. , 3. ) + //bary (-1. , 0. , 2.5 ) -> outp ( 0.353553, 2.85355 ) + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) in FIELD::fillFromAnalytic() in case of support, different from nodes: + // barycenterField in FullInterlace, but values extracted like from NoInterlace + CPPUNIT_ASSERT_DOUBLES_EQUAL(outp[0], aFieldOnGroup2->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(outp[1], aFieldOnGroup2->getValueIJ(anElems[i-1], 2), 0.000001); +#endif + + // currently it gives values, that are wrong: + //aFieldOnGroup2 row1 ( 0.902369, 0.235702) + //aFieldOnGroup2 row2 (-0.235702, 2.7643 ) + //aFieldOnGroup2 row3 (-0.235702, -1.2357 ) + //aFieldOnGroup2 row4 ( 1.7643 , -0.235702) + //aFieldOnGroup2 row5 ( 0.235702, 2.7357 ) + } + + // info about support (Group1) + CPPUNIT_ASSERT(!aFieldOnGroup1->isOnAllElements()); // because we build Group1 so + int nbTypes = aFieldOnGroup1->getNumberOfGeometricTypes(); + //CPPUNIT_ASSERT(nbTypes); + CPPUNIT_ASSERT_EQUAL(2, nbTypes); + const int * nbElemsInEachType = aFieldOnGroup1->getNumberOfElements(); + const MED_EN::medGeometryElement * aGeomTypes = aFieldOnGroup1->getGeometricTypes(); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aGeomTypes[0]); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aGeomTypes[1]); + + // GAUSS + + // now we have no gauss localization in aFieldOnGroup1 + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA6), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalization(MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalizationPtr(MED_EN::MED_TRIA3), MEDEXCEPTION); + + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNbGaussI(anElems[0])); + + // set a gauss localization into aFieldOnGroup1 + double cooRef[6] = {1.,1., 2.,4., 3.,9.}; // xy xy xy + double cooGauss[10] = {7.,7., 6.,6., 5.,5., 4.,3., 2.,1.}; // x1,y1 x2,y2 x3,y3 x4,y4 x5,y5 + double wg[5] = {1., 2., 3., 4., 5.}; + GAUSS_LOCALIZATION<> gl1 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg); + + aFieldOnGroup1->setGaussLocalization(MED_EN::MED_TRIA3, gl1); + + // now we have a gauss localization for MED_TRIA3 type + CPPUNIT_ASSERT_EQUAL(5, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(MED_EN::MED_TRIA6), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getNumberOfGaussPoints(), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalization(MED_EN::MED_QUAD4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->getGaussLocalizationPtr(MED_EN::MED_QUAD4), MEDEXCEPTION); + + GAUSS_LOCALIZATION<> gl1Back = aFieldOnGroup1->getGaussLocalization(MED_EN::MED_TRIA3); + const GAUSS_LOCALIZATION<> * gl1BackPtr = aFieldOnGroup1->getGaussLocalizationPtr(MED_EN::MED_TRIA3); + + CPPUNIT_ASSERT(gl1 == gl1Back); + CPPUNIT_ASSERT(gl1 == *gl1BackPtr); + + CPPUNIT_ASSERT_EQUAL(1, aFieldOnGroup1->getNbGaussI(anElems[0])); + + // sub-support of Group1 on one (first) geometric type + SUPPORT * aSubSupport1 = new SUPPORT(aMesh, "Sub-Support 1 of Group1", MED_EN::MED_FACE); + aSubSupport1->setAll(false); + + int nbTypes1 = 1; + int nbElemsInEachType1[1]; + nbElemsInEachType1[0] = nbElemsInEachType[0]; + int nbElems1 = nbElemsInEachType1[0]; + MED_EN::medGeometryElement aGeomTypes1[1]; + aGeomTypes1[0] = aGeomTypes[0]; + int * anElems1 = new int[nbElems1]; + for (int i = 0; i < nbElems1; i++) { + anElems1[i] = anElems[i]; + } + + aSubSupport1->setpartial("Support for sub-field 1 on one type of elements", + nbTypes1, nbElems1, aGeomTypes1, nbElemsInEachType1, anElems1); + + //cout << "aSubSupport1:" << endl; + //cout << *aSubSupport1 << endl; + + // extract sub-field on aSubSupport1 + FIELD<double, FullInterlace> * aSubField1 = aFieldOnGroup1->extract(aSubSupport1); + CPPUNIT_ASSERT_EQUAL(nbElems1 * /*NumberOfComponents = */2, aSubField1->getValueLength()); + + // aSubField1: + // elt\comp | 1 | 2 + //-------------------- + // 1 | 14 | 12 + // 2 | 15 | 11 + + // check normL2() and normL1() + FIELD<double>* anAreaField = aMesh->getArea(aSubSupport1); + double area1 = anAreaField->getValueIJ(anElems1[0], 1); + double area2 = anAreaField->getValueIJ(anElems1[1], 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.44949, area1, 0.00001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2.44949, area2, 0.00001); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(210.5, aSubField1->normL2(1), 0.00001); // (14*14 + 15*15)/2 +#ifdef ENABLE_FORCED_FAILURES + // (BUG) FIELD::normL2(int component, const FIELD * p_field_volume): + // component is not taken into account + CPPUNIT_ASSERT_DOUBLES_EQUAL(132.5, aSubField1->normL2(2), 0.00001); // (12*12 + 11*11)/2 +#endif + CPPUNIT_ASSERT_DOUBLES_EQUAL(343.0, aSubField1->normL2() , 0.00001); // 210.5 + 132.5 + + CPPUNIT_ASSERT_DOUBLES_EQUAL(14.5, aSubField1->normL1(1), 0.00001); // (14 + 15)/2 + CPPUNIT_ASSERT_DOUBLES_EQUAL(11.5, aSubField1->normL1(2), 0.00001); // (12 + 11)/2 + CPPUNIT_ASSERT_DOUBLES_EQUAL(26.0, aSubField1->normL1() , 0.00001); // 14.5 + 11.5 + + double aNewArea [2] = {1., 0.}; // only first element will be taken into account + anAreaField->setValue(aNewArea); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(196.0, aSubField1->normL2(1, anAreaField), 0.00001); // 14*14/1 +#ifdef ENABLE_FORCED_FAILURES + // (BUG) FIELD::normL2(int component, const FIELD * p_field_volume): + // component is not taken into account + CPPUNIT_ASSERT_DOUBLES_EQUAL(144.0, aSubField1->normL2(2, anAreaField), 0.00001); // 12*12/1 +#endif + CPPUNIT_ASSERT_DOUBLES_EQUAL(340.0, aSubField1->normL2(anAreaField) , 0.00001); // 196 + 144 + + CPPUNIT_ASSERT_DOUBLES_EQUAL(14.0, aSubField1->normL1(1, anAreaField), 0.00001); // 14/1 + CPPUNIT_ASSERT_DOUBLES_EQUAL(12.0, aSubField1->normL1(2, anAreaField), 0.00001); // 12/1 + CPPUNIT_ASSERT_DOUBLES_EQUAL(26.0, aSubField1->normL1(anAreaField) , 0.00001); // 14 + 12 + + // applyPow + aSubField1->applyPow(2.); + CPPUNIT_ASSERT_DOUBLES_EQUAL(196., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); // 14*14 + CPPUNIT_ASSERT_DOUBLES_EQUAL(144., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); // 12*12 + CPPUNIT_ASSERT_DOUBLES_EQUAL(225., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); // 15*15 + CPPUNIT_ASSERT_DOUBLES_EQUAL(121., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); // 11*11 + + // setArray (NoGauss) + MEDMEM_ArrayInterface<double,FullInterlace,NoGauss>::Array * aNewArrayNoGauss = + new MEDMEM_ArrayInterface<double,FullInterlace,NoGauss>::Array(/*dim*/2, /*nbelem*/2); + aNewArrayNoGauss->setIJ(1, 1, 4.); + aNewArrayNoGauss->setIJ(1, 2, 2.); + aNewArrayNoGauss->setIJ(2, 1, 5.); + aNewArrayNoGauss->setIJ(2, 2, 1.); + aSubField1->setArray(aNewArrayNoGauss); + // no need to delete aNewArrayNoGauss, because it will be deleted + // in destructor or in deallocValue() method of aSubField1 + + CPPUNIT_ASSERT_DOUBLES_EQUAL(4., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); + + // setRow + double row[2] = {-1., -3.}; + aSubField1->setRow(anElems1[0], row); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-1., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-3., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 5., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); + // out of range + CPPUNIT_ASSERT_THROW(aSubField1->setRow(3, row), MEDEXCEPTION); + + // setColumn + double col[2] = {-7., -9.}; + aSubField1->setColumn(1, col); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-7., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-3., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) in MEDMEM_Array::setColumn() + CPPUNIT_ASSERT_DOUBLES_EQUAL(-9., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); +#endif + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); + // out of range + CPPUNIT_ASSERT_THROW(aSubField1->setColumn(3, col), MEDEXCEPTION); + + // setArray (Gauss) + { + int nbelgeoc[2] = {1, 3}; // 3 - 1 = two elements for the first (and the only) type + int nbgaussgeo[2] = {-1, 1}; // one gauss point per each element + MEDMEM_ArrayInterface<double,FullInterlace,Gauss>::Array * aNewArrayGauss = + new MEDMEM_ArrayInterface<double,FullInterlace,Gauss>::Array + (/*dim*/2, /*nbelem*/2, /*nbtypegeo*/1, /*nbelgeoc*/nbelgeoc, /*nbgaussgeo*/nbgaussgeo); + +#ifdef ENABLE_FAULTS + aNewArrayGauss->setIJ(1, 1, -4.); + aNewArrayGauss->setIJ(1, 2, -2.); + aNewArrayGauss->setIJ(2, 1, -5.); + aNewArrayGauss->setIJ(2, 2, -1.); +#endif +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) in FullInterlaceGaussPolicy::getIndex(int i,int j) + // FullInterlaceGaussPolicy::getIndex(2,2) returns 4!!! + CPPUNIT_FAIL("? Bug in FullInterlaceGaussPolicy::getIndex(int i,int j) ?"); +#endif + + aNewArrayGauss->setIJK(1, 1, 1, -4.); + aNewArrayGauss->setIJK(1, 2, 1, -2.); + aNewArrayGauss->setIJK(2, 1, 1, -5.); + aNewArrayGauss->setIJK(2, 2, 1, -1.); + + aSubField1->setArray(aNewArrayGauss); + // no need to delete aNewArrayGauss, because it will be deleted + // in destructor or in deallocValue() method of aSubField1 + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_DOUBLES_EQUAL(-4., aSubField1->getValueIJ(anElems1[0], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2., aSubField1->getValueIJ(anElems1[0], 2), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-5., aSubField1->getValueIJ(anElems1[1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-1., aSubField1->getValueIJ(anElems1[1], 2), 0.000001); +#endif +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) in FullInterlaceGaussPolicy::getIndex(int i,int j) + // Must be : return _G[i-1]-1 + (j-1); + // Instead of: return _G[i-1]-1 + (j-1)*_dim; + CPPUNIT_FAIL("? Bug in FullInterlaceGaussPolicy::getIndex(int i,int j) ?"); +#endif + + CPPUNIT_ASSERT_DOUBLES_EQUAL(-4., aSubField1->getValueIJK(anElems1[0], 1, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2., aSubField1->getValueIJK(anElems1[0], 2, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-5., aSubField1->getValueIJK(anElems1[1], 1, 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-1., aSubField1->getValueIJK(anElems1[1], 2, 1), 0.000001); + } + + // alloc/dealloc; compatibility of new size with support + try { + aSubField1->deallocValue(); + aSubField1->allocValue(/*NumberOfComponents*/2, /*LengthValue*/5); +#ifdef ENABLE_FAULTS + // (BUG) No compatibility between Support and allocated value + aSubField1->normL1(); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("Error: no compatibility between Support and allocated value"); +#endif + } + catch (MEDEXCEPTION & ex) { + // normal behaviour + } + catch (...) { + CPPUNIT_FAIL("Error: no compatibility between Support and allocated value"); + } + + // check that aFieldOnGroup1 is not changed after aSubField1 modifications + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // reset aFieldOnGroup2 values for simple control of operators results + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup2->setValueIJ(anElems[i-1], 1, i*i); + aFieldOnGroup2->setValueIJ(anElems[i-1], 2, -i*i); + } + + int len = aFieldOnGroup1->getValueLength(); + const double * val1 = aFieldOnGroup1->getValue(); + const double * val2 = aFieldOnGroup2->getValue(); + const double * val_res; + + // operators and add, sub, mul, div + + // + + FIELD<double> aSum = *aFieldOnGroup1 + *aFieldOnGroup2; + aSum.setName(aFieldOnGroup1->getName()); + aSum.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aSum, true, true); + val_res = aSum.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val2[i], val_res[i], 0.000001); + } + + // - + FIELD<double> aDifference = *aFieldOnGroup1 - *aFieldOnGroup2; + aDifference.setName(aFieldOnGroup1->getName()); + aDifference.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aDifference, true, true); + val_res = aDifference.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] - val2[i], val_res[i], 0.000001); + } + + // - (unary) + FIELD<double> aNegative = - *aFieldOnGroup1; + aNegative.setName(aFieldOnGroup1->getName()); + aNegative.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aNegative, true, true); + val_res = aNegative.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(- val1[i], val_res[i], 0.000001); + } + + // * + FIELD<double> aProduct = (*aFieldOnGroup1) * (*aFieldOnGroup2); + aProduct.setName(aFieldOnGroup1->getName()); + aProduct.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aProduct, true, true); + val_res = aProduct.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] * val2[i], val_res[i], 0.000001); + } + + // / + FIELD<double> aQuotient = *aFieldOnGroup1 / *aFieldOnGroup2; + aQuotient.setName(aFieldOnGroup1->getName()); + aQuotient.setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, &aQuotient, true, true); + val_res = aQuotient.getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] / val2[i], val_res[i], 0.000001); + } + + double val22 = aFieldOnGroup2->getValueIJ(anElems[2], 2); + aFieldOnGroup2->setValueIJ(anElems[2], 2, 0.); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 / *aFieldOnGroup2, MEDEXCEPTION); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) is it up to user to control validity of data to avoid division on zero? + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 /= *aFieldOnGroup2, MEDEXCEPTION); +#endif + CPPUNIT_ASSERT_THROW(FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + + // restore value + aFieldOnGroup2->setValueIJ(anElems[2], 2, val22); + + // restore values + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup1->setValueIJ(anElems[i-1], 1, 13 + i); + aFieldOnGroup1->setValueIJ(anElems[i-1], 2, 13 - i); + } + + // static methods + FIELD<double> * aPtr; + + // add + aPtr = FIELD<double>::add(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // sub + aPtr = FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] - val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // mul + aPtr = FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] * val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // div + aPtr = FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] / val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // addDeep + aPtr = FIELD<double>::addDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // subDeep + aPtr = FIELD<double>::subDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] - val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // mulDeep + aPtr = FIELD<double>::mulDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] * val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // divDeep + aPtr = FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup2); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] / val2[i], val_res[i], 0.000001); + } + delete aPtr; + + // += + *aFieldOnGroup1 += *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i + i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i - i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // -= + *aFieldOnGroup1 -= *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // *= + *aFieldOnGroup1 *= *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( (13 + i)*i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-(13 - i)*i*i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // /= + *aFieldOnGroup1 /= *aFieldOnGroup2; + for (int i = 1; i <= nbVals; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 + i, aFieldOnGroup1->getValueIJ(anElems[i-1], 1), 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13 - i, aFieldOnGroup1->getValueIJ(anElems[i-1], 2), 0.000001); + } + + // check case of different operands: support + MESH * aMeshOneMore = MEDMEMTest_createTestMesh(); + const GROUP* aGroupOneMore = aMeshOneMore->getGroup(MED_EN::MED_FACE, 1); + FIELD<double> * aFieldOnGroup3 = + createFieldOnGroup<double>(aMeshOneMore, aGroupOneMore, "Test_Diff_Mesh", "test"); + for (int i = 1; i <= nbVals; i++) { + aFieldOnGroup3->setValueIJ(anElems[i-1], 1, 2*i); + aFieldOnGroup3->setValueIJ(anElems[i-1], 2, 3*i); + } + const double * val3 = aFieldOnGroup3->getValue(); + + //CPPUNIT_ASSERT_NO_THROW(); + try { + aPtr = FIELD<double>::addDeep(*aFieldOnGroup1, *aFieldOnGroup3); + aPtr->setName(aFieldOnGroup1->getName()); + aPtr->setDescription(aFieldOnGroup1->getDescription()); + compareField_(aFieldOnGroup1, aPtr, true, true); + val_res = aPtr->getValue(); + for (int i = 0; i < len; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(val1[i] + val3[i], val_res[i], 0.000001); + } + delete aPtr; + + aPtr = FIELD<double>::subDeep(*aFieldOnGroup1, *aFieldOnGroup3); + delete aPtr; + aPtr = FIELD<double>::mulDeep(*aFieldOnGroup1, *aFieldOnGroup3); + delete aPtr; + aPtr = FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup3); + delete aPtr; + } + catch (MEDEXCEPTION & ex) { + CPPUNIT_FAIL(ex.what()); + } + catch (...) { + CPPUNIT_FAIL("Unknown exception in FIELD::xxxDeep()"); + } + + CPPUNIT_ASSERT_THROW(FIELD<double>::add(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup3), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 + *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 - *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 * *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 / *aFieldOnGroup3, MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 += *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 -= *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 *= *aFieldOnGroup3, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 /= *aFieldOnGroup3, MEDEXCEPTION); + + // check case of different operands: MEDComponentsUnits + aFieldOnGroup1->setMEDComponentUnit(1, "unit3"); + + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 + *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 - *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 += *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(*aFieldOnGroup1 -= *aFieldOnGroup2, MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::add(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::sub(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::addDeep(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(FIELD<double>::subDeep(*aFieldOnGroup1, *aFieldOnGroup2), MEDEXCEPTION); + + //CPPUNIT_ASSERT_NO_THROW(); + try { + aPtr = FIELD<double>::mul(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + aPtr = FIELD<double>::div(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + aPtr = FIELD<double>::mulDeep(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + aPtr = FIELD<double>::divDeep(*aFieldOnGroup1, *aFieldOnGroup2); + delete aPtr; + + *aFieldOnGroup1 *= *aFieldOnGroup2; + *aFieldOnGroup1 /= *aFieldOnGroup2; + + FIELD<double> aPr = *aFieldOnGroup1 * *aFieldOnGroup2; + FIELD<double> aQu = *aFieldOnGroup1 / *aFieldOnGroup2; + } + catch (MEDEXCEPTION & ex) { + CPPUNIT_FAIL(ex.what()); + } + catch (...) { + CPPUNIT_FAIL("Unknown exception"); + } + + // restore MED units + aFieldOnGroup1->setMEDComponentUnit(1, "unit1"); + + // check case of different operands: numberOfComponents +#ifdef ENABLE_FAULTS + // (BUG) Cannot allocate value of higher dimension because of _componentsTypes reinitialization + // Must be MEDEXCEPTION instead. And on attempt to change nb.components must be the same behaviour. + aFieldOnGroup1->deallocValue(); + CPPUNIT_ASSERT_THROW(aFieldOnGroup1->allocValue(/*dim*/5), MEDEXCEPTION); +#endif + + delete aSubSupport1; + delete [] anElems1; + + delete aScalarProduct; + delete aSubField1; + delete anAreaField; + delete barycenter; + delete aFieldOnGroup1; + delete aFieldOnGroup2; + delete aFieldOnGroup3; + + delete aMesh; + delete aMeshOneMore; + + ///////////////////// + // TEST 5: Drivers // + ///////////////////// + testDrivers(); +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testField(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Formulae.cxx b/src/MEDMEM/Test/MEDMEMTest_Formulae.cxx new file mode 100644 index 000000000..c8e30bada --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Formulae.cxx @@ -0,0 +1,611 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Formulae.hxx" +#include "MEDMEM_STRING.hxx" + +#include <iostream> +#include <sstream> +#include <cmath> +#include <cfloat> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #17: MEDMEM_Formulae.hxx } MEDMEMTest_Formulae.cxx + +/*! + * Check methods (13), defined in MEDMEM_Formulae.hxx: + * + * (+) inline void CalculateBarycenterDyn(const double **pts, int nbPts, int dim, double *bary); + * + * (+) inline double CalculateAreaForPolyg(const double **coords, int nbOfPtsInPolygs, int spaceDim); + * (+) inline double CalculateAreaForTria(const double *p1, const double *p2, + * const double *p3, int spaceDim); + * (+) inline double CalculateAreaForQuad(const double *p1, const double *p2, + * const double *p3, const double *p4, int spaceDim); + * + * (+) inline void CalculateNormalForTria(const double *p1, const double *p2, + * const double *p3, double *normal); + * (+) inline void CalculateNormalForQuad(const double *p1, const double *p2, + * const double *p3, const double *p4, double *normal); + * (+) inline void CalculateNormalForPolyg(const double **coords, int nbOfPtsInPolygs, double *normal); + * + * (+) inline double CalculateVolumeForTetra(const double *p1, const double *p2, + * const double *p3, const double *p4); + * (+) inline double CalculateVolumeForPyra(const double *p1, const double *p2, + * const double *p3, const double *p4, const double *p5); + * (+) inline double CalculateVolumeForPenta(const double *p1, const double *p2, const double *p3, + * const double *p4, const double *p5, const double *p6); + * (+) inline double CalculateVolumeForHexa(const double *pt1, const double *pt2, const double *pt3, + * const double *pt4, const double *pt5, const double *pt6, + * const double *pt7, const double *pt8); + * (+) inline double CalculateVolumeForPolyh(const double ***pts, const int *nbOfNodesPerFaces, + * int nbOfFaces, const double *bary); + * + * (+) template<int N> inline double addComponentsOfVec(const double **pts, int rk); + * (+) template<> inline double addComponentsOfVec<1>(const double **pts, int rk); + * + * (+) template<int N, int DIM> inline void CalculateBarycenter(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<2,0>(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<3,0>(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<4,0>(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<5,0>(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<6,0>(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<7,0>(const double **pts, double *bary); + * (-) template<> inline void CalculateBarycenter<8,0>(const double **pts, double *bary); + */ +void MEDMEMTest::testFormulae() +{ + double val; + + // ^y + // | + // *3 + // 4 | + // .*. . . . . . *6,7 + // | + // . .8* . . . . . + // | 5 2,9 + // . . . .*. * . . + // 1| + // -.-.-*-.-.-.-.-.-->x + // | + + // S_12634 = (3 + (3+4.8)*2 + 4.8 + 1.5*4)/2 = 1.5 + 7.8 + 2.4 + 3 = 14.7 + // S_143652 = S_14362 - S_625 = 14.7 - 2 * 1.5 / 2 = 13.2 + + double xy1[2] = { 0.0, 0.0}; + double xy2[2] = { 3.0, 1.0}; + double xy3[2] = { 0.0, 4.0}; + double xy4[2] = {-1.5, 3.0}; + double xy5[2] = { 1.5, 1.0}; + double xy6[2] = { 4.8, 3.0}; + + double xyz1[3] = { 0.0, 0.0, 0.0}; + double xyz2[3] = { 3.0, 1.0, 4.0}; // cos(alpha) = 3/5 + double xyz3[3] = { 0.0, 4.0, 0.0}; + double xyz4[3] = {-1.5, 3.0, -2.0}; // z4 = z2 * x4 / x2 = - 4 * 1.5 / 3 + double xyz5[3] = { 1.5, 1.0, 2.0}; // z5 = z2 * x5 / x2 = 4 * 1.5 / 3 + double xyz6[3] = { 4.8, 3.0, 6.4}; // z6 = z2 * x6 / x2 = 4 * 4.8 / 3 + double xyz7[3] = { 4.8, 3.0, 0.0}; + double xyz8[3] = { 0.0, 2.0, 0.0}; + double xyz9[3] = { 3.0, 1.0, 0.0}; + + // S_3d = S_2d * 5.0 / 3.0 + + /////////////////////////// + // CalculateAreaForPolyg // + /////////////////////////// + { + // 2D: Convex polygon + const double * poly_2d_cc[5] = {xy1, xy2, xy6, xy3, xy4}; + const double * poly_2d_cw[5] = {xy1, xy4, xy3, xy6, xy2}; + + // counter-clockwise + val = CalculateAreaForPolyg(poly_2d_cc, /*nbOfPtsInPolygs*/5, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-14.7, val, 0.000001); + + // clockwise + val = CalculateAreaForPolyg(poly_2d_cw, /*nbOfPtsInPolygs*/5, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(14.7, val, 0.000001); + + // 2D: Non-convex polygon + const double * poly_2d_nc[6] = {xy1, xy4, xy3, xy6, xy5, xy2}; + val = CalculateAreaForPolyg(poly_2d_nc, /*nbOfPtsInPolygs*/6, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(13.2, val, 0.000001); + + // 3D: Convex polygon + const double * poly_3d_cc[5] = {xyz1, xyz2, xyz6, xyz3, xyz4}; + + val = CalculateAreaForPolyg(poly_3d_cc, /*nbOfPtsInPolygs*/5, /*dim*/3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(24.5, val, 0.000001); + + // 3D: Non-convex polygon + const double * poly_3d_nc[6] = {xyz1, xyz4, xyz3, xyz6, xyz5, xyz2}; + val = CalculateAreaForPolyg(poly_3d_nc, /*nbOfPtsInPolygs*/6, /*dim*/3); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Wrong area calculation for non-convex polygons in 3D space, + // because area of triangle is always positive + CPPUNIT_ASSERT_DOUBLES_EQUAL(22.0, val, 0.000001); +#endif + } + + ////////////////////////// + // CalculateAreaForTria // + ////////////////////////// + { + // 2D: counter-clockwise + val = CalculateAreaForTria(xy1, xy2, xy3, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-6.0, val, 0.000001); + + // 2D: clockwise + val = CalculateAreaForTria(xy2, xy1, xy3, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, val, 0.000001); + + // 3D + val = CalculateAreaForTria(xyz1, xyz2, xyz3, /*dim*/3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(10.0, val, 0.000001); + + // Invalid (three points on one line) + val = CalculateAreaForTria(xyz1, xyz8, xyz3, /*dim*/3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, val, 0.000001); + } + + ////////////////////////// + // CalculateAreaForQuad // + ////////////////////////// + { + // 2D: Convex quadrangle + + // counter-clockwise + val = CalculateAreaForQuad(xy1, xy2, xy3, xy4, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-9.0, val, 0.000001); + + // clockwise + val = CalculateAreaForQuad(xy2, xy1, xy4, xy3, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.0, val, 0.000001); + + // wrong order + CPPUNIT_ASSERT_NO_THROW(CalculateAreaForQuad(xy2, xy1, xy3, xy4, /*dim*/2)); + + // 2D: Non-convex quadrangle + + // counter-clockwise + val = CalculateAreaForQuad(xy1, xy2, xy3, xy5, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0, val, 0.000001); + + // clockwise + val = CalculateAreaForQuad(xy1, xy5, xy3, xy2, /*dim*/2); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, val, 0.000001); + + // 3D: Convex quadrangle + + // good order + val = CalculateAreaForQuad(xyz1, xyz2, xyz3, xyz4, /*dim*/3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(15.0, val, 0.000001); + + // wrong order + CPPUNIT_ASSERT_NO_THROW(CalculateAreaForQuad(xyz1, xyz4, xyz2, xyz3, /*dim*/3)); + + // 3D: Non-convex quadrangle + val = CalculateAreaForQuad(xyz1, xyz2, xyz3, xyz5, /*dim*/3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, val, 0.000001); + + // 3D: Non-planar quadrangle + double xyz7[3] = {-1.5, 3.0, 2.0}; + CPPUNIT_ASSERT_NO_THROW(CalculateAreaForQuad(xyz1, xyz2, xyz3, xyz7, /*dim*/3)); + } + + //////////////////////////// + // CalculateNormalForTria // + //////////////////////////// + { + double tria_normal [3]; + + // Triangle in plane XOY, normal is opposit to axis Z + CalculateNormalForTria(xyz1, xyz3, xyz7, tria_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, tria_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, tria_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT(tria_normal[2] < -0.0000001); // Nz + + // Triangle in plane XOY, normal co-directed with axis Z + CalculateNormalForTria(xyz1, xyz7, xyz3, tria_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, tria_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, tria_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT(tria_normal[2] > 0.0000001); // Nz + + // Triangle in 3D + CalculateNormalForTria(xyz1, xyz3, xyz6, tria_normal); + double koeff = tria_normal[0]/12.8; + //CPPUNIT_ASSERT_DOUBLES_EQUAL(12.8, tria_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0 , tria_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT_DOUBLES_EQUAL(-9.6 * koeff, tria_normal[2], 0.0000001); // Nz + + // Invalid Triangle (three points on one line) + CPPUNIT_ASSERT_NO_THROW(CalculateNormalForTria(xyz1, xyz8, xyz3, tria_normal)); + //MEDMEMTest_DumpArray<double>(cout, tria_normal, 3, "Invalid Triangle normal"); + //Invalid Triangle normal: {0, 0, 0} + } + + //////////////////////////// + // CalculateNormalForQuad // + //////////////////////////// + { + double quad_normal [3]; + + // Quadrangle in plane XOY, normal is opposit to axis Z + CalculateNormalForQuad(xyz1, xyz3, xyz7, xyz9, quad_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, quad_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, quad_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT(quad_normal[2] < -0.0000001); // Nz + + // Quadrangle in plane XOY, normal co-directed with axis Z + CalculateNormalForQuad(xyz1, xyz9, xyz7, xyz3, quad_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, quad_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, quad_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT(quad_normal[2] > 0.0000001); // Nz + + // Quadrangle in 3D + CalculateNormalForQuad(xyz1, xyz3, xyz6, xyz2, quad_normal); + //MEDMEMTest_DumpArray<double>(cout, quad_normal, 3, "Quadrangle in 3D normal"); + double koeff = quad_normal[0]/15.6; + //CPPUNIT_ASSERT_DOUBLES_EQUAL(15.6, quad_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0 , quad_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT_DOUBLES_EQUAL(-11.7 * koeff, quad_normal[2], 0.0000001); // Nz + + // Invalid Quadrangle (four points on one line) + CPPUNIT_ASSERT_NO_THROW(CalculateNormalForQuad(xyz1, xyz8, xyz3, xyz3, quad_normal)); + //MEDMEMTest_DumpArray<double>(cout, quad_normal, 3, "Invalid Quadrangle normal"); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) division on zero in CalculateNormalForQuad(), if quadrangle is singular + //Invalid Quadrangle normal: {nan, nan, nan} + CPPUNIT_ASSERT(quad_normal[0] < DBL_MAX); + CPPUNIT_ASSERT(quad_normal[1] < DBL_MAX); + CPPUNIT_ASSERT(quad_normal[2] < DBL_MAX); +#endif + } + + ///////////////////////////// + // CalculateNormalForPolyg // + ///////////////////////////// + { + double poly_normal [3]; + const double * polygon_cc[4] = {xyz1, xyz3, xyz7, xyz9}; + const double * polygon_er[4] = {xyz1, xyz8, xyz3, xyz7}; + const double * polygon_cw[4] = {xyz1, xyz9, xyz7, xyz3}; + const double * polygon_3d[4] = {xyz1, xyz3, xyz6, xyz2}; + const double * polygon_si[4] = {xyz1, xyz8, xyz3, xyz3}; + + // Polygon in plane XOY, normal is opposit to axis Z + CalculateNormalForPolyg(polygon_cc, /*nbOfPtsInPolygs*/4, poly_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, poly_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, poly_normal[1], 0.0000001); // Ny +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Normal for polygon is wrong + CPPUNIT_ASSERT(poly_normal[2] < -0.0000001); // Nz +#endif + + // Polygon in plane XOY, normal co-directed with axis Z + CalculateNormalForPolyg(polygon_cw, /*nbOfPtsInPolygs*/4, poly_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, poly_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, poly_normal[1], 0.0000001); // Ny +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Normal for polygon is wrong + CPPUNIT_ASSERT(poly_normal[2] > 0.0000001); // Nz +#endif + + // Polygon in plane XOY, normal is opposit to axis Z, first three points lay on one line + CalculateNormalForPolyg(polygon_er, /*nbOfPtsInPolygs*/4, poly_normal); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, poly_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, poly_normal[1], 0.0000001); // Ny +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Normal for polygon is wrong if first (three) points are on one line + CPPUNIT_ASSERT(poly_normal[2] < -0.0000001); // Nz +#endif + + // Polygon in 3D + CalculateNormalForPolyg(polygon_3d, /*nbOfPtsInPolygs*/4, poly_normal); + double koeff = poly_normal[0]/15.6; + //CPPUNIT_ASSERT_DOUBLES_EQUAL(15.6, poly_normal[0], 0.0000001); // Nx + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0 , poly_normal[1], 0.0000001); // Ny + CPPUNIT_ASSERT_DOUBLES_EQUAL(-11.7 * koeff, poly_normal[2], 0.0000001); // Nz + + // Invalid Polygon (four points on one line) + CPPUNIT_ASSERT_NO_THROW(CalculateNormalForPolyg(polygon_si, /*nbOfPtsInPolygs*/4, poly_normal)); + //MEDMEMTest_DumpArray<double>(cout, poly_normal, 3, "Invalid Polygon normal"); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) division on zero in CalculateNormalForPolyg(), if polygon is singular + //Invalid Polygon normal: {nan, nan, nan} + CPPUNIT_ASSERT(poly_normal[0] < DBL_MAX); + CPPUNIT_ASSERT(poly_normal[1] < DBL_MAX); + CPPUNIT_ASSERT(poly_normal[2] < DBL_MAX); +#endif + } + + ///////////////////////////// + // CalculateVolumeForTetra // + ///////////////////////////// + { + // good + val = CalculateVolumeForTetra(xyz1, xyz3, xyz7, xyz5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6.4, val, 0.000001); + + // reversed + val = CalculateVolumeForTetra(xyz1, xyz7, xyz3, xyz5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-6.4, val, 0.000001); + + // good + val = CalculateVolumeForTetra(xyz1, xyz7, xyz3, xyz4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6.4, val, 0.000001); + + // reversed + val = CalculateVolumeForTetra(xyz1, xyz3, xyz7, xyz4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-6.4, val, 0.000001); + + // singular (in plane) + val = CalculateVolumeForTetra(xyz1, xyz3, xyz7, xyz9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, val, 0.000001); + } + + //////////////////////////// + // CalculateVolumeForPyra // + //////////////////////////// + { + // good + val = CalculateVolumeForPyra(xyz1, xyz3, xyz7, xyz9, xyz5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8, val, 0.000001); + + // reversed + val = CalculateVolumeForPyra(xyz1, xyz9, xyz7, xyz3, xyz5); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-7.8, val, 0.000001); + + // good + val = CalculateVolumeForPyra(xyz1, xyz9, xyz7, xyz3, xyz4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(7.8, val, 0.000001); + + // reversed + val = CalculateVolumeForPyra(xyz1, xyz3, xyz7, xyz9, xyz4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-7.8, val, 0.000001); + + // singular (in plane) + val = CalculateVolumeForPyra(xyz1, xyz3, xyz7, xyz9, xyz8); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, val, 0.000001); + } + + ///////////////////////////// + // CalculateVolumeForPenta // + ///////////////////////////// + { + double top1[3] = {xyz1[0], xyz1[1], xyz1[2] + 10.0}; + double top3[3] = {xyz3[0], xyz3[1], xyz3[2] + 10.0}; + double top7[3] = {xyz7[0], xyz7[1], xyz7[2] + 10.0}; + + // good + val = CalculateVolumeForPenta(xyz1, xyz3, xyz7, top1, top3, top7); + CPPUNIT_ASSERT_DOUBLES_EQUAL(96.0, val, 0.000001); + + // reversed + val = CalculateVolumeForPenta(xyz1, xyz7, xyz3, top1, top7, top3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-96.0, val, 0.000001); + + // good + top1[0] = top1[0] + 7.0; + top3[0] = top3[0] + 7.0; + top7[0] = top7[0] + 7.0; + + val = CalculateVolumeForPenta(xyz1, xyz3, xyz7, top1, top3, top7); + CPPUNIT_ASSERT_DOUBLES_EQUAL(96.0, val, 0.000001); + + // reversed + val = CalculateVolumeForPenta(xyz1, xyz7, xyz3, top1, top7, top3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-96.0, val, 0.000001); + + // singular (in plane) + top1[2] = top1[2] - 10.0; + top3[2] = top3[2] - 10.0; + top7[2] = top7[2] - 10.0; + + val = CalculateVolumeForPenta(xyz1, xyz3, xyz7, top1, top3, top7); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, val, 0.000001); + } + + //////////////////////////// + // CalculateVolumeForHexa // + //////////////////////////// + { + double top1[3] = {xyz1[0], xyz1[1], xyz1[2] + 10.0}; + double top3[3] = {xyz3[0], xyz3[1], xyz3[2] + 10.0}; + double top7[3] = {xyz7[0], xyz7[1], xyz7[2] + 10.0}; + double top9[3] = {xyz9[0], xyz9[1], xyz9[2] + 10.0}; + + // good + val = CalculateVolumeForHexa(xyz1, xyz3, xyz7, xyz9, top1, top3, top7, top9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(117.0, val, 0.000001); + + // reversed + val = CalculateVolumeForHexa(xyz1, xyz9, xyz7, xyz3, top1, top9, top7, top3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-117.0, val, 0.000001); + + // good + top1[0] = top1[0] + 7.0; + top3[0] = top3[0] + 7.0; + top7[0] = top7[0] + 7.0; + top9[0] = top9[0] + 7.0; + + val = CalculateVolumeForHexa(xyz1, xyz3, xyz7, xyz9, top1, top3, top7, top9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(117.0, val, 0.000001); + + // reversed + val = CalculateVolumeForHexa(xyz1, xyz9, xyz7, xyz3, top1, top9, top7, top3); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-117.0, val, 0.000001); + + // singular (in plane) + top1[2] = top1[2] - 10.0; + top3[2] = top3[2] - 10.0; + top7[2] = top7[2] - 10.0; + top9[2] = top9[2] - 10.0; + + val = CalculateVolumeForHexa(xyz1, xyz3, xyz7, xyz9, top1, top3, top7, top9); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, val, 0.000001); + } + + ///////////////////////////// + // CalculateVolumeForPolyh // + ///////////////////////////// + // inline double CalculateVolumeForPolyh(const double ***pts, const int *nbOfNodesPerFaces, + // int nbOfFaces, const double *bary); + { + int nbFaces = 4; + int nbOfNodesPerFaces[4] = {3,3,3,3}; + + const double * nodes[4] = {xyz1, xyz7, xyz3, xyz5}; + double bary[3]; + CalculateBarycenterDyn(nodes, 4, /*dim*/3, bary); + + // good + const double * fa1[3] = {xyz1, xyz7, xyz3}; + const double * fa2[3] = {xyz1, xyz3, xyz5}; + const double * fa3[3] = {xyz3, xyz7, xyz5}; + const double * fa4[3] = {xyz7, xyz1, xyz5}; + const double ** polyh[4] = {fa1, fa2, fa3, fa4}; + + val = CalculateVolumeForPolyh(polyh, nbOfNodesPerFaces, nbFaces, bary); + CPPUNIT_ASSERT_DOUBLES_EQUAL(6.4, val, 0.000001); + + // reversed + //const double * fa1_r[3] = {xyz1, xyz3, xyz7}; + //const double * fa2_r[3] = {xyz3, xyz1, xyz5}; + //const double * fa3_r[3] = {xyz7, xyz3, xyz5}; + //const double * fa4_r[3] = {xyz1, xyz7, xyz5}; + //const double ** polyh_r[4] = {fa1_r, fa2_r, fa3_r, fa4_r}; + // + //val = CalculateVolumeForPolyh(polyh_r, nbOfNodesPerFaces, nbFaces, bary); + //CPPUNIT_ASSERT_DOUBLES_EQUAL(-6.4, val, 0.000001); + + // singular (in plane) + const double * nodes_si[4] = {xyz1, xyz7, xyz3, xyz9}; + double bary_si[3]; + CalculateBarycenterDyn(nodes_si, 4, /*dim*/3, bary_si); + + const double * fa1_si[3] = {xyz1, xyz7, xyz3}; + const double * fa2_si[3] = {xyz1, xyz3, xyz9}; + const double * fa3_si[3] = {xyz3, xyz7, xyz9}; + const double * fa4_si[3] = {xyz7, xyz1, xyz9}; + const double ** polyh_si[4] = {fa1_si, fa2_si, fa3_si, fa4_si}; + + val = CalculateVolumeForPolyh(polyh_si, nbOfNodesPerFaces, nbFaces, bary_si); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, val, 0.000001); + } + + //////////////////////// + // addComponentsOfVec // + //////////////////////// + { + // five points + const double * pts[5] = {xyz2, xyz1, xyz3, xyz4, xyz5}; + + val = addComponentsOfVec<5>(pts, 0); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, val, 0.000001); + + val = addComponentsOfVec<5>(pts, 1); // y + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.0, val, 0.000001); + + val = addComponentsOfVec<5>(pts, 2); // z + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, val, 0.000001); + + // one point: xyz2 + val = addComponentsOfVec<1>(pts, 0); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, val, 0.000001); + + val = addComponentsOfVec<1>(pts, 1); // y + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, val, 0.000001); + + val = addComponentsOfVec<1>(pts, 2); // z + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, val, 0.000001); + } + + //////////////////////////// + // CalculateBarycenterDyn // + //////////////////////////// + { + // five points + const double * pts[5] = {xyz2, xyz1, xyz3, xyz4, xyz5}; + double bary_3d[3]; + double bary_2d[2]; + + CalculateBarycenterDyn(pts, /*nbPts*/5, /*dim*/3, bary_3d); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0/5.0, bary_3d[0], 0.000001); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.0/5.0, bary_3d[1], 0.000001); // y + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0/5.0, bary_3d[2], 0.000001); // z + + CalculateBarycenterDyn(pts, /*nbPts*/5, /*dim*/2, bary_2d); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0/5.0, bary_2d[0], 0.000001); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.0/5.0, bary_2d[1], 0.000001); // y + + // one point: xyz2 + CalculateBarycenterDyn(pts, /*nbPts*/1, /*dim*/3, bary_3d); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, bary_3d[0], 0.000001); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, bary_3d[1], 0.000001); // y + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, bary_3d[2], 0.000001); // z + } + + ///////////////////////// + // CalculateBarycenter // + ///////////////////////// + // template<int N, int DIM> inline void CalculateBarycenter(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<2,0>(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<3,0>(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<4,0>(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<5,0>(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<6,0>(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<7,0>(const double **pts, double *bary); + // template<> inline void CalculateBarycenter<8,0>(const double **pts, double *bary); + { + // five points + const double * pts[5] = {xyz2, xyz1, xyz3, xyz4, xyz5}; + double bary_3d[3]; + double bary_2d[2]; + + CalculateBarycenter<5,3>(pts, bary_3d); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0/5.0, bary_3d[0], 0.000001); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.0/5.0, bary_3d[1], 0.000001); // y + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0/5.0, bary_3d[2], 0.000001); // z + + CalculateBarycenter<5,2>(pts, bary_2d); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0/5.0, bary_2d[0], 0.000001); // x + CPPUNIT_ASSERT_DOUBLES_EQUAL(9.0/5.0, bary_2d[1], 0.000001); // y + + // one point: xyz2 : NOT IMPLEMENTED!!! + //CalculateBarycenter<1,3>(pts, bary_3d); + //CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, bary_3d[0], 0.000001); + //CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, bary_3d[1], 0.000001); + //CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, bary_3d[2], 0.000001); + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_GaussLocalization.cxx b/src/MEDMEM/Test/MEDMEMTest_GaussLocalization.cxx new file mode 100644 index 000000000..d7b03d67a --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_GaussLocalization.cxx @@ -0,0 +1,206 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_GaussLocalization.hxx" +#include "MEDMEM_STRING.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #18: MEDMEM_GaussLocalization.hxx } MEDMEMTest.cxx + +/*! + * Check methods (13), defined in MEDMEM_GaussLocalization.hxx: + * class GAUSS_LOCALIZATION_ { + * (+) virtual MED_EN::medModeSwitch getInterlacingType() const; + * (+) virtual ~GAUSS_LOCALIZATION_(); + * } + * (+) template <class INTERLACING_TAG=FullInterlace> class GAUSS_LOCALIZATION; + * + * (+) template <class INTERLACING_TAG> ostream & operator<< + * (ostream &os, const GAUSS_LOCALIZATION<INTERLACING_TAG> &loc); + * + * template <class INTERLACING_TAG> class GAUSS_LOCALIZATION : public GAUSS_LOCALIZATION_ { + * (+) GAUSS_LOCALIZATION() throw (MEDEXCEPTION); + * (+) GAUSS_LOCALIZATION(const string & locName, + * const MED_EN::medGeometryElement typeGeo, + * const int nGauss, + * const ArrayNoGauss & cooRef, + * const ArrayNoGauss & cooGauss, + * const vector<double> & wg) throw (MEDEXCEPTION); + * (+) GAUSS_LOCALIZATION(const string & locName, + * const MED_EN::medGeometryElement typeGeo, + * const int nGauss, + * const double * const cooRef, + * const double * const cooGauss, + * const double * const wg) throw (MEDEXCEPTION); + * (+) virtual ~GAUSS_LOCALIZATION(); + * + * (+) GAUSS_LOCALIZATION & operator=(const GAUSS_LOCALIZATION & gaussLoc); + * (+) bool operator == (const GAUSS_LOCALIZATION &loc) const; + * + * (+) string getName() const; + * (+) MED_EN::medGeometryElement getType() const; + * + * (+) int getNbGauss() const; + * (+) ArrayNoGauss getRefCoo () const; + * (+) ArrayNoGauss getGsCoo () const; + * (+) vector <double> getWeight () const; + * + * (+) inline MED_EN::medModeSwitch getInterlacingType() const; + * } + */ +void MEDMEMTest::testGaussLocalization() +{ + // GAUSS_LOCALIZATION_ + GAUSS_LOCALIZATION_ aGL_; + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_UNDEFINED_INTERLACE, aGL_.getInterlacingType()); + + // GAUSS_LOCALIZATION empty constructor and InterlaceType + GAUSS_LOCALIZATION<> anEmptyGL1; + MED_EN::medModeSwitch aDefaultInterlaceType = anEmptyGL1.getInterlacingType(); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FULL_INTERLACE, aDefaultInterlaceType); + + GAUSS_LOCALIZATION<NoInterlace> anEmptyGL2; + MED_EN::medModeSwitch anInterlaceType2 = anEmptyGL2.getInterlacingType(); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NO_INTERLACE, anInterlaceType2); + + // Construction from C++ arrays + double cooRef[6] = {1.,1., 2.,4., 3.,9.}; // xy xy xy + double cooGauss[10] = {7.,7., 6.,6., 5.,5., 4.,3., 2.,1.}; // x1,y1 x2,y2 x3,y3 x4,y4 x5,y5 + double wg[5] = {1., 2., 3., 4., 5.}; + + GAUSS_LOCALIZATION<> gl1 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg); + GAUSS_LOCALIZATION<> gl2 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg); + + // getXXX + CPPUNIT_ASSERT(gl1.getName() == "GL1"); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, gl1.getType()); + CPPUNIT_ASSERT_EQUAL(5, gl1.getNbGauss()); + + GAUSS_LOCALIZATION<>::ArrayNoGauss cooRefBack = gl1.getRefCoo(); + GAUSS_LOCALIZATION<>::ArrayNoGauss cooGaussBack = gl1.getGsCoo(); + vector<double> wgBack = gl1.getWeight(); + + double * cooRefBack_ptr = cooRefBack.getPtr(); + double * cooGaussBack_ptr = cooGaussBack.getPtr(); + + for (int i = 0; i < 10; i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL(cooRef[i%6], cooRefBack_ptr[i%6], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(cooGauss[i], cooGaussBack_ptr[i], 0.000001); + CPPUNIT_ASSERT_DOUBLES_EQUAL(wg[i%5] , wgBack[i%5] , 0.000001); + } + + // Operators == and = + CPPUNIT_ASSERT(gl1 == gl2); + CPPUNIT_ASSERT_EQUAL(gl1, gl2); + + GAUSS_LOCALIZATION<> gl1_c; + gl1_c = gl1; + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Badly copyed arrays as a result of operator= usage + CPPUNIT_ASSERT_EQUAL(gl1, gl1_c); + // Invalid read of size 8 + // at 0x342B157A: MEDMEM::MEDMEM_Array<double, MEDMEM::FullInterlaceNoGaussPolicy, MEDMEM::IndexCheckPolicy>::operator==(MEDMEM::MEDMEM_Array<double, MEDMEM::FullInterlaceNoGaussPolicy, MEDMEM::IndexCheckPolicy> const&) const (MEDMEM_nArray.hxx:255) + // by 0x342A1CDA: MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace>::operator==(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&) const (MEDMEM_GaussLocalization.hxx:175) + // by 0x34315F98: CppUnit::assertion_traits<MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> >::equal(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&, MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&) (TestAssert.h:40) + // by 0x34314D35: void CppUnit::assertEquals<MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> >(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&, MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&, CppUnit::SourceLine, std::string const&) (TestAssert.h:62) + // by 0x34311D6F: MEDMEMTest::testGaussLocalization() (MEDMEMTest_GaussLocalization.cxx:132) + // Address 0x35B5FC98 is 0 bytes inside a block of size 48 free'd + // at 0x3414CD61: operator delete[](void*) (vg_replace_malloc.c:161) + // by 0x341D88CA: MEDMEM::PointerOf<double>::~PointerOf() (MEDMEM_PointerOf.hxx:141) + // by 0x341D56C7: MEDMEM::MEDMEM_Array<double, MEDMEM::FullInterlaceNoGaussPolicy, MEDMEM::IndexCheckPolicy>::~MEDMEM_Array() (MEDMEM_nArray.hxx:52) + // by 0x34314F58: MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace>::operator=(MEDMEM::GAUSS_LOCALIZATION<MEDMEM::FullInterlace> const&) (MEDMEM_GaussLocalization.hxx:166) + // by 0x34311CCC: MEDMEMTest::testGaussLocalization() (MEDMEMTest_GaussLocalization.cxx:128) +#endif + + // same name, type and nb.gauss, but different coords or weights + double cooRef_ch[6] = {1.,1., 2.,8., 3.,9.}; + double cooGauss_ch[10] = {7.,8., 6.,6., 5.,5., 4.,3., 2.,1.}; + double wg_ch[5] = {1., 2., 8., 4., 5.}; + + GAUSS_LOCALIZATION<> gl3 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef_ch, cooGauss, wg); + GAUSS_LOCALIZATION<> gl4 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss_ch, wg); + GAUSS_LOCALIZATION<> gl5 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg_ch); + + CPPUNIT_ASSERT(!(gl1 == gl3)); + CPPUNIT_ASSERT(!(gl1 == gl4)); + CPPUNIT_ASSERT(!(gl1 == gl5)); + + // different name or type, or nb.gauss + double cooRef_quad[8] = {1.,1., 2.,4., 3.,9., 4., 16.}; + double cooGauss_4[8] = {7.,8., 6.,6., 5.,5., 4.,3.}; + double wg_4[4] = {1., 2., 8., 4.}; + + GAUSS_LOCALIZATION<> gl6 ("GL6", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef, cooGauss, wg); + GAUSS_LOCALIZATION<> gl7 ("GL1", MED_EN::MED_QUAD4, /*nGauss*/5, cooRef_quad, cooGauss, wg); + GAUSS_LOCALIZATION<> gl8 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/4, cooRef, cooGauss_4, wg_4); + + CPPUNIT_ASSERT(!(gl1 == gl6)); + CPPUNIT_ASSERT(!(gl1 == gl7)); + CPPUNIT_ASSERT(!(gl1 == gl8)); + + // Operator << + ostringstream ostr1; + ostr1 << gl1; + CPPUNIT_ASSERT(ostr1.str() != ""); + + ostringstream ostr2; + ostr2 << gl2; + CPPUNIT_ASSERT_EQUAL(ostr1.str(), ostr2.str()); + + // Construction from ArrayNoGauss and vector<double> + GAUSS_LOCALIZATION<> gl9 ("GL1", MED_EN::MED_TRIA3, /*nGauss*/5, cooRefBack, cooGaussBack, wgBack); + CPPUNIT_ASSERT(gl1 == gl9); + + // NoInterlace + double cooRef_ni[6] = {1.,2.,3., 1.,4.,9.}; // xxx yyy + double cooGauss_ni[10] = {7.,6.,5.,4.,2., 7.,6.,5.,3.,1.}; // x1,x2,x3,x4,x5 y1,y2,y3,y4,y5 + + GAUSS_LOCALIZATION<NoInterlace> gl10 ("GL10", MED_EN::MED_TRIA3, /*nGauss*/5, cooRef_ni, cooGauss_ni, wg); + + GAUSS_LOCALIZATION<NoInterlace>::ArrayNoGauss cooRefBack_ni = gl10.getRefCoo(); + GAUSS_LOCALIZATION<NoInterlace>::ArrayNoGauss cooGaussBack_ni = gl10.getGsCoo(); + + for (int i = 1; i <= 3; i++) { // nb. nodes + for (int j = 1; j <= 2; j++) { // dim + CPPUNIT_ASSERT_DOUBLES_EQUAL(cooRefBack.getIJ(i, j), cooRefBack_ni.getIJ(i, j), 0.000001); + } + } + + for (int i = 1; i <= 5; i++) { // nGauss + for (int j = 1; j <= 2; j++) { // dim + CPPUNIT_ASSERT_DOUBLES_EQUAL(cooGaussBack.getIJ(i, j), cooGaussBack_ni.getIJ(i, j), 0.000001); + } + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_GibiMeshDriver.cxx b/src/MEDMEM/Test/MEDMEMTest_GibiMeshDriver.cxx new file mode 100644 index 000000000..f5e7dd63b --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_GibiMeshDriver.cxx @@ -0,0 +1,502 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_GibiMeshDriver.hxx> +#include <MEDMEM_Mesh.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (31), defined in MEDMEM_GibiMeshDriver.hxx: + * class GIBI_MESH_DRIVER : public GENDRIVER { + * (+) GIBI_MESH_DRIVER(); + * (+) GIBI_MESH_DRIVER(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces accessMode); + * (+) GIBI_MESH_DRIVER(const GIBI_MESH_DRIVER & driver); + * (+) virtual ~GIBI_MESH_DRIVER(); + * (+) virtual void write(void) const = 0; + * (+) virtual void read (void) = 0; + * (+) void setMeshName(const string & meshName); + * (+) string getMeshName() const; + * (+) static MED_EN::medGeometryElement gibi2medGeom(size_t gibiTypeNb); + * (+) static int med2gibiGeom(MED_EN::medGeometryElement medGeomType); + * } + * class GIBI_MESH_RDONLY_DRIVER : public virtual GIBI_MESH_DRIVER { + * (+) GIBI_MESH_RDONLY_DRIVER(); + * (+) GIBI_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver); + * (+) virtual ~GIBI_MESH_RDONLY_DRIVER(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void open(); + * (+) void close(); + * } + * class GIBI_MESH_WRONLY_DRIVER : public virtual GIBI_MESH_DRIVER { + * (+) GIBI_MESH_WRONLY_DRIVER(); + * (+) GIBI_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) GIBI_MESH_WRONLY_DRIVER(const GIBI_MESH_WRONLY_DRIVER & driver); + * (+) virtual ~GIBI_MESH_WRONLY_DRIVER(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void open(); + * (+) void close(); + * } + * class GIBI_MESH_RDWR_DRIVER : public GIBI_MESH_RDONLY_DRIVER, public GIBI_MESH_WRONLY_DRIVER { + * (+) GIBI_MESH_RDWR_DRIVER(); + * (+) GIBI_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) GIBI_MESH_RDWR_DRIVER(const GIBI_MESH_RDWR_DRIVER & driver); + * (+) ~GIBI_MESH_RDWR_DRIVER(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void open(); + * (+) void close(); + * } + * class GIBI_MED_RDONLY_DRIVER : public GIBI_MESH_RDONLY_DRIVER { + * (+) GIBI_MED_RDONLY_DRIVER(); + * (+) GIBI_MED_RDONLY_DRIVER(const string & fileName, MED * ptrMed); + * (+) GIBI_MED_RDONLY_DRIVER(const GIBI_MED_RDONLY_DRIVER & driver); + * (+) virtual ~GIBI_MED_RDONLY_DRIVER(); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * class GIBI_MED_WRONLY_DRIVER : public GIBI_MESH_WRONLY_DRIVER { + * (+) GIBI_MED_WRONLY_DRIVER(); + * (+) GIBI_MED_WRONLY_DRIVER(const string & fileName, MED * ptrMed, MESH * ptrMesh); + * (+) GIBI_MED_WRONLY_DRIVER(const GIBI_MED_WRONLY_DRIVER & driver); + * (+) virtual ~GIBI_MED_WRONLY_DRIVER(); + * (+) void write(void) const throw (MEDEXCEPTION); + * } + */ + +void MEDMEMTest::testGibiMeshDriver() +{ + MESH *aMesh = new MESH(); + MESH *aMesh_NULL = NULL; + MESH *aMesh_2 = new MESH(); + MED *aMed = new MED(); + MED *aMed_1 = NULL; + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + + string filename_rd = data_dir + "/Sauv/Darcy3_3D_H_10x10x10.sauve"; + string filenamemed_rd = data_dir + "/Sauv/elle_3D_HPr_10x10x10.sauve"; + string filename_wr = tmp_dir + "/myWr_Darcy3_3D_H_10x10x10.sauve"; + string tmpfile = tmp_dir + "/tmp.sauve"; + string tmpfile_rdwr = tmp_dir + "/rdwr_tmp.sauve"; + string filenamemed_wr = tmp_dir + "/myWrMed_elle_3D_HPr_10x10x10.sauve"; + string tmpfilemed = tmp_dir + "/tmpmed.sauve"; + string meshname = "Darcy3_3D_H_10x10x10"; + string newmeshname = "new" + meshname; + string fileNotExistsName_rd = "notExists.sauve"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.sauve"; + string filename_rdwr = tmp_dir + "/myRdWr_Darcy3_3D_H_10x10x10.sauve"; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(tmpfile); + aRemover.Register(tmpfilemed); + aRemover.Register(filenamemed_wr); + aRemover.Register(tmpfile_rdwr); + aRemover.Register(filename_rdwr); + + //Test gibi2medGeom() and med2gibiGeom() methods + size_t aSize = 17; + CPPUNIT_ASSERT_EQUAL(GIBI_MESH_DRIVER::gibi2medGeom(aSize), MED_PENTA15); + CPPUNIT_ASSERT_EQUAL(GIBI_MESH_DRIVER::med2gibiGeom(MED_PENTA15), 17); + + //---------------------------Test GIBI MESH READ ONLY part--------------------------------// + { + { + //Creation of an incorrect read only driver + GIBI_MESH_RDONLY_DRIVER *aInvalidGibiRdDriver = + new GIBI_MESH_RDONLY_DRIVER(fileNotExistsName_rd, aMesh); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidGibiRdDriver->open(), MEDEXCEPTION); + + delete aInvalidGibiRdDriver; + } + + //Creation a correct Gibi read only driver (normal constructor) + GIBI_MESH_RDONLY_DRIVER *aGibiRdDriver = + new GIBI_MESH_RDONLY_DRIVER(filename_rd, aMesh); + + //Check driver + CPPUNIT_ASSERT(aGibiRdDriver); + + //Trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aGibiRdDriver->read(), MEDEXCEPTION); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aGibiRdDriver->open()); + + //Trying open file secondary. +#ifdef ENABLE_FORCED_FAILURES + //This case is not work, seems it BUG + CPPUNIT_ASSERT_THROW(aGibiRdDriver->open(), MEDEXCEPTION); +#endif + + //Test setMeshName() and getMeshName() methods + CPPUNIT_ASSERT_NO_THROW(aGibiRdDriver->setMeshName(meshname)); + CPPUNIT_ASSERT_EQUAL(meshname, aGibiRdDriver->getMeshName()); + + //Test read() method + CPPUNIT_ASSERT_NO_THROW(aGibiRdDriver->read()); + // Source and destination overlap in memcpy(0x35DBF040, 0x35DBF06D, 101) + // at 0x3414D97E: memcpy (mac_replace_strmem.c:113) + // by 0x3492EDE9: MEDMEM::GIBI_MESH_RDONLY_DRIVER::getLine(char*&) (MEDMEM_GibiMeshDriver.cxx:942) + // by 0x349407FD: MEDMEM::GIBI_MESH_RDONLY_DRIVER::getNextLine(char*&, bool) (MEDMEM_GibiMeshDriver.hxx:168) + // by 0x349268B1: MEDMEM::GIBI_MESH_RDONLY_DRIVER::readFile(MEDMEM::_intermediateMED*, bool) (MEDMEM_GibiMeshDriver.cxx:209) + // by 0x3492F58B: MEDMEM::GIBI_MESH_RDONLY_DRIVER::read() (MEDMEM_GibiMeshDriver.cxx:1058) + // by 0x3436DEA6: MEDMEMTest::testGibiMeshDriver() (MEDMEMTest_GibiMeshDriver.cxx:168) + + //Trying fill not empty mesh + CPPUNIT_ASSERT_THROW(aGibiRdDriver->read(), MEDEXCEPTION); + + //Test write() method for GIBI READ ONLY driver + CPPUNIT_ASSERT_THROW(aGibiRdDriver->write(), MEDEXCEPTION); + + //Check Mesh + CPPUNIT_ASSERT(aMesh); + + //Test close method + CPPUNIT_ASSERT_NO_THROW(aGibiRdDriver->close()); + + //Default constructor + { + GIBI_MESH_RDONLY_DRIVER aGibiRdDriverCpy_1; + } + + //Test copy constructor and operator==(), defined in GENDRIVER class + { + GIBI_MESH_RDONLY_DRIVER aGibiRdDriverCpy_2 (*aGibiRdDriver); + CPPUNIT_ASSERT(aGibiRdDriverCpy_2.GENDRIVER::operator==(*aGibiRdDriver)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + ostringstream rostr1, rostr2; + rostr1 << *aGibiRdDriver; + rostr2 << aGibiRdDriverCpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT(rostr1.str() == rostr2.str()); + } + + delete aGibiRdDriver; + } + + //-------------------------------Test GIBI WRITE ONLY part------------------------------// + { + { + //Creation a incorrect gibi write only driver + GIBI_MESH_WRONLY_DRIVER *aInvalidGibiWrDriver = + new GIBI_MESH_WRONLY_DRIVER(fileNotExistsName_wr, aMesh); + + //Trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidGibiWrDriver->open(), MEDEXCEPTION); + + delete aInvalidGibiWrDriver; + } + + //Trying write empty mesh + { + GIBI_MESH_WRONLY_DRIVER *aTmpGibiWrDriver = + new GIBI_MESH_WRONLY_DRIVER(tmpfile, aMesh_NULL); + aTmpGibiWrDriver->open(); + + CPPUNIT_ASSERT_THROW(aTmpGibiWrDriver->write(),MEDEXCEPTION); + aTmpGibiWrDriver->close(); + + delete aTmpGibiWrDriver; + } + + //Creation a correct gibi write only drivers + GIBI_MESH_WRONLY_DRIVER *aGibiWrDriver = + new GIBI_MESH_WRONLY_DRIVER(filename_wr, aMesh); + + //Check driver + CPPUNIT_ASSERT(aGibiWrDriver); + + //Trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aGibiWrDriver->write(), MEDEXCEPTION); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aGibiWrDriver->open()); + + //Trying open file secondary. +#ifdef ENABLE_FORCED_FAILURES + // (BUG) No exception on attempt to open an opened file for the second time + CPPUNIT_ASSERT_THROW(aGibiWrDriver->open(), MEDEXCEPTION); +#endif + + //Test setMeshName() and getMeshName() methods + CPPUNIT_ASSERT_NO_THROW(aGibiWrDriver->setMeshName(newmeshname)); + CPPUNIT_ASSERT_EQUAL(newmeshname, aGibiWrDriver->getMeshName()); + + //Test write() method + CPPUNIT_ASSERT_NO_THROW(aGibiWrDriver->write()); + + //Test read() method for GIBI WRITE ONLY driver + CPPUNIT_ASSERT_THROW(aGibiWrDriver->read(), MEDEXCEPTION); + + //Test close method + CPPUNIT_ASSERT_NO_THROW(aGibiWrDriver->close()); + + //Default constructor + GIBI_MESH_WRONLY_DRIVER aGibiWrDriverCpy_1; + + //Test copy constructor + GIBI_MESH_WRONLY_DRIVER aGibiWrDriverCpy_2 (*aGibiWrDriver); + + //Test (bool operator ==) defined GENDRIVER class + CPPUNIT_ASSERT(aGibiWrDriverCpy_2.GENDRIVER::operator==(*aGibiWrDriver)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + ostringstream wostr1, wostr2; + wostr1 << *aGibiWrDriver; + wostr2 << aGibiWrDriverCpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + delete aGibiWrDriver; + } + + //-------------------------------Test GIBI READ/WRITE part---------------------------------// + { + //Copy file + system(fcopy.c_str()); + + { + //Creation a incorrect gibi read/write driver + GIBI_MESH_RDWR_DRIVER *aInvalidGibiRdWrDriver = + new GIBI_MESH_RDWR_DRIVER(fileNotExistsName_wr, aMesh_2); + + //Trying read/write from not existing file + CPPUNIT_ASSERT_THROW(aInvalidGibiRdWrDriver->read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidGibiRdWrDriver->write(), MEDEXCEPTION); + + delete aInvalidGibiRdWrDriver; + } + + //Trying write empty mesh + { + GIBI_MESH_RDWR_DRIVER *aTmpGibiRdWrDriver = + new GIBI_MESH_RDWR_DRIVER(tmpfile_rdwr, aMesh_NULL); + CPPUNIT_ASSERT_THROW(aTmpGibiRdWrDriver->write(), MEDEXCEPTION); + delete aTmpGibiRdWrDriver; + } + + //Creation a correct read/write driver + GIBI_MESH_RDWR_DRIVER *aGibiRdWrDriver = + new GIBI_MESH_RDWR_DRIVER(filename_rdwr, aMesh_2); + + //Test open/close methods + CPPUNIT_ASSERT_NO_THROW(aGibiRdWrDriver->open()); + CPPUNIT_ASSERT_NO_THROW(aGibiRdWrDriver->close()); + + //Check driver + CPPUNIT_ASSERT(aGibiRdWrDriver); + + //Test read() method + CPPUNIT_ASSERT_NO_THROW(aGibiRdWrDriver->read()); + + //Check Mesh + CPPUNIT_ASSERT(aMesh); + + //Trying fill not empty mesh + CPPUNIT_ASSERT_THROW(aGibiRdWrDriver->read(),MEDEXCEPTION); + + //Test write() method + aGibiRdWrDriver->setMeshName(newmeshname); + CPPUNIT_ASSERT_NO_THROW(aGibiRdWrDriver->write()); + + //Default constructor + GIBI_MESH_RDWR_DRIVER aGibiRdWrDriverCpy_1; + + //Test copy constructor + GIBI_MESH_RDWR_DRIVER aGibiRdWrDriverCpy_2 (*aGibiRdWrDriver); + + //Test (bool operator ==) + CPPUNIT_ASSERT(aGibiRdWrDriverCpy_2.GENDRIVER::operator==(*aGibiRdWrDriver)); + + //Test (ostream & operator <<) + ostringstream rwostr1, rwostr2; + rwostr1 << *aGibiRdWrDriver; + rwostr2 << aGibiRdWrDriverCpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + delete aGibiRdWrDriver; + } + + //----------------------------Test GIBI_MED_RDONLY_DRIVER---------------------------- + { + { + GIBI_MED_RDONLY_DRIVER *aInvalidMedGibiRdDriver = + new GIBI_MED_RDONLY_DRIVER(fileNotExistsName_rd, aMed); + + //Trying open not exising file + CPPUNIT_ASSERT_THROW(aInvalidMedGibiRdDriver->open(), MEDEXCEPTION); + + delete aInvalidMedGibiRdDriver; + } + + //Creation a correct Gibi read only driver (normal constructor) + GIBI_MED_RDONLY_DRIVER *aGibiMedRdDriver = + new GIBI_MED_RDONLY_DRIVER(filenamemed_rd, aMed); + + //Check driver + CPPUNIT_ASSERT(aGibiMedRdDriver); + + //Trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aGibiMedRdDriver->read(), MEDEXCEPTION); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aGibiMedRdDriver->open()); + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aGibiMedRdDriver->open(), MEDEXCEPTION); + //This case is not work, seems it BUG +#endif + + //Test read() method + CPPUNIT_ASSERT_NO_THROW(aGibiMedRdDriver->read()); + + //Test write() method for GIBI MED READ ONLY driver + CPPUNIT_ASSERT_THROW(aGibiMedRdDriver->write(), MEDEXCEPTION); + + //Check Med + CPPUNIT_ASSERT(aMed); + + //Test close method + CPPUNIT_ASSERT_NO_THROW(aGibiMedRdDriver->close()); + + //Default constructor + GIBI_MED_RDONLY_DRIVER aGibiMedRdDriverCpy_1; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(! aGibiMedRdDriverCpy_1.GENDRIVER::operator==(*aGibiMedRdDriver)); + + //Test copy constructor + GIBI_MED_RDONLY_DRIVER aGibiMedRdDriverCpy_2 (*aGibiMedRdDriver); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Copy constructor of GIBI_MED_RDONLY_DRIVER is not implemented + CPPUNIT_ASSERT(aGibiMedRdDriverCpy_2.GENDRIVER::operator==(*aGibiMedRdDriver)); +#endif + + //Test (friend ostream & operator <<) defined in GENDRIVER class + ostringstream medrostr1, medrostr2; + medrostr1 << *aGibiMedRdDriver; + medrostr2 << aGibiMedRdDriverCpy_2; + CPPUNIT_ASSERT(medrostr1.str() != ""); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Copy constructor of GIBI_MED_RDONLY_DRIVER is not implemented + CPPUNIT_ASSERT(medrostr1.str() == medrostr2.str()); +#endif + + delete aGibiMedRdDriver; + } + + //----------------------------Test GIBI MED WRITE ONLY part----------------------------------// + { + { + //Creation a incorrect gibi med write only driver + GIBI_MED_WRONLY_DRIVER *aInvalidGibiMedWrDriver = + new GIBI_MED_WRONLY_DRIVER(fileNotExistsName_wr, aMed, aMesh); + + //Trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidGibiMedWrDriver->open(), MEDEXCEPTION); + + delete aInvalidGibiMedWrDriver; + } + + //Trying create gibi med write only driver with null MED and MESH + CPPUNIT_ASSERT_THROW(new GIBI_MED_WRONLY_DRIVER(tmpfilemed, aMed_1, aMesh_NULL), MEDEXCEPTION); + + //Creation a correct gibi med write only drivers + GIBI_MED_WRONLY_DRIVER *aGibiMedWrDriver = + new GIBI_MED_WRONLY_DRIVER(filenamemed_wr, aMed, aMesh); + + //Check driver + CPPUNIT_ASSERT(aGibiMedWrDriver); + + //Trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aGibiMedWrDriver->write(), MEDEXCEPTION); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aGibiMedWrDriver->open()); + + //Trying open file secondary. +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Exception is generated, but second call to open() function breaks driver + CPPUNIT_ASSERT_THROW(aGibiMedWrDriver->open(), MEDEXCEPTION); +#endif + + //Test write() method + CPPUNIT_ASSERT_NO_THROW(aGibiMedWrDriver->write()); + + //Test read() method for GIBI MED WRITE ONLY driver + CPPUNIT_ASSERT_THROW(aGibiMedWrDriver->read(), MEDEXCEPTION); + + //Test close method + CPPUNIT_ASSERT_NO_THROW(aGibiMedWrDriver->close()); + + //Default constructor + GIBI_MED_WRONLY_DRIVER aGibiMedWrDriverCpy_1; + + //Test copy constructor + { + GIBI_MED_WRONLY_DRIVER aGibiMedWrDriverCpy_2 (*aGibiMedWrDriver); + + //Test (bool operator ==) defined in GENDRIVER class +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Copy constructor of GIBI_MED_WRONLY_DRIVER is not implemented!!! + CPPUNIT_ASSERT(aGibiMedWrDriverCpy_2.GENDRIVER::operator==(*aGibiMedWrDriver)); +#endif + + //Test (friend ostream & operator <<) defined GENDRIVER class + ostringstream medwostr1, medwostr2; + medwostr1 << *aGibiMedWrDriver; + medwostr2 << aGibiMedWrDriverCpy_2; + CPPUNIT_ASSERT(medwostr1.str() != ""); +#ifdef ENABLE_FORCED_FAILURES + // Copy constructor of GIBI_MED_WRONLY_DRIVER is not implemented!!! + CPPUNIT_ASSERT(medwostr1.str() == medwostr2.str()); +#endif + } + + delete aGibiMedWrDriver; + } + + //Delete all objects + delete aMesh; + delete aMesh_2; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Grid.cxx b/src/MEDMEM/Test/MEDMEMTest_Grid.cxx new file mode 100644 index 000000000..204b99cfc --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Grid.cxx @@ -0,0 +1,696 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Grid.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_MedMedDriver.hxx" +#include "MEDMEM_MedMeshDriver.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + + +/*! + * Check methods (44), defined in MEDMEM_Grid.hxx: + * class GRID: public MESH { + * (+) GRID(); + * (+) GRID(const MED_EN::med_grid_type type); + * (BUG:operator=() not implemented but init() not called) GRID(const GRID &m); + * (+) GRID(driverTypes driverType, const string & fileName="",const string & meshName=""); + * (+) GRID(const std::vector<std::vector<double> >& xyz_array, + * const std::vector<std::string>& coord_name, + * const std::vector<std::string>& coord_unit, + * const MED_EN::med_grid_type type=MED_EN::MED_CARTESIAN); + * (NOT IMPLEMENTED) GRID & operator=(const GRID &m); + * (+) virtual ~GRID(); + * (+) virtual void init(); + * (tested together with getCoordinateptr() as it is called + * internally from there first of all. + * Moreover, fillCoordinates should be made private to avoid + * ambiguity druing in GRID class usage.) void fillCoordinates() const; + * (tested together with getConnectivityptr()) void fillConnectivity() const; + * (+) inline void makeUnstructured();//fill coordinates and connectivity of MESH + * (+) void fillMeshAfterRead(); + * (+) void writeUnstructured(int index=0, const string & driverName = ""); + * (+) void read(int index=0); + * (+) inline int getNodeNumber(const int i, const int j=0, const int k=0) const; + * (+) inline int getCellNumber(const int i, const int j=0, const int k=0) const; + * (+) int getEdgeNumber + * (const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION); + * (+) int getFaceNumber + * (const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION); + * (+) void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) void getEdgePosition + * (const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) void getFacePosition + * (const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) inline MED_EN::med_grid_type getGridType() const; + * (+) int getArrayLength(const int Axis) const throw (MEDEXCEPTION); + * (+) const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION); + * (+) inline const COORDINATE * getCoordinateptr() const; + * (+) inline const double * getCoordinates(MED_EN::medModeSwitch Mode) const; + * (+) inline const double getCoordinate(int Number,int Axis) const; + * (+) inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const; + * (+) inline int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const; + * (+) MED_EN::medGeometryElement * getTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) inline const CELLMODEL * getCellsTypes(MED_EN::medEntityMesh Entity) const; + * (+) const int * getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const; + * (+) inline int getNumberOfElements + * (MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * (+) inline int getNumberOfElementsWithPoly + * (MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * (+) inline bool existConnectivity + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline MED_EN::medGeometryElement getElementType + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) inline MED_EN::medGeometryElement getElementTypeWithPoly + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) inline void calculateConnectivity(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline const CONNECTIVITY* getConnectivityptr() const; + * (+) inline const int * getConnectivity + * (MED_EN::medModeSwitch Mode, MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * (+) inline const int * getConnectivityIndex(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline const int * getReverseConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) inline const int * getReverseConnectivityIndex(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) inline void setGridType(MED_EN::med_grid_type gridType); + * } + */ +void MEDMEMTest::testGrid() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/test19.med" ; + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filenameout21 = tmp_dir + "/myGridWrite_grid21.med"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filenameout21); + + // Remove file in advance to ensure it does not exist at the moment of writing, + // because files are not removed by the MEDMEMTest_TmpFilesRemover in case of + // Segmentation Fault (in previous tests execution). + { + MEDMEMTest_TmpFilesRemover aRemover1; + aRemover1.Register(filenameout21); + } + + MED * myMed = new MED() ; + MED_MED_RDONLY_DRIVER myMeshDriver (filename, myMed); + myMeshDriver.open(); + myMeshDriver.readFileStruct(); + myMeshDriver.close(); + + int nbMeshes = myMed->getNumberOfMeshes(); + CPPUNIT_ASSERT(nbMeshes); + + deque<string> mesh_names = myMed->getMeshNames(); + CPPUNIT_ASSERT(mesh_names.size() != 0); + + ////////////////////////////// + // test1 "CARTESIAN GRID" // + ////////////////////////////// + { + MESH* myMesh = myMed->getMesh(mesh_names[0]); + myMesh->read(); + + CPPUNIT_ASSERT(myMesh != NULL); + CPPUNIT_ASSERT(myMesh->getIsAGrid()); + + GRID* myGrid = dynamic_cast<GRID*>(myMesh); + CPPUNIT_ASSERT(myGrid); + + CPPUNIT_ASSERT_THROW(myGrid->getArrayLength(0), MEDEXCEPTION); + + int I, J, K; + CPPUNIT_ASSERT_NO_THROW(I = myGrid->getArrayLength(1)); + CPPUNIT_ASSERT_NO_THROW(J = myGrid->getArrayLength(2)); + CPPUNIT_ASSERT_NO_THROW(K = myGrid->getArrayLength(3)); + + CPPUNIT_ASSERT(I); + CPPUNIT_ASSERT(J); + + med_grid_type grid_type = myGrid->getGridType(); + CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_CARTESIAN); + + const double * coordinates = myGrid->getCoordinates(MED_FULL_INTERLACE); + int SpaceDimension = myGrid->getSpaceDimension(); + for (int axe = 0; axe < SpaceDimension; axe++) { + for (int num = 0; num < myGrid->getNumberOfNodes(); num++) { + double coordinate; + CPPUNIT_ASSERT_NO_THROW(coordinate = myGrid->getCoordinate(num + 1, axe + 1)); + //cout << "coordinate = " << coordinate << endl; + CPPUNIT_ASSERT(fabs(coordinate - coordinates[(num * SpaceDimension)+axe]) < 0.001); + } + } + + int nbTypesCell = myGrid->getNumberOfTypes(MED_CELL); + CPPUNIT_ASSERT(nbTypesCell == 1); + + const medGeometryElement* types; + CPPUNIT_ASSERT_NO_THROW(types = myGrid->getTypes(MED_CELL)); +#ifdef ENABLE_FORCED_FAILURES + // Compilation warning about GRID::getTypes(): + // "inline function + // `virtual const MED_EN::medGeometryElement* MEDMEM::GRID::getTypes(MED_EN::medEntityMesh) const' + // used but never defined". + // In MEDMEM_Grid.hxx: + // inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const; + // But implemented in MEDMEM_Grid.cxx: + // const MED_EN::medGeometryElement * GRID::getTypes(MED_EN::medEntityMesh entity) const + CPPUNIT_FAIL("Problem with GRID::getTypes() method implementation."); +#endif + CPPUNIT_ASSERT(types[0] == MED_QUAD4); + + int nbElem = 0; + CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid->getNumberOfElements(MED_CELL,types[0])); + CPPUNIT_ASSERT(nbElem); + + int nbNodes = myGrid->getNumberOfNodes(); + CPPUNIT_ASSERT(nbNodes); + + int ijkNode[3]; + int NodeNumber; + for (int nbNode = 1; nbNode <= nbNodes; nbNode++) { + CPPUNIT_ASSERT_NO_THROW(myGrid->getNodePosition(nbNode, ijkNode[0], ijkNode[1], ijkNode[2])); + CPPUNIT_ASSERT_NO_THROW(NodeNumber = myGrid->getNodeNumber(ijkNode[0], ijkNode[1], ijkNode[2])); + CPPUNIT_ASSERT(NodeNumber == nbNode); + } + + int nbCells = myGrid->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS); + CPPUNIT_ASSERT(nbCells); + + int ijkCell[3]; + int CellNumber; + for (int nbCell = 1; nbCell <= nbCells; nbCell++) { + CPPUNIT_ASSERT_NO_THROW(myGrid->getCellPosition(nbCell, ijkCell[0], ijkCell[1], ijkCell[2])); + CPPUNIT_ASSERT_NO_THROW(CellNumber = myGrid->getCellNumber(ijkCell[0], ijkCell[1], ijkCell[2])); + CPPUNIT_ASSERT(CellNumber == nbCell); + } + + int nbEdges = myGrid->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS); + CPPUNIT_ASSERT(nbEdges); + + int ijkAxisEdge[4]; + int EdgeNumber; + for (int nbEdge = 1; nbEdge <= nbEdges; nbEdge++) { + CPPUNIT_ASSERT_NO_THROW(myGrid->getEdgePosition(nbEdge, ijkAxisEdge[0], ijkAxisEdge[1], + ijkAxisEdge[2], ijkAxisEdge[3])); + CPPUNIT_ASSERT_NO_THROW(EdgeNumber = myGrid->getEdgeNumber(ijkAxisEdge[0], ijkAxisEdge[1], + ijkAxisEdge[2], ijkAxisEdge[3])); + CPPUNIT_ASSERT(EdgeNumber == nbEdge); + } + + int nbFaces = myGrid->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS); + CPPUNIT_ASSERT(nbFaces == 0); + +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: nbFaces == 0, but getFacePosition(AnyNumber, ...) - return position(i,j,k)"); +#endif + int ijkAxisFace[4]; + CPPUNIT_ASSERT_NO_THROW(myGrid->getFacePosition(6, ijkAxisFace[0], ijkAxisFace[1], + ijkAxisFace[2], ijkAxisFace[3])); + CPPUNIT_ASSERT(ijkAxisFace[0]); + CPPUNIT_ASSERT(ijkAxisFace[1]); + CPPUNIT_ASSERT(ijkAxisFace[2]); + + /*int FaceNumber; + for(int nbFace = 1; nbFace <= nbFaces; nbFace++) + { + CPPUNIT_ASSERT_NO_THROW( myGrid->getFacePosition(nbFace, ijkAxisFace[0], ijkAxisFace[1], + ijkAxisFace[2], ijkAxisFace[3])); + CPPUNIT_ASSERT_NO_THROW( EdgeNumber = myGrid->getEdgeNumber(ijkAxisFace[0], ijkAxisFace[1], + ijkAxisFace[2], ijkAxisFace[3])); + CPPUNIT_ASSERT(FaceNumber == nbFace); + }*/ + + bool existConnect = false; + CPPUNIT_ASSERT_NO_THROW(existConnect = myGrid->existConnectivity(MED_NODAL, MED_CELL)); + if (!existConnect) { + CPPUNIT_ASSERT_NO_THROW(myGrid->calculateConnectivity(MED_FULL_INTERLACE, MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT(myGrid->existConnectivity(MED_NODAL, MED_CELL)); + } + + const int* Connectivity; + const int* connectivity_index; + CPPUNIT_ASSERT_NO_THROW(Connectivity = myGrid->getConnectivity(MED_FULL_INTERLACE, MED_NODAL, + MED_CELL, types[0])); + CPPUNIT_ASSERT_NO_THROW(connectivity_index = myGrid->getConnectivityIndex(MED_NODAL, MED_CELL)); + cout << "Nodal connectivity" << endl; + for (int j = 0; j < nbElem; j++) { + cout << "Element "<< j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << Connectivity[k-1] << " "; + cout << endl; + } + + const int * ReverseNodalConnectivity; + const int * ReverseConnectivityIndex; + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = myGrid->getReverseConnectivity(MED_NODAL)); + CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndex = myGrid->getReverseConnectivityIndex(MED_NODAL)); + for (int i = 0; i < nbNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseConnectivityIndex[i]; j < ReverseConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + const int* myGlobalNbIdx; + CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = myGrid->getGlobalNumberingIndex(MED_CELL)); + for (int i = 0; i <= nbTypesCell; i++) { + if (i == nbTypesCell) { + CPPUNIT_ASSERT_THROW(myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]), MEDEXCEPTION); + break; + } + medGeometryElement aElem, geomPolyElem; + CPPUNIT_ASSERT_NO_THROW(aElem = myGrid->getElementType(MED_CELL, myGlobalNbIdx[i])); + CPPUNIT_ASSERT_NO_THROW(geomPolyElem = myGrid->getElementTypeWithPoly(MED_CELL, myGlobalNbIdx[i])); + CPPUNIT_ASSERT(types[0] == aElem); + CPPUNIT_ASSERT(geomPolyElem == aElem); + } + + CPPUNIT_ASSERT_NO_THROW(existConnect = myGrid->existConnectivity(MED_DESCENDING, MED_CELL)); + if (!existConnect) { + CPPUNIT_ASSERT_NO_THROW(myGrid->calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_CELL)); + CPPUNIT_ASSERT(myGrid->existConnectivity(MED_DESCENDING, MED_CELL)); + } + + const int* ConnectivityDes; + const int* connectivity_index_des; + CPPUNIT_ASSERT_NO_THROW(ConnectivityDes = myGrid->getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, + MED_CELL, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_NO_THROW(connectivity_index_des = + myGrid->getConnectivityIndex(MED_DESCENDING, MED_CELL)); + cout<<"Descending connectivity"<<endl; + for (int j = 0; j < nbElem; j++) { + cout << "Element "<< j+1 << " : "; + for (int k = connectivity_index_des[j]; k < connectivity_index_des[j+1]; k++) + cout << ConnectivityDes[k-1] << " "; + cout << endl; + } + + const int * ReverseDesConnectivity; + const int * ReverseConnectivityIndexDes; + CPPUNIT_ASSERT_NO_THROW(ReverseDesConnectivity = myGrid->getReverseConnectivity(MED_DESCENDING)); + CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndexDes = + myGrid->getReverseConnectivityIndex(MED_DESCENDING)); + for (int i = 0; i < nbNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseConnectivityIndexDes[i]; j < ReverseConnectivityIndexDes[i+1]; j++) + cout << ReverseDesConnectivity[j-1] << " "; + cout << endl; + } + + //TEST POLY + { + int nbPolytypes; + //test getNumberOfTypesWithPoly() - a grid has one type + CPPUNIT_ASSERT_NO_THROW(nbPolytypes = myGrid->getNumberOfTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT(nbPolytypes == 1 ); + + const MED_EN::medGeometryElement * PolyTypes, *Types; + CPPUNIT_ASSERT_NO_THROW(PolyTypes = myGrid->getTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(Types = myGrid->getTypes(MED_CELL)); + CPPUNIT_ASSERT_EQUAL(PolyTypes[nbPolytypes-1],Types[nbPolytypes-1]); + + for (int t = 0; t < nbPolytypes; t++) { + int nbElPoly, nbEl; + CPPUNIT_ASSERT_NO_THROW(nbElPoly = myGrid->getNumberOfElementsWithPoly(MED_CELL, PolyTypes[t])); + CPPUNIT_ASSERT_NO_THROW(nbEl = myGrid->getNumberOfElements(MED_CELL, PolyTypes[t])); + CPPUNIT_ASSERT(nbElPoly == nbEl); + } + } + } + + ////////////////////////////// + // test2 "MED_BODY_FITTED" // + ////////////////////////////// + { + MESH* myMesh1 = myMed->getMesh(mesh_names[1]); + myMesh1->read(); + + CPPUNIT_ASSERT(myMesh1 != NULL); + CPPUNIT_ASSERT(myMesh1->getIsAGrid()); + + GRID* myGrid1 = dynamic_cast<GRID*>(myMesh1); + CPPUNIT_ASSERT(myGrid1); + + int I, J, K; + CPPUNIT_ASSERT_NO_THROW(I = myGrid1->getArrayLength(1)); + CPPUNIT_ASSERT_NO_THROW(J = myGrid1->getArrayLength(2)); + CPPUNIT_ASSERT_NO_THROW(K = myGrid1->getArrayLength(3)); + + CPPUNIT_ASSERT(I == 2); + CPPUNIT_ASSERT(J == 2); + + med_grid_type grid_type = myGrid1->getGridType(); + CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_BODY_FITTED); + + int nbTypesCell = myGrid1->getNumberOfTypes(MED_CELL); + CPPUNIT_ASSERT(nbTypesCell == 1); + + const medGeometryElement* types1; + CPPUNIT_ASSERT_NO_THROW( types1 = myGrid1->getTypes(MED_CELL) ); + CPPUNIT_ASSERT( types1[0] == MED_QUAD4); + + int nbElem; + CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid1->getNumberOfElements(MED_CELL, types1[0])); + CPPUNIT_ASSERT(nbElem); + + const int* BodyConnectivity; + const int* body_connectivity_index; + int ijkNodeBody[3]; + CPPUNIT_ASSERT_NO_THROW(BodyConnectivity = myGrid1->getConnectivity(MED_FULL_INTERLACE, MED_NODAL, + MED_CELL, types1[0])); + CPPUNIT_ASSERT_NO_THROW(body_connectivity_index = myGrid1->getConnectivityIndex(MED_NODAL, MED_CELL)); + cout<<"Nodal connectivity"<<endl; + for (int j = 0; j < nbElem; j++) { + cout << "Element "<< j+1 << " : "; + for (int k = body_connectivity_index[j]; k < body_connectivity_index[j+1]; k++){ + CPPUNIT_ASSERT_NO_THROW(myGrid1->getNodePosition(BodyConnectivity[k-1], ijkNodeBody[0], + ijkNodeBody[1], ijkNodeBody[2])); + cout << BodyConnectivity[k-1] << " "; + } + cout << endl; + } + } + + /////////////////////////////////////////////////// + // test3 "maa1" which in fact is not a pure GRID // + /////////////////////////////////////////////////// + { + MESH* myMesh2 = NULL; + + myMesh2 = myMed->getMesh(mesh_names[2]); + myMesh2->read(); + + CPPUNIT_ASSERT(myMesh2 != NULL); + CPPUNIT_ASSERT(!(myMesh2->getIsAGrid())); + } + + delete myMed; + + //////////////////////////// + // test4 create new GRID // + //////////////////////////// + + // Default constructor and destructor + { + GRID* myGrid2 = new GRID(); + CPPUNIT_ASSERT(myGrid2->getIsAGrid()); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN); + CPPUNIT_ASSERT(!myGrid2->getArrayLength(1)); + CPPUNIT_ASSERT(!myGrid2->getArrayLength(2)); + CPPUNIT_ASSERT(!myGrid2->getArrayLength(3)); + delete myGrid2; + } + + // Constructor with grid type, setGridType() + { + GRID* myGrid2 = new GRID(MED_POLAR); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_POLAR); + myGrid2->setGridType(MED_CARTESIAN); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN); + delete myGrid2; + } + + // Constructor with coordinate values, getArrayValue(), init() + { + vector<vector<double> > xyz; + const int nbCoords = 3; + xyz.resize(nbCoords); + for ( int i = 0; i < nbCoords; i++ ) + { + xyz[i].resize(i + 2); + for ( int j = 0; j < i + 2; j++ ) + xyz[i][j] = j; + } + vector<string> Coord_Names; + Coord_Names.resize(nbCoords); + Coord_Names[0] = "X"; + Coord_Names[1] = "Y"; + Coord_Names[2] = "Z"; + + vector<string> Coord_Units; + Coord_Units.resize(nbCoords); + for(int i = 0; i < 3; i++) + Coord_Units[i] = "cm"; + + GRID* myGrid2; + + try{ + myGrid2 = new GRID(xyz, Coord_Names, Coord_Units, MED_CARTESIAN); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // testing getCoordinateptr() and fillCoordinates() + // We fill a map of all possible coordinate triples. + // After iteration through all coordinates, this map should contain only "true" as data. + // "true" in some map element during iteration means duplicated node position. + // "false" in some map element after iteration means empty node position. + map<int, bool> found; + for ( int i1 = 0; i1 < xyz[0].size(); i1++ ) + for ( int i2 = 0; i2 < xyz[1].size(); i2++ ) + for ( int i3 = 0; i3 < xyz[2].size(); i3++ ) + found[int(xyz[0][i1] * 100 + xyz[1][i2] * 10 + xyz[2][i3])] = false; + + COORDINATE* coords = (COORDINATE*)myGrid2->getCoordinateptr(); + CPPUNIT_ASSERT(coords); + for (int num = 0; num < myGrid2->getNumberOfNodes(); num++) { + int x = int(coords->getCoordinate(num + 1, 1)); + int y = int(coords->getCoordinate(num + 1, 2)); + int z = int(coords->getCoordinate(num + 1, 3)); + CPPUNIT_ASSERT(!found[x * 100 + y * 10 + z]); + found[x * 100 + y * 10 + z] = true; + } + + for ( map<int, bool>::iterator it = found.begin(); it != found.end(); it++ ) + CPPUNIT_ASSERT((*it).second); + + // Testing fillConnectivity() and getConnectivityptr() + // Basic testing: presence of connectivity arrays, element types and number of elements + CONNECTIVITY* conn = (CONNECTIVITY*)myGrid2->getConnectivityptr(); + CPPUNIT_ASSERT(conn); + bool hasFaces = myGrid2->getArrayLength(3), hasEdges = myGrid2->getArrayLength(2); + medGeometryElement aCellGeometry; + if (hasFaces) aCellGeometry = MED_HEXA8; + else if (hasEdges) aCellGeometry = MED_QUAD4; + else aCellGeometry = MED_SEG2; + CPPUNIT_ASSERT(conn->getElementType(MED_CELL, 1) == aCellGeometry); + CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT(conn->existConnectivity(MED_DESCENDING, MED_CELL)); + //test getCellsTypes + CELLMODEL* cellmodel = (CELLMODEL*)myGrid2->getCellsTypes(MED_CELL); + CPPUNIT_ASSERT(cellmodel); + + int nbCells, nbFaces, nbEdges; + + int iLen = myGrid2->getArrayLength(1); + int jLen = myGrid2->getArrayLength(2); + int kLen = myGrid2->getArrayLength(3); + int iLenMin1 = myGrid2->getArrayLength(1)-1; + int jLenMin1 = myGrid2->getArrayLength(2)-1; + int kLenMin1 = myGrid2->getArrayLength(3)-1; + const int* aCellCount = conn->getGlobalNumberingIndex(MED_CELL); + nbCells = iLenMin1 * jLenMin1 * kLenMin1; + CPPUNIT_ASSERT(aCellCount[1] - 1 == nbCells); + + if (hasFaces){ + CPPUNIT_ASSERT(conn->getElementType(MED_FACE, 1) == MED_QUAD4); + nbFaces = iLen * jLenMin1 * kLenMin1; + nbFaces += jLen * kLenMin1 * iLenMin1; + nbFaces += kLen * iLenMin1 * jLenMin1; + const int* aFaceCount = conn->getGlobalNumberingIndex(MED_FACE); + CPPUNIT_ASSERT(aFaceCount[1] - 1 == nbFaces); + CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_FACE)); + //test getCellsTypes + CELLMODEL* cellmodelF = (CELLMODEL*)myGrid2->getCellsTypes(MED_FACE); + CPPUNIT_ASSERT(cellmodelF); + } + if (hasEdges){ + CPPUNIT_ASSERT(conn->getElementType(MED_EDGE, 1) == MED_SEG2); + if (kLen) { // 3d grid + nbEdges = iLenMin1 * jLen * kLen; + nbEdges += jLenMin1 * kLen * iLen; + nbEdges += kLenMin1 * iLen * jLen; + } + else if (jLen) { // 2d + nbEdges = iLenMin1 * jLen; + nbEdges += jLenMin1 * iLen; + } + const int* anEdgeCount = conn->getGlobalNumberingIndex(MED_EDGE); + CPPUNIT_ASSERT(anEdgeCount[1] - 1 == nbEdges); + CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_EDGE)); + //test getCellsTypes + CELLMODEL* cellmodelE = (CELLMODEL*)myGrid2->getCellsTypes(MED_EDGE); + CPPUNIT_ASSERT(cellmodelE); + + } + + // Testing getArrayValue() + for ( int ii = 1; ii <= nbCoords; ii++ ) + for ( int jj = 0; jj < ii + 1; jj++ ) + CPPUNIT_ASSERT(myGrid2->getArrayValue(ii, jj) == xyz[ii - 1][jj]); + + CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(nbCoords + 1, 0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(1, myGrid2->getArrayLength(1) + 1), MEDEXCEPTION); + myGrid2->setGridType(MED_POLAR); + + //testing read/write functions + + // add new driver + int idGridV21; + + try + { + idGridV21 = myGrid2->addDriver(MED_DRIVER,filenameout21); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // write this driver to file as an unstructured mesh + CPPUNIT_ASSERT_NO_THROW(myGrid2->writeUnstructured(idGridV21)); + + GRID* myGrid3 = new GRID(); + // add new driver for myGrid3 + int driver; + CPPUNIT_ASSERT_NO_THROW(driver = myGrid3->addDriver(MED_DRIVER, filenameout21)); + +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) ? "The mesh dimension |-1| seems to be incorrect for the mesh : |Default Mesh Name|" + CPPUNIT_ASSERT_NO_THROW(myGrid3->read(driver)); + + // Testing getArrayValue() + for ( int ii = 1; ii <= nbCoords; ii++ ) + for ( int jj = 0; jj < ii + 1; jj++ ) + CPPUNIT_ASSERT(myGrid3->getArrayValue(ii, jj) == xyz[ii - 1][jj]); + + CPPUNIT_ASSERT(myGrid3->getGridType() == MED_POLAR); +#endif + + delete myGrid3; + + //test init() + CPPUNIT_ASSERT_NO_THROW(myGrid2->init()); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN); + CPPUNIT_ASSERT(myGrid2->getArrayLength(1) == 0); + CPPUNIT_ASSERT(myGrid2->getArrayLength(2) == 0); + CPPUNIT_ASSERT(myGrid2->getArrayLength(3) == 0); +#ifdef ENABLE_FAULTS + // (BUG) Segmentation Fault + myGrid2->makeUnstructured(); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR:makeUnstructured() - there is no check if grid is empty or not"); +#endif + + delete myGrid2; + } + +#ifdef ENABLE_FORCED_FAILURES + { + GRID* myGrid2; + // ? (BUG) ? MED Exception in /dn20/salome/jfa/V3/SRC/MED_SRC/src/MEDMEM/MEDMEM_MedM + //eshDriver21.cxx [430] : MED_MESH_RDONLY_DRIVER21::getCOORDINATE() : The number + //of nodes |0| seems to be incorrect for the mesh : |bodyfitted| + CPPUNIT_ASSERT_NO_THROW(myGrid2 = new GRID(MED_DRIVER, filename, mesh_names[1])); + + // Check if something has been read - full mesh data testing is above + CPPUNIT_ASSERT(myGrid2->getSpaceDimension()); + CPPUNIT_ASSERT(myGrid2->getNumberOfNodes()); + CPPUNIT_ASSERT(myGrid2->getNumberOfTypes(MED_CELL) == 1); + const medGeometryElement* types2; + CPPUNIT_ASSERT_NO_THROW(types2 = myGrid2->getTypes(MED_CELL)); + int nbElem; + CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid2->getNumberOfElements(MED_CELL,types2[0])); + CPPUNIT_ASSERT(nbElem); + delete myGrid2; + } +#endif + + { + GRID* myGrid4 = new GRID(); + filename = datadir + "/MedFiles/pointe.med"; + myGrid4->setName("maa1"); + MED_MESH_RDONLY_DRIVER myMeshDriver(filename, myGrid4); + myMeshDriver.setMeshName("maa1"); + + // add new driver for myGrid4 + int driver; + CPPUNIT_ASSERT_NO_THROW(driver = myGrid4->addDriver(myMeshDriver)); + + // ??? ERROR:myGrid4->fillMeshAfterRead()- this method is incomplete: + // currently it only resets _is_coordinates_filled and _is_connectivity_filled + // flags that leads to grid reconstruction + + // MED Exception : MED_MESH_RDONLY_DRIVER21::getGRID() : The number + // of nodes |-1| seems to be incorrect for the mesh : |maa1| + // But this exception seems to be correct reaction on attempt + // to read a grid from a file, which does not contain it. + CPPUNIT_ASSERT_THROW(myGrid4->read(driver), MEDEXCEPTION); + //CPPUNIT_ASSERT_NO_THROW(myGrid4->read(driver)); + /*CPPUNIT_ASSERT(myGrid4->getArrayLength(1) == 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(2) == 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(3) == 0); + myGrid4->fillMeshAfterRead(); + CPPUNIT_ASSERT(myGrid4->getArrayLength(1) != 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(2) != 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(3) != 0);*/ + + delete myGrid4; + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Grid_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Grid_fault.cxx new file mode 100644 index 000000000..a38538280 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Grid_fault.cxx @@ -0,0 +1,701 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Grid.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_MedMedDriver.hxx" +#include "MEDMEM_MedMeshDriver.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + + +/*! + * Check methods (44), defined in MEDMEM_Grid.hxx: + * class GRID: public MESH { + * (+) GRID(); + * (+) GRID(const MED_EN::med_grid_type type); + * (BUG:operator=() not implemented but init() not called) GRID(const GRID &m); + * (+) GRID(driverTypes driverType, const string & fileName="",const string & meshName=""); + * (+) GRID(const std::vector<std::vector<double> >& xyz_array, + * const std::vector<std::string>& coord_name, + * const std::vector<std::string>& coord_unit, + * const MED_EN::med_grid_type type=MED_EN::MED_CARTESIAN); + * (NOT IMPLEMENTED) GRID & operator=(const GRID &m); + * (+) virtual ~GRID(); + * (+) virtual void init(); + * (tested together with getCoordinateptr() as it is called + * internally from there first of all. + * Moreover, fillCoordinates should be made private to avoid + * ambiguity druing in GRID class usage.) void fillCoordinates() const; + * (tested together with getConnectivityptr()) void fillConnectivity() const; + * (+) inline void makeUnstructured();//fill coordinates and connectivity of MESH + * (+) void fillMeshAfterRead(); + * (+) void writeUnstructured(int index=0, const string & driverName = ""); + * (+) void read(int index=0); + * (+) inline int getNodeNumber(const int i, const int j=0, const int k=0) const; + * (+) inline int getCellNumber(const int i, const int j=0, const int k=0) const; + * (+) int getEdgeNumber + * (const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION); + * (+) int getFaceNumber + * (const int Axis, const int i, const int j=0, const int k=0) const throw (MEDEXCEPTION); + * (+) void getNodePosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) void getCellPosition(const int Number, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) void getEdgePosition + * (const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) void getFacePosition + * (const int Number, int& Axis, int& i, int& j, int& k) const throw (MEDEXCEPTION); + * (+) inline MED_EN::med_grid_type getGridType() const; + * (+) int getArrayLength(const int Axis) const throw (MEDEXCEPTION); + * (+) const double getArrayValue (const int Axis, const int i) const throw (MEDEXCEPTION); + * (+) inline const COORDINATE * getCoordinateptr() const; + * (+) inline const double * getCoordinates(MED_EN::medModeSwitch Mode) const; + * (+) inline const double getCoordinate(int Number,int Axis) const; + * (+) inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const; + * (+) inline int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const; + * (+) MED_EN::medGeometryElement * getTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) inline const CELLMODEL * getCellsTypes(MED_EN::medEntityMesh Entity) const; + * (+) const int * getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const; + * (+) inline int getNumberOfElements + * (MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * (+) inline int getNumberOfElementsWithPoly + * (MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * (+) inline bool existConnectivity + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline MED_EN::medGeometryElement getElementType + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) inline MED_EN::medGeometryElement getElementTypeWithPoly + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) inline void calculateConnectivity(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline const CONNECTIVITY* getConnectivityptr() const; + * (+) inline const int * getConnectivity + * (MED_EN::medModeSwitch Mode, MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type) const; + * (+) inline const int * getConnectivityIndex(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline const int * getReverseConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) inline const int * getReverseConnectivityIndex(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) inline void setGridType(MED_EN::med_grid_type gridType); + * } + */ +void MEDMEMTest_testGrid() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/test19.med" ; + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filenameout21 = tmp_dir + "/myGridWrite_grid21.med"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filenameout21); + + // Remove file in advance to ensure it does not exist at the moment of writing, + // because files are not removed by the MEDMEMTest_TmpFilesRemover in case of + // Segmentation Fault (in previous tests execution). + { + MEDMEMTest_TmpFilesRemover aRemover1; + aRemover1.Register(filenameout21); + } + + MED * myMed = new MED() ; + MED_MED_RDONLY_DRIVER myMeshDriver (filename, myMed); + myMeshDriver.open(); + myMeshDriver.readFileStruct(); + myMeshDriver.close(); + + int nbMeshes = myMed->getNumberOfMeshes(); + CPPUNIT_ASSERT(nbMeshes); + + deque<string> mesh_names = myMed->getMeshNames(); + CPPUNIT_ASSERT(mesh_names.size() != 0); + + ////////////////////////////// + // test1 "CARTESIAN GRID" // + ////////////////////////////// + { + MESH* myMesh = myMed->getMesh(mesh_names[0]); + myMesh->read(); + + CPPUNIT_ASSERT(myMesh != NULL); + CPPUNIT_ASSERT(myMesh->getIsAGrid()); + + GRID* myGrid = dynamic_cast<GRID*>(myMesh); + CPPUNIT_ASSERT(myGrid); + + CPPUNIT_ASSERT_THROW(myGrid->getArrayLength(0), MEDEXCEPTION); + + int I, J, K; + CPPUNIT_ASSERT_NO_THROW(I = myGrid->getArrayLength(1)); + CPPUNIT_ASSERT_NO_THROW(J = myGrid->getArrayLength(2)); + CPPUNIT_ASSERT_NO_THROW(K = myGrid->getArrayLength(3)); + + CPPUNIT_ASSERT(I); + CPPUNIT_ASSERT(J); + + med_grid_type grid_type = myGrid->getGridType(); + CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_CARTESIAN); + + const double * coordinates = myGrid->getCoordinates(MED_FULL_INTERLACE); + int SpaceDimension = myGrid->getSpaceDimension(); + for (int axe = 0; axe < SpaceDimension; axe++) { + for (int num = 0; num < myGrid->getNumberOfNodes(); num++) { + double coordinate; + CPPUNIT_ASSERT_NO_THROW(coordinate = myGrid->getCoordinate(num + 1, axe + 1)); + //cout << "coordinate = " << coordinate << endl; + CPPUNIT_ASSERT(fabs(coordinate - coordinates[(num * SpaceDimension)+axe]) < 0.001); + } + } + + int nbTypesCell = myGrid->getNumberOfTypes(MED_CELL); + CPPUNIT_ASSERT(nbTypesCell == 1); + + const medGeometryElement* types; + CPPUNIT_ASSERT_NO_THROW(types = myGrid->getTypes(MED_CELL)); +#ifdef ENABLE_FORCED_FAILURES + // Compilation warning about GRID::getTypes(): + // "inline function + // `virtual const MED_EN::medGeometryElement* MEDMEM::GRID::getTypes(MED_EN::medEntityMesh) const' + // used but never defined". + // In MEDMEM_Grid.hxx: + // inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const; + // But implemented in MEDMEM_Grid.cxx: + // const MED_EN::medGeometryElement * GRID::getTypes(MED_EN::medEntityMesh entity) const + CPPUNIT_FAIL("Problem with GRID::getTypes() method implementation."); +#endif + CPPUNIT_ASSERT(types[0] == MED_QUAD4); + + int nbElem = 0; + CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid->getNumberOfElements(MED_CELL,types[0])); + CPPUNIT_ASSERT(nbElem); + + int nbNodes = myGrid->getNumberOfNodes(); + CPPUNIT_ASSERT(nbNodes); + + int ijkNode[3]; + int NodeNumber; + for (int nbNode = 1; nbNode <= nbNodes; nbNode++) { + CPPUNIT_ASSERT_NO_THROW(myGrid->getNodePosition(nbNode, ijkNode[0], ijkNode[1], ijkNode[2])); + CPPUNIT_ASSERT_NO_THROW(NodeNumber = myGrid->getNodeNumber(ijkNode[0], ijkNode[1], ijkNode[2])); + CPPUNIT_ASSERT(NodeNumber == nbNode); + } + + int nbCells = myGrid->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS); + CPPUNIT_ASSERT(nbCells); + + int ijkCell[3]; + int CellNumber; + for (int nbCell = 1; nbCell <= nbCells; nbCell++) { + CPPUNIT_ASSERT_NO_THROW(myGrid->getCellPosition(nbCell, ijkCell[0], ijkCell[1], ijkCell[2])); + CPPUNIT_ASSERT_NO_THROW(CellNumber = myGrid->getCellNumber(ijkCell[0], ijkCell[1], ijkCell[2])); + CPPUNIT_ASSERT(CellNumber == nbCell); + } + + int nbEdges = myGrid->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS); + CPPUNIT_ASSERT(nbEdges); + + int ijkAxisEdge[4]; + int EdgeNumber; + for (int nbEdge = 1; nbEdge <= nbEdges; nbEdge++) { + CPPUNIT_ASSERT_NO_THROW(myGrid->getEdgePosition(nbEdge, ijkAxisEdge[0], ijkAxisEdge[1], + ijkAxisEdge[2], ijkAxisEdge[3])); + CPPUNIT_ASSERT_NO_THROW(EdgeNumber = myGrid->getEdgeNumber(ijkAxisEdge[0], ijkAxisEdge[1], + ijkAxisEdge[2], ijkAxisEdge[3])); + CPPUNIT_ASSERT(EdgeNumber == nbEdge); + } + + int nbFaces = myGrid->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS); + CPPUNIT_ASSERT(nbFaces == 0); + +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: nbFaces == 0, but getFacePosition(AnyNumber, ...) - return position(i,j,k)"); +#endif + int ijkAxisFace[4]; + CPPUNIT_ASSERT_NO_THROW(myGrid->getFacePosition(6, ijkAxisFace[0], ijkAxisFace[1], + ijkAxisFace[2], ijkAxisFace[3])); + CPPUNIT_ASSERT(ijkAxisFace[0]); + CPPUNIT_ASSERT(ijkAxisFace[1]); + CPPUNIT_ASSERT(ijkAxisFace[2]); + + /*int FaceNumber; + for(int nbFace = 1; nbFace <= nbFaces; nbFace++) + { + CPPUNIT_ASSERT_NO_THROW( myGrid->getFacePosition(nbFace, ijkAxisFace[0], ijkAxisFace[1], + ijkAxisFace[2], ijkAxisFace[3])); + CPPUNIT_ASSERT_NO_THROW( EdgeNumber = myGrid->getEdgeNumber(ijkAxisFace[0], ijkAxisFace[1], + ijkAxisFace[2], ijkAxisFace[3])); + CPPUNIT_ASSERT(FaceNumber == nbFace); + }*/ + + bool existConnect = false; + CPPUNIT_ASSERT_NO_THROW(existConnect = myGrid->existConnectivity(MED_NODAL, MED_CELL)); + if (!existConnect) { + CPPUNIT_ASSERT_NO_THROW(myGrid->calculateConnectivity(MED_FULL_INTERLACE, MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT(myGrid->existConnectivity(MED_NODAL, MED_CELL)); + } + + const int* Connectivity; + const int* connectivity_index; + CPPUNIT_ASSERT_NO_THROW(Connectivity = myGrid->getConnectivity(MED_FULL_INTERLACE, MED_NODAL, + MED_CELL, types[0])); + CPPUNIT_ASSERT_NO_THROW(connectivity_index = myGrid->getConnectivityIndex(MED_NODAL, MED_CELL)); + cout << "Nodal connectivity" << endl; + for (int j = 0; j < nbElem; j++) { + cout << "Element "<< j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << Connectivity[k-1] << " "; + cout << endl; + } + + const int * ReverseNodalConnectivity; + const int * ReverseConnectivityIndex; + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = myGrid->getReverseConnectivity(MED_NODAL)); + CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndex = myGrid->getReverseConnectivityIndex(MED_NODAL)); + for (int i = 0; i < nbNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseConnectivityIndex[i]; j < ReverseConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + const int* myGlobalNbIdx; + CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = myGrid->getGlobalNumberingIndex(MED_CELL)); + for (int i = 0; i <= nbTypesCell; i++) { + if (i == nbTypesCell) { + CPPUNIT_ASSERT_THROW(myGrid->getElementType(MED_CELL, myGlobalNbIdx[i]), MEDEXCEPTION); + break; + } + medGeometryElement aElem, geomPolyElem; + CPPUNIT_ASSERT_NO_THROW(aElem = myGrid->getElementType(MED_CELL, myGlobalNbIdx[i])); + CPPUNIT_ASSERT_NO_THROW(geomPolyElem = myGrid->getElementTypeWithPoly(MED_CELL, myGlobalNbIdx[i])); + CPPUNIT_ASSERT(types[0] == aElem); + CPPUNIT_ASSERT(geomPolyElem == aElem); + } + + CPPUNIT_ASSERT_NO_THROW(existConnect = myGrid->existConnectivity(MED_DESCENDING, MED_CELL)); + if (!existConnect) { + CPPUNIT_ASSERT_NO_THROW(myGrid->calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_CELL)); + CPPUNIT_ASSERT(myGrid->existConnectivity(MED_DESCENDING, MED_CELL)); + } + + const int* ConnectivityDes; + const int* connectivity_index_des; + CPPUNIT_ASSERT_NO_THROW(ConnectivityDes = myGrid->getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, + MED_CELL, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_NO_THROW(connectivity_index_des = + myGrid->getConnectivityIndex(MED_DESCENDING, MED_CELL)); + cout<<"Descending connectivity"<<endl; + for (int j = 0; j < nbElem; j++) { + cout << "Element "<< j+1 << " : "; + for (int k = connectivity_index_des[j]; k < connectivity_index_des[j+1]; k++) + cout << ConnectivityDes[k-1] << " "; + cout << endl; + } + + const int * ReverseDesConnectivity; + const int * ReverseConnectivityIndexDes; + CPPUNIT_ASSERT_NO_THROW(ReverseDesConnectivity = myGrid->getReverseConnectivity(MED_DESCENDING)); + CPPUNIT_ASSERT_NO_THROW(ReverseConnectivityIndexDes = + myGrid->getReverseConnectivityIndex(MED_DESCENDING)); + for (int i = 0; i < nbNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseConnectivityIndexDes[i]; j < ReverseConnectivityIndexDes[i+1]; j++) + cout << ReverseDesConnectivity[j-1] << " "; + cout << endl; + } + + //TEST POLY + { + int nbPolytypes; + //test getNumberOfTypesWithPoly() - a grid has one type + CPPUNIT_ASSERT_NO_THROW(nbPolytypes = myGrid->getNumberOfTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT(nbPolytypes == 1 ); + + const MED_EN::medGeometryElement * PolyTypes, *Types; + CPPUNIT_ASSERT_NO_THROW(PolyTypes = myGrid->getTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(Types = myGrid->getTypes(MED_CELL)); + CPPUNIT_ASSERT_EQUAL(PolyTypes[nbPolytypes-1],Types[nbPolytypes-1]); + + for (int t = 0; t < nbPolytypes; t++) { + int nbElPoly, nbEl; + CPPUNIT_ASSERT_NO_THROW(nbElPoly = myGrid->getNumberOfElementsWithPoly(MED_CELL, PolyTypes[t])); + CPPUNIT_ASSERT_NO_THROW(nbEl = myGrid->getNumberOfElements(MED_CELL, PolyTypes[t])); + CPPUNIT_ASSERT(nbElPoly == nbEl); + } + } + } + + ////////////////////////////// + // test2 "MED_BODY_FITTED" // + ////////////////////////////// + { + MESH* myMesh1 = myMed->getMesh(mesh_names[1]); + myMesh1->read(); + + CPPUNIT_ASSERT(myMesh1 != NULL); + CPPUNIT_ASSERT(myMesh1->getIsAGrid()); + + GRID* myGrid1 = dynamic_cast<GRID*>(myMesh1); + CPPUNIT_ASSERT(myGrid1); + + int I, J, K; + CPPUNIT_ASSERT_NO_THROW(I = myGrid1->getArrayLength(1)); + CPPUNIT_ASSERT_NO_THROW(J = myGrid1->getArrayLength(2)); + CPPUNIT_ASSERT_NO_THROW(K = myGrid1->getArrayLength(3)); + + CPPUNIT_ASSERT(I == 2); + CPPUNIT_ASSERT(J == 2); + + med_grid_type grid_type = myGrid1->getGridType(); + CPPUNIT_ASSERT_MESSAGE("Wrong grid type", grid_type == MED_BODY_FITTED); + + int nbTypesCell = myGrid1->getNumberOfTypes(MED_CELL); + CPPUNIT_ASSERT(nbTypesCell == 1); + + const medGeometryElement* types1; + CPPUNIT_ASSERT_NO_THROW( types1 = myGrid1->getTypes(MED_CELL) ); + CPPUNIT_ASSERT( types1[0] == MED_QUAD4); + + int nbElem; + CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid1->getNumberOfElements(MED_CELL, types1[0])); + CPPUNIT_ASSERT(nbElem); + + const int* BodyConnectivity; + const int* body_connectivity_index; + int ijkNodeBody[3]; + CPPUNIT_ASSERT_NO_THROW(BodyConnectivity = myGrid1->getConnectivity(MED_FULL_INTERLACE, MED_NODAL, + MED_CELL, types1[0])); + CPPUNIT_ASSERT_NO_THROW(body_connectivity_index = myGrid1->getConnectivityIndex(MED_NODAL, MED_CELL)); + cout<<"Nodal connectivity"<<endl; + for (int j = 0; j < nbElem; j++) { + cout << "Element "<< j+1 << " : "; + for (int k = body_connectivity_index[j]; k < body_connectivity_index[j+1]; k++){ + CPPUNIT_ASSERT_NO_THROW(myGrid1->getNodePosition(BodyConnectivity[k-1], ijkNodeBody[0], + ijkNodeBody[1], ijkNodeBody[2])); + cout << BodyConnectivity[k-1] << " "; + } + cout << endl; + } + } + + /////////////////////////////////////////////////// + // test3 "maa1" which in fact is not a pure GRID // + /////////////////////////////////////////////////// + { + MESH* myMesh2 = NULL; + + myMesh2 = myMed->getMesh(mesh_names[2]); + myMesh2->read(); + + CPPUNIT_ASSERT(myMesh2 != NULL); + CPPUNIT_ASSERT(!(myMesh2->getIsAGrid())); + } + + delete myMed; + + //////////////////////////// + // test4 create new GRID // + //////////////////////////// + + // Default constructor and destructor + { + GRID* myGrid2 = new GRID(); + CPPUNIT_ASSERT(myGrid2->getIsAGrid()); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN); + CPPUNIT_ASSERT(!myGrid2->getArrayLength(1)); + CPPUNIT_ASSERT(!myGrid2->getArrayLength(2)); + CPPUNIT_ASSERT(!myGrid2->getArrayLength(3)); + delete myGrid2; + } + + // Constructor with grid type, setGridType() + { + GRID* myGrid2 = new GRID(MED_POLAR); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_POLAR); + myGrid2->setGridType(MED_CARTESIAN); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN); + delete myGrid2; + } + + // Constructor with coordinate values, getArrayValue(), init() + { + vector<vector<double> > xyz; + const int nbCoords = 3; + xyz.resize(nbCoords); + for ( int i = 0; i < nbCoords; i++ ) + { + xyz[i].resize(i + 2); + for ( int j = 0; j < i + 2; j++ ) + xyz[i][j] = j; + } + vector<string> Coord_Names; + Coord_Names.resize(nbCoords); + Coord_Names[0] = "X"; + Coord_Names[1] = "Y"; + Coord_Names[2] = "Z"; + + vector<string> Coord_Units; + Coord_Units.resize(nbCoords); + for(int i = 0; i < 3; i++) + Coord_Units[i] = "cm"; + + GRID* myGrid2; + + try{ + myGrid2 = new GRID(xyz, Coord_Names, Coord_Units, MED_CARTESIAN); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // testing getCoordinateptr() and fillCoordinates() + // We fill a map of all possible coordinate triples. + // After iteration through all coordinates, this map should contain only "true" as data. + // "true" in some map element during iteration means duplicated node position. + // "false" in some map element after iteration means empty node position. + map<int, bool> found; + for ( int i1 = 0; i1 < xyz[0].size(); i1++ ) + for ( int i2 = 0; i2 < xyz[1].size(); i2++ ) + for ( int i3 = 0; i3 < xyz[2].size(); i3++ ) + found[int(xyz[0][i1] * 100 + xyz[1][i2] * 10 + xyz[2][i3])] = false; + + COORDINATE* coords = (COORDINATE*)myGrid2->getCoordinateptr(); + CPPUNIT_ASSERT(coords); + for (int num = 0; num < myGrid2->getNumberOfNodes(); num++) { + int x = int(coords->getCoordinate(num + 1, 1)); + int y = int(coords->getCoordinate(num + 1, 2)); + int z = int(coords->getCoordinate(num + 1, 3)); + CPPUNIT_ASSERT(!found[x * 100 + y * 10 + z]); + found[x * 100 + y * 10 + z] = true; + } + + for ( map<int, bool>::iterator it = found.begin(); it != found.end(); it++ ) + CPPUNIT_ASSERT((*it).second); + + // Testing fillConnectivity() and getConnectivityptr() + // Basic testing: presence of connectivity arrays, element types and number of elements + CONNECTIVITY* conn = (CONNECTIVITY*)myGrid2->getConnectivityptr(); + CPPUNIT_ASSERT(conn); + bool hasFaces = myGrid2->getArrayLength(3), hasEdges = myGrid2->getArrayLength(2); + medGeometryElement aCellGeometry; + if (hasFaces) aCellGeometry = MED_HEXA8; + else if (hasEdges) aCellGeometry = MED_QUAD4; + else aCellGeometry = MED_SEG2; + CPPUNIT_ASSERT(conn->getElementType(MED_CELL, 1) == aCellGeometry); + CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT(conn->existConnectivity(MED_DESCENDING, MED_CELL)); + //test getCellsTypes + CELLMODEL* cellmodel = (CELLMODEL*)myGrid2->getCellsTypes(MED_CELL); + CPPUNIT_ASSERT(cellmodel); + + int nbCells, nbFaces, nbEdges; + + int iLen = myGrid2->getArrayLength(1); + int jLen = myGrid2->getArrayLength(2); + int kLen = myGrid2->getArrayLength(3); + int iLenMin1 = myGrid2->getArrayLength(1)-1; + int jLenMin1 = myGrid2->getArrayLength(2)-1; + int kLenMin1 = myGrid2->getArrayLength(3)-1; + const int* aCellCount = conn->getGlobalNumberingIndex(MED_CELL); + nbCells = iLenMin1 * jLenMin1 * kLenMin1; + CPPUNIT_ASSERT(aCellCount[1] - 1 == nbCells); + + if (hasFaces){ + CPPUNIT_ASSERT(conn->getElementType(MED_FACE, 1) == MED_QUAD4); + nbFaces = iLen * jLenMin1 * kLenMin1; + nbFaces += jLen * kLenMin1 * iLenMin1; + nbFaces += kLen * iLenMin1 * jLenMin1; + const int* aFaceCount = conn->getGlobalNumberingIndex(MED_FACE); + CPPUNIT_ASSERT(aFaceCount[1] - 1 == nbFaces); + CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_FACE)); + //test getCellsTypes + CELLMODEL* cellmodelF = (CELLMODEL*)myGrid2->getCellsTypes(MED_FACE); + CPPUNIT_ASSERT(cellmodelF); + } + if (hasEdges){ + CPPUNIT_ASSERT(conn->getElementType(MED_EDGE, 1) == MED_SEG2); + if (kLen) { // 3d grid + nbEdges = iLenMin1 * jLen * kLen; + nbEdges += jLenMin1 * kLen * iLen; + nbEdges += kLenMin1 * iLen * jLen; + } + else if (jLen) { // 2d + nbEdges = iLenMin1 * jLen; + nbEdges += jLenMin1 * iLen; + } + const int* anEdgeCount = conn->getGlobalNumberingIndex(MED_EDGE); + CPPUNIT_ASSERT(anEdgeCount[1] - 1 == nbEdges); + CPPUNIT_ASSERT(conn->existConnectivity(MED_NODAL, MED_EDGE)); + //test getCellsTypes + CELLMODEL* cellmodelE = (CELLMODEL*)myGrid2->getCellsTypes(MED_EDGE); + CPPUNIT_ASSERT(cellmodelE); + + } + + // Testing getArrayValue() + for ( int ii = 1; ii <= nbCoords; ii++ ) + for ( int jj = 0; jj < ii + 1; jj++ ) + CPPUNIT_ASSERT(myGrid2->getArrayValue(ii, jj) == xyz[ii - 1][jj]); + + CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(nbCoords + 1, 0), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(myGrid2->getArrayValue(1, myGrid2->getArrayLength(1) + 1), MEDEXCEPTION); + myGrid2->setGridType(MED_POLAR); + + //testing read/write functions + + // add new driver + int idGridV21; + + try + { + idGridV21 = myGrid2->addDriver(MED_DRIVER,filenameout21); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // write this driver to file as an unstructured mesh + CPPUNIT_ASSERT_NO_THROW(myGrid2->writeUnstructured(idGridV21)); + + GRID* myGrid3 = new GRID(); + // add new driver for myGrid3 + int driver; + CPPUNIT_ASSERT_NO_THROW(driver = myGrid3->addDriver(MED_DRIVER, filenameout21)); + +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) ? "The mesh dimension |-1| seems to be incorrect for the mesh : |Default Mesh Name|" + CPPUNIT_ASSERT_NO_THROW(myGrid3->read(driver)); + + // Testing getArrayValue() + for ( int ii = 1; ii <= nbCoords; ii++ ) + for ( int jj = 0; jj < ii + 1; jj++ ) + CPPUNIT_ASSERT(myGrid3->getArrayValue(ii, jj) == xyz[ii - 1][jj]); + + CPPUNIT_ASSERT(myGrid3->getGridType() == MED_POLAR); +#endif + + delete myGrid3; + + //test init() + CPPUNIT_ASSERT_NO_THROW(myGrid2->init()); + CPPUNIT_ASSERT(myGrid2->getGridType() == MED_CARTESIAN); + CPPUNIT_ASSERT(myGrid2->getArrayLength(1) == 0); + CPPUNIT_ASSERT(myGrid2->getArrayLength(2) == 0); + CPPUNIT_ASSERT(myGrid2->getArrayLength(3) == 0); +#ifdef ENABLE_FAULTS + // (BUG) Segmentation Fault + myGrid2->makeUnstructured(); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR:makeUnstructured() - there is no check if grid is empty or not"); +#endif + + delete myGrid2; + } + +#ifdef ENABLE_FORCED_FAILURES + { + GRID* myGrid2; + // ? (BUG) ? MED Exception in /dn20/salome/jfa/V3/SRC/MED_SRC/src/MEDMEM/MEDMEM_MedM + //eshDriver21.cxx [430] : MED_MESH_RDONLY_DRIVER21::getCOORDINATE() : The number + //of nodes |0| seems to be incorrect for the mesh : |bodyfitted| + CPPUNIT_ASSERT_NO_THROW(myGrid2 = new GRID(MED_DRIVER, filename, mesh_names[1])); + + // Check if something has been read - full mesh data testing is above + CPPUNIT_ASSERT(myGrid2->getSpaceDimension()); + CPPUNIT_ASSERT(myGrid2->getNumberOfNodes()); + CPPUNIT_ASSERT(myGrid2->getNumberOfTypes(MED_CELL) == 1); + const medGeometryElement* types2; + CPPUNIT_ASSERT_NO_THROW(types2 = myGrid2->getTypes(MED_CELL)); + int nbElem; + CPPUNIT_ASSERT_NO_THROW(nbElem = myGrid2->getNumberOfElements(MED_CELL,types2[0])); + CPPUNIT_ASSERT(nbElem); + delete myGrid2; + } +#endif + + { + GRID* myGrid4 = new GRID(); + filename = datadir + "/MedFiles/pointe.med"; + myGrid4->setName("maa1"); + MED_MESH_RDONLY_DRIVER myMeshDriver(filename, myGrid4); + myMeshDriver.setMeshName("maa1"); + + // add new driver for myGrid4 + int driver; + CPPUNIT_ASSERT_NO_THROW(driver = myGrid4->addDriver(myMeshDriver)); + + // ??? ERROR:myGrid4->fillMeshAfterRead()- this method is incomplete: + // currently it only resets _is_coordinates_filled and _is_connectivity_filled + // flags that leads to grid reconstruction + + // MED Exception : MED_MESH_RDONLY_DRIVER21::getGRID() : The number + // of nodes |-1| seems to be incorrect for the mesh : |maa1| + // But this exception seems to be correct reaction on attempt + // to read a grid from a file, which does not contain it. + CPPUNIT_ASSERT_THROW(myGrid4->read(driver), MEDEXCEPTION); + //CPPUNIT_ASSERT_NO_THROW(myGrid4->read(driver)); + /*CPPUNIT_ASSERT(myGrid4->getArrayLength(1) == 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(2) == 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(3) == 0); + myGrid4->fillMeshAfterRead(); + CPPUNIT_ASSERT(myGrid4->getArrayLength(1) != 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(2) != 0); + CPPUNIT_ASSERT(myGrid4->getArrayLength(3) != 0);*/ + + delete myGrid4; + } +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testGrid(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Group.cxx b/src/MEDMEM/Test/MEDMEMTest_Group.cxx new file mode 100644 index 000000000..1680f692e --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Group.cxx @@ -0,0 +1,149 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Group.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_MedMeshDriver.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (10), defined in MEDMEM_Group.hxx: + * class GROUP : virtual public SUPPORT { + * (+) GROUP(); + * (+) GROUP(const string & name, const list<FAMILY*> & family) throw (MEDEXCEPTION); + * (+) GROUP(const GROUP & m); + * (+) virtual ~GROUP(); + * (+) GROUP & operator=(const GROUP &group); + * (+) friend ostream & operator<<(ostream &os, GROUP &my); + * (+) inline void setNumberOfFamilies(int numberOfFamilies); + * (+) inline void setFamilies(vector<FAMILY*> Family); + * (+) inline int getNumberOfFamilies() const; + * (+) inline vector<FAMILY*> getFamilies() const; + * (+) inline FAMILY * getFamily(int i) const; + * } + */ +void MEDMEMTest::testGroup() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med" ; + string meshname = "maa1"; + + MESH * myMesh= new MESH() ; + myMesh->setName(meshname); + MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh); + myMeshDriver.setMeshName(meshname); + myMeshDriver.open(); + myMeshDriver.read(); + myMeshDriver.close(); + + const GROUP * myGroup = myMesh->getGroup(MED_NODE,1); + CPPUNIT_ASSERT(myGroup != NULL); + + int NumberOfFamillies = myGroup->getNumberOfFamilies(); + CPPUNIT_ASSERT(NumberOfFamillies != 0); + + vector<FAMILY*> aFamilies = myGroup->getFamilies(); + CPPUNIT_ASSERT(NumberOfFamillies == aFamilies.size()); + list<FAMILY*> aList; + + for (int j=1;j<=NumberOfFamillies;j++) + { + try{ + aList.push_back(myGroup->getFamily(j)); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(myGroup->getFamily(j)->getName(), aFamilies[j-1]->getName()); + } + + GROUP* myGroup2 = new GROUP(*myGroup); + + cout<<*myGroup2<<endl; + ostringstream os; + os << *myGroup2; + CPPUNIT_ASSERT(os.str() != ""); + + GROUP myGroup3; + try{ + myGroup3 = *myGroup2; + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(myGroup3, *myGroup2); + + GROUP myGroup4; + const GROUP * Group = myMesh->getGroup(MED_NODE,2); + CPPUNIT_ASSERT(Group != NULL); + + int NumberOfFamillies1 = Group->getNumberOfFamilies(); + CPPUNIT_ASSERT(NumberOfFamillies1 != 0); + if(NumberOfFamillies1) + { + myGroup4.setNumberOfFamilies(NumberOfFamillies1); + myGroup4.setFamilies(Group->getFamilies()); + for(int i = 1; i <= myGroup4.getNumberOfFamilies(); i++ ) + { + CPPUNIT_ASSERT_EQUAL(myGroup4.getFamily(i), Group->getFamily(i)); + } + } + + if(aList.size()) + { + try{ + GROUP myGroup5("newFamily", aList); + cout<< myGroup5 <<endl; + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + + delete myGroup2; + delete myMesh ; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Med.cxx b/src/MEDMEM/Test/MEDMEMTest_Med.cxx new file mode 100644 index 000000000..3b040101d --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Med.cxx @@ -0,0 +1,437 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Med.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +// #30: MEDMEM_Med.hxx } MEDMEMTest_Med.cxx + +/*! + * Check methods (26), defined in MEDMEM_Med.hxx: + * class MED { + * (+) MED(); + * (+) MED (driverTypes driverType, const string & fileName); + * (+) ~MED(); + * (+) void addField (FIELD_ * const ptrField) throw (MED_EXCEPTION); + * (+) void addMesh (MESH * const ptrMesh) throw (MED_EXCEPTION); + * (+) int addDriver (driverTypes driverType, const string & fileName, + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (+) int addDriver (GENDRIVER & driver); + * (+) void rmDriver (int index=0) throw (MEDEXCEPTION); + * (+) void readFileStruct(int index=0) throw (MEDEXCEPTION); + * (+) void read (int index=0) throw (MEDEXCEPTION); + * (+) void writeFrom (int index=0) throw (MEDEXCEPTION); + * (+) void write (int index=0) throw (MEDEXCEPTION); + * (+) int getNumberOfMeshes (void) const; + * (+) int getNumberOfFields (void) const; + * (+) void getMeshNames (string * meshNames) const throw (MEDEXCEPTION); + * (+) deque<string> getMeshNames () const; + * (+) MESH * getMesh (const string & meshName) const throw (MEDEXCEPTION); + * (+) MESH * getMesh (const FIELD_ * const field) const throw (MEDEXCEPTION); + * (+) void getFieldNames (string * fieldNames) const throw (MEDEXCEPTION); + * (+) deque<string> getFieldNames () const; + * (+) deque<DT_IT_> getFieldIteration (const string & fieldName) const throw (MEDEXCEPTION); + * (+) FIELD_ * getField (const string & fieldName, const int dt, + * const int it) const throw (MEDEXCEPTION); + * (NOT COMPILABLE!!!) template<class T> FIELD<T> * getFieldT + * (const string & fieldName, const int dt, const int it) const throw (MEDEXCEPTION); + * (+) FIELD_ * getField2 (const string & fieldName, double time, int it=0) const throw (MEDEXCEPTION); + * (+) const map<MED_EN::medEntityMesh,SUPPORT *> & getSupports + * (const string & meshName) const throw (MEDEXCEPTION); + * (+) SUPPORT * getSupport (const string & meshName, + * MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); + * (-, as it is temporary and called from driver after Med object reading from file) void updateSupport (); + * } + */ +void MEDMEMTest::testMed() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + + string filenameout21 = tmp_dir + "/myMedWrite_pointe21.med"; + string filenameout21_from = tmp_dir + "/myMedWrite_pointe21_from.med"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filenameout21); + aRemover.Register(filenameout21_from); + + MED* myMed = new MED(MED_DRIVER, filename); + //read all objects in the file + CPPUNIT_ASSERT_NO_THROW(myMed->read()); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Memory problem in MED::updateSupport()! + // Invalid read of size 4 + // at 0x34548AD6: std::_Rb_tree_decrement(std::_Rb_tree_node_base*) (in /usr/lib/libstdc++.so.6.0.1) + // by 0x34876722: std::_Rb_tree_iterator<std::pair<long const, MEDMEM::SUPPORT*> >::operator--(int) (stl_tree.h:203) + // by 0x348733BE: MEDMEM::MED::updateSupport() (MEDMEM_Med.cxx:805) + // Address 0x35C67598 is 0 bytes inside a block of size 24 free'd + // at 0x3414CBD5: operator delete(void*) (vg_replace_malloc.c:155) + // ... + // by 0x348766EB: std::map<long, MEDMEM::SUPPORT*, std::less<long>, std::allocator<std::pair<long const, MEDMEM::SUPPORT*> > >::erase(std::_Rb_tree_iterator<std::pair<long const, MEDMEM::SUPPORT*> >) (stl_map.h:410) + // by 0x348733A3: MEDMEM::MED::updateSupport() (MEDMEM_Med.cxx:804) + CPPUNIT_FAIL("Memory problem in MED::updateSupport(): removing map item while iterating on this map."); +#endif + + //getNumberOfMeshes + int nbMeshes, nbFields; + try{ + nbMeshes = myMed->getNumberOfMeshes(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(nbMeshes); + + //getMeshNames + deque<string> mesh_names, field_names; + try{ + mesh_names = myMed->getMeshNames(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(mesh_names.size() != 0); + + //getNumberOfFields + try{ + nbFields = myMed->getNumberOfFields(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(nbFields); + + //getFieldNames + try{ + field_names = myMed->getFieldNames(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(field_names.size() != 0); + + string field_names_1[nbFields]; + string mesh_names_1[nbMeshes]; + //get field and mesh names + try{ + myMed->getMeshNames(mesh_names_1); + myMed->getFieldNames(field_names_1); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // Ensure what it's impossible to get mesh object by empty or non-existent name + CPPUNIT_ASSERT_THROW(myMed->getMesh(""), MEDEXCEPTION); + + //compare mesh names, produced by two different methods + for(int nb = 0; nb < nbMeshes; nb++ ) + { + MESH* myMesh; + CPPUNIT_ASSERT(mesh_names_1[nb] == mesh_names[nb]); + CPPUNIT_ASSERT_NO_THROW(myMesh = myMed->getMesh(mesh_names[nb])); + //ensure mesh is not empty + CPPUNIT_ASSERT(myMesh->getSpaceDimension() != MED_INVALID); + CPPUNIT_ASSERT(myMesh->getNumberOfNodes() != MED_INVALID); + CPPUNIT_ASSERT(myMesh->getCoordinateptr() != NULL); + } + + // Ensure what it's impossible to get field object by empty or non-existent name + CPPUNIT_ASSERT_THROW(myMed->getField("", 0, 0),MEDEXCEPTION); + + // Cycle by amount of fields + // Compare field names produced by two different methods + // Get field object with help of getField(...) and getField2(...) + for(int nb = 0; nb < nbFields; nb++ ) + { + CPPUNIT_ASSERT(field_names_1[nb] == field_names[nb]); + deque<DT_IT_> myFIter; + CPPUNIT_ASSERT_NO_THROW(myFIter = myMed->getFieldIteration(field_names[nb])); + CPPUNIT_ASSERT(myFIter.size()); + for(int nbIter = 0; nbIter < myFIter.size(); nbIter++) + { + FIELD_ *myField, *myField2; + CPPUNIT_ASSERT_NO_THROW(myField = myMed->getField (field_names[nb], myFIter[nbIter].dt, myFIter[nbIter].it)); + CPPUNIT_ASSERT_NO_THROW(myField2 = myMed->getField2(field_names[nb], myField->getTime())); + CPPUNIT_ASSERT(myField==myField2); + //compare two fields + CPPUNIT_ASSERT(myField->getNumberOfComponents() == myField2->getNumberOfComponents()); + CPPUNIT_ASSERT(myField->getNumberOfValues() == myField2->getNumberOfValues()); + CPPUNIT_ASSERT(myField->getSupport() == myField2->getSupport()); + CPPUNIT_ASSERT(myField->getValueType() == myField2->getValueType()); + CPPUNIT_ASSERT(myField->getDescription() == myField2->getDescription()); + + med_type_champ type = myField->getValueType(); + switch (type) + { + case MED_INT32: + { +#ifdef ENABLE_FORCED_FAILURES + // (BUG) ERROR in MEDMEM_Med.hxx line 153: FIELD_ retUp=getField(fieldName,dt,it); + // But getField returns FIELD_* + CPPUNIT_FAIL("Error in MED::getFieldT(const string & fieldName, const int dt, const int it)"); +#endif + // not compilable + //FIELD<int> *myFieldT; + //CPPUNIT_ASSERT_NO_THROW(myFieldT = myMed->getFieldT<int>(field_names[nb], myFIter[nbIter].dt, myFIter[nbIter].it)) + } + break; + case MED_REEL64: + { + // not compilable + //FIELD<double> *myFieldT; + //CPPUNIT_ASSERT_NO_THROW(myFieldT = myMed->getFieldT<double>(field_names[nb], myFIter[nbIter].dt, myFIter[nbIter].it)) + } + break; + } + } + } + + // For each mesh get a map + for(int nb = 0; nb < nbMeshes; nb++ ) + { + map<MED_EN::medEntityMesh,SUPPORT *> myMapSupports; + CPPUNIT_ASSERT_NO_THROW(myMapSupports = myMed->getSupports(mesh_names[nb])); + map<MED_EN::medEntityMesh,SUPPORT *>::const_iterator myMapSupportsIter = myMapSupports.begin(); + for( ; myMapSupportsIter != myMapSupports.end(); myMapSupportsIter++ ) + { + SUPPORT* mySupport; + CPPUNIT_ASSERT_NO_THROW(mySupport = myMed->getSupport(mesh_names[nb], (*myMapSupportsIter).first)); + CPPUNIT_ASSERT_EQUAL(mySupport, (*myMapSupportsIter).second); + CPPUNIT_ASSERT(mySupport->deepCompare(*(*myMapSupportsIter).second)); + } + } + + // add new driver + int idMedV21; + + try + { + idMedV21 = myMed->addDriver(MED_DRIVER,filenameout21); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // write to file + CPPUNIT_ASSERT_NO_THROW(myMed->write(idMedV21)); + // check, that the file is created on disk + CPPUNIT_ASSERT(access(filenameout21.data(), F_OK) == 0); + + // writeFrom + CPPUNIT_ASSERT_THROW(myMed->writeFrom(idMedV21 + 1000), MEDEXCEPTION); // invalid driver index + int idMedV21_from = myMed->addDriver(MED_DRIVER, filenameout21_from); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) MED::writeFrom(int) always throws MEDEXCEPTION. + // ? missed 'else' clause before throw ? + CPPUNIT_ASSERT_NO_THROW(myMed->writeFrom(idMedV21_from)); +#endif + // check, that the file is created on disk +#ifdef ENABLE_FORCED_FAILURES + // ? (BUG) The file is not created. + CPPUNIT_ASSERT(access(filenameout21_from.data(), F_OK) == 0); +#endif + + // remove driver from med + CPPUNIT_ASSERT_NO_THROW(myMed->rmDriver(idMedV21)); +#ifdef ENABLE_FORCED_FAILURES + //ERROR: driver with index idMedV21 has not been removed + // Why driver removal is commented out? + // ensure exception is raised on second attempt to remove driver + CPPUNIT_ASSERT_THROW(myMed->rmDriver(idMedV21),MEDEXCEPTION); +#endif + + //create empty MED object + MED* myEmptyMed = new MED(); + // create new driver for med object + // and add driver to med + int idDriver; + GENDRIVER *driver = DRIVERFACTORY::buildDriverForMed(MED_DRIVER,filename,myEmptyMed,MED_LECT); + try{ + idDriver = myEmptyMed->addDriver(*driver); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(idDriver == 0); + + // trying to read file with non-existent index of driver + // read file and create empty object + CPPUNIT_ASSERT_NO_THROW(myEmptyMed->readFileStruct()); + + //getNumberOfMeshes + int nbEmptyMeshes, nbEmptyFields; + try{ + nbEmptyMeshes = myEmptyMed->getNumberOfMeshes(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(nbEmptyMeshes == nbMeshes); + + //getMeshNames + deque<string> empty_mesh_names, empty_field_names; + try{ + empty_mesh_names = myEmptyMed->getMeshNames(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(empty_mesh_names.size() != 0); + + //getNumberOfFields + try{ + nbEmptyFields = myEmptyMed->getNumberOfFields(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(nbFields == nbEmptyFields); + + //getFieldNames + try{ + empty_field_names = myEmptyMed->getFieldNames(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(empty_field_names.size() != 0); + + //compare mesh names, produced by two different methods + for(int nb = 0; nb < nbMeshes; nb++ ) + { + MESH* myMesh; + CPPUNIT_ASSERT(empty_mesh_names[nb] == mesh_names[nb]); + CPPUNIT_ASSERT_NO_THROW(myMesh = myEmptyMed->getMesh(empty_mesh_names[nb])); + //MESH* myMesh1 = myMed->getMesh(mesh_names[nb]); + CPPUNIT_ASSERT(!myMesh->deepCompare(*(myMed->getMesh(mesh_names[nb])))); + //ensure mesh is empty + CPPUNIT_ASSERT(myMesh->getSpaceDimension() == MED_INVALID); + CPPUNIT_ASSERT(myMesh->getNumberOfNodes() == MED_INVALID); + CPPUNIT_ASSERT(myMesh->getCoordinateptr() == NULL); + } + + // trying to add null mesh pointer + CPPUNIT_ASSERT_THROW(myEmptyMed->addMesh(NULL), MEDEXCEPTION); + + //create a mesh + MESH * aMesh = MEDMEMTest_createTestMesh(); + // and add it + CPPUNIT_ASSERT_NO_THROW(myEmptyMed->addMesh(aMesh)); + + //compare two meshes + CPPUNIT_ASSERT(aMesh->deepCompare(*(myEmptyMed->getMesh("meshing")))); + + // add null field, exception should be raised + CPPUNIT_ASSERT_THROW(myEmptyMed->addField(NULL), MEDEXCEPTION); + // + FIELD_* myEmptyField = new FIELD_(); + // add empty field, ensure exception is raised + CPPUNIT_ASSERT_THROW(myEmptyMed->addField(myEmptyField), MEDEXCEPTION); + //set field name + myEmptyField->setName("myField"); + + // set support + SUPPORT* aSupport = new SUPPORT(myEmptyMed->getMesh("meshing"), "Support On Cells"); + myEmptyField->setSupport(aSupport); + + CPPUNIT_ASSERT_NO_THROW(myEmptyMed->addField(myEmptyField)); + + CPPUNIT_ASSERT(aSupport->deepCompare(*(myEmptyMed->getSupport("meshing",MED_CELL)))); + CPPUNIT_ASSERT(aMesh->deepCompare(*(myEmptyMed->getMesh("meshing")))); + + delete myMed; + delete myEmptyMed; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver21.cxx b/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver21.cxx new file mode 100644 index 000000000..262bfabe6 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver21.cxx @@ -0,0 +1,625 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Field.hxx> +#include <MEDMEM_MedFieldDriver21.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +/*! + * Check methods (17), defined in MEDMEM_MedFieldDriver21.hxx: + * template <class T> class MED_FIELD_DRIVER21 : public virtual MED_FIELD_DRIVER<T> { + * (+) MED_FIELD_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_DRIVER21(const string & fileName, + * FIELD<T, INTERLACING_TAG> * ptrField, MED_EN::med_mode_acces accessMode); + * (+) MED_FIELD_DRIVER21(const MED_FIELD_DRIVER21 & fieldDriver); + * (+) virtual ~MED_FIELD_DRIVER21(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * } + * template <class T> class MED_FIELD_RDONLY_DRIVER21 : public virtual MED_FIELD_DRIVER21<T>, + * public virtual IMED_FIELD_RDONLY_DRIVER<T> { + * (+) MED_FIELD_RDONLY_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_RDONLY_DRIVER21 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_RDONLY_DRIVER21(const MED_FIELD_RDONLY_DRIVER21 & fieldDriver); + * (+) virtual ~MED_FIELD_RDONLY_DRIVER21(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * template <class T> class MED_FIELD_WRONLY_DRIVER21 : public virtual MED_FIELD_DRIVER21<T>, + * public virtual IMED_FIELD_WRONLY_DRIVER<T> { + * (+) MED_FIELD_WRONLY_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_WRONLY_DRIVER21 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_WRONLY_DRIVER21(const MED_FIELD_WRONLY_DRIVER21 & fieldDriver); + * (+) virtual ~MED_FIELD_WRONLY_DRIVER21(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * template <class T> class MED_FIELD_RDWR_DRIVER21 : public MED_FIELD_RDONLY_DRIVER21<T>, + * public MED_FIELD_WRONLY_DRIVER21<T>, public IMED_FIELD_RDWR_DRIVER<T> { + * (+) MED_FIELD_RDWR_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_RDWR_DRIVER21 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_RDWR_DRIVER21(const MED_FIELD_RDWR_DRIVER21 & fieldDriver); + * (+) ~MED_FIELD_RDWR_DRIVER21(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testMedFieldDriver21() +{ + FIELD<int> *aField = new FIELD<int> (); + FIELD<int> *aField_1 = new FIELD<int> (); + FIELD<double> *aField_2 = new FIELD<double> (); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string filenameWithOutFileds = data_dir + "/MedFiles/Mistrat.med"; + string fileldnotexist = "anyfield"; + string fieldname = "fieldnodeint"; + string fieldname_cpy = fieldname + "_cpy"; + string fileNotExist_rd = "notExist.med"; + string emptyfilename = ""; + + string filename_wr = tmp_dir + "/myWrField_pointe21.med"; + string cp_file_wr = "cp " + filename_rd + " " + filename_wr; + string fileNotExist_wr = "/path_not_exist/file_not_exist.med"; + string emptyfile_wr = tmp_dir + "/myWrField_pointe_empty21.med"; + string other_file = data_dir + "/MedFiles/fra.med"; + string other_file_wr = tmp_dir + "/myWRfra.med"; + string cp_other_file = "cp " + other_file + " " + other_file_wr; + + string filename_rdwr = tmp_dir + "/myRdWrField_pointe21.med"; + string cp_file_rdwr = "cp " + filename_rd + " " + filename_rdwr; + string emptyfile_rdwr = tmp_dir + "/myRdWrField_pointe_empty21.med"; + string fieldnameDouble = "fieldnodedouble"; + string fieldnameDouble_cpy = fieldnameDouble + "_cpy"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(emptyfile_wr); + aRemover.Register(other_file_wr); + aRemover.Register(filename_rdwr); + aRemover.Register(emptyfile_rdwr); + + //--------------------------Test READ ONLY part------------------------------// + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Read Only MedFieldDriver21 (file not exist) + MED_FIELD_RDONLY_DRIVER21<int> *aInvalidMedRdFieldDriver21_1 = + new MED_FIELD_RDONLY_DRIVER21<int>(fileNotExist_rd, aField); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver21_1->open(), MEDEXCEPTION); + + ////////////////////////////////////////////// + // TEST2: Open file with empty file name /// + ////////////////////////////////////////////// + + //Creation Invalid Read Only MedFieldDriver21 (empty file name) + MED_FIELD_RDONLY_DRIVER21<int> *aInvalidMedRdFieldDriver21_2 = + new MED_FIELD_RDONLY_DRIVER21<int>(emptyfilename, aField); + //Trying file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver21_2->open(), MEDEXCEPTION); + + ///////////////////////////////////////////////////// + // TEST3: Reading field from file without fields // + ///////////////////////////////////////////////////// + MED_FIELD_RDONLY_DRIVER21<int> *aInvalidMedRdFieldDriver21_3 = + new MED_FIELD_RDONLY_DRIVER21<int>(filenameWithOutFileds, aField); + aInvalidMedRdFieldDriver21_3->open(); + aInvalidMedRdFieldDriver21_3->setFieldName(fieldname); + //Trying read field from file + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver21_3->read(), MEDEXCEPTION); + aInvalidMedRdFieldDriver21_3->close(); + + //////////////////////// + // TEST4: Main test // + //////////////////////// + //Creation correct Read Only MedFieldDriver21 + MED_FIELD_RDONLY_DRIVER21<int> *aMedRdFieldDriver21 = + new MED_FIELD_RDONLY_DRIVER21<int>(filename_rd, aField); + + //Check driver + CPPUNIT_ASSERT(aMedRdFieldDriver21); + + //Trying read field before open file + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(),MEDEXCEPTION); + + //Test open() method + try + { + aMedRdFieldDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Trying read field form file if it name is empty + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(), MEDEXCEPTION); + + //Test setFieldName() and getFieldName() + try + { + aMedRdFieldDriver21->setFieldName(fileldnotexist); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdFieldDriver21->getFieldName()); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(), MEDEXCEPTION); + + //Test read() method + aMedRdFieldDriver21->setFieldName(fieldname); + try + { + aMedRdFieldDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() method for READ ONLY driver + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->write(), MEDEXCEPTION); + + //Test close() method + try + { + aMedRdFieldDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_RDONLY_DRIVER21<int> aMedRdFieldDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + aMedRdFieldDriver21Cpy_1 = *aMedRdFieldDriver21; + + //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aMedRdFieldDriver21Cpy_1 == *aMedRdFieldDriver21); + + //Test copy constructor + MED_FIELD_RDONLY_DRIVER21<int> aMedRdFieldDriver21Cpy_2 (*aMedRdFieldDriver21); + CPPUNIT_ASSERT_EQUAL(aMedRdFieldDriver21Cpy_2, *aMedRdFieldDriver21); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rostr1, rostr2; + rostr1<<aMedRdFieldDriver21Cpy_1; + rostr2<<aMedRdFieldDriver21Cpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT(rostr1.str() == rostr2.str()); + + + //--------------------------Test WRITE ONLY part------------------------------// + + //Copy file + system(cp_other_file.c_str()); + system(cp_file_wr.c_str()); + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Write Only MedFieldDriver21 (file not exist) + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_1 = + new MED_FIELD_WRONLY_DRIVER21<int>(fileNotExist_wr, aField_1); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_1->open(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid Write Only MedFieldDriver21 (empty file name) + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_2 = + new MED_FIELD_WRONLY_DRIVER21<int>(emptyfilename, aField_1); + //Trying open not existing file and file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_2->open(), MEDEXCEPTION); + + /////////////////////////////////////////////////////// + // TEST3: Writing field in empty file without mesh // + /////////////////////////////////////////////////////// + //Creation Invalid Write Only MedFieldDriver21 + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_3 = + new MED_FIELD_WRONLY_DRIVER21<int>(emptyfile_wr, aField); + + aInvalidMedWrFieldDriver21_3->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_3->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + ////////////////////////////////////////////// + // TEST4: Writing field in the other file // + ////////////////////////////////////////////// + + //Creation Invalid Write Only MedFieldDriver21 + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_4 = + new MED_FIELD_WRONLY_DRIVER21<int>(other_file_wr, aField); + aInvalidMedWrFieldDriver21_4->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_4->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + //////////////////////// + // TEST5: Main test // + //////////////////////// + + //Creation correct Write Only MedFieldDriver21 + MED_FIELD_WRONLY_DRIVER21<int> *aMedWrFieldDriver21 = + new MED_FIELD_WRONLY_DRIVER21<int>(filename_wr, aField); + + //Check driver + CPPUNIT_ASSERT(aMedWrFieldDriver21); + + //Trying write field before open file +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver21->write(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Test open() method + try + { + aMedWrFieldDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver21->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Test setFieldName() and getFieldName + aField->setName(fieldname_cpy); + try + { + aMedWrFieldDriver21->setFieldName(fieldname_cpy); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fieldname_cpy, aMedWrFieldDriver21->getFieldName()); + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedWrFieldDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + //=>Segmentation fault in this case +#endif + + //Test read() method for Write only part + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver21->read(),MEDEXCEPTION); + + //Test close() method + try + { + aMedWrFieldDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_WRONLY_DRIVER21<int> aMedWrFieldDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedWrFieldDriver21Cpy_1 = *aMedWrFieldDriver21; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aMedWrFieldDriver21Cpy_1.GENDRIVER::operator==(*aMedWrFieldDriver21)); + + //Test copy constructor + MED_FIELD_WRONLY_DRIVER21<int> aMedWrFieldDriver21Cpy_2 (*aMedWrFieldDriver21); + CPPUNIT_ASSERT_EQUAL(aMedWrFieldDriver21Cpy_2, *aMedWrFieldDriver21); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream wostr1, wostr2; + wostr1 << aMedWrFieldDriver21Cpy_1; + wostr2 << aMedWrFieldDriver21Cpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + + //--------------------------Test READ/WRITE part------------------------------// + + //Copy files + system(cp_file_rdwr.c_str()); + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Read/Write MedFieldDriver21 (file not exist) + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_1 = + new MED_FIELD_RDWR_DRIVER21<int>(fileNotExist_wr, aField_1); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_1->open(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver21 (empty file name) + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_2 = + new MED_FIELD_RDWR_DRIVER21<int>(emptyfilename, aField_1); + //Trying open not existing file and file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_2->open(), MEDEXCEPTION); + + ///////////////////////////////////////////////////// + // TEST3: Reading field from file without fields // + ///////////////////////////////////////////////////// + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_3 = + new MED_FIELD_RDWR_DRIVER21<int>(filenameWithOutFileds, aField_1); + aInvalidMedRdWrFieldDriver21_3->open(); + aInvalidMedRdWrFieldDriver21_3->setFieldName(fieldname); + //Trying read field from file + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_3->read(), MEDEXCEPTION); + aInvalidMedRdWrFieldDriver21_3->close(); + + /////////////////////////////////////////////////////// + // TEST4: Writing field in empty file without mesh // + /////////////////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver21 + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_4 = + new MED_FIELD_RDWR_DRIVER21<int>(emptyfile_rdwr, aField); + + aInvalidMedRdWrFieldDriver21_4->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_4->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + ////////////////////////////////////////////// + // TEST6: Writing field in the other file // + ////////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver21 + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_5 = + new MED_FIELD_RDWR_DRIVER21<int>(other_file_wr, aField); + aInvalidMedRdWrFieldDriver21_5->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_5->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + //////////////////////// + // TEST7: Main test // + //////////////////////// + + //Creation correct Read/Write MedFieldDriver21 + MED_FIELD_RDWR_DRIVER21<double> *aMedRdWrFieldDriver21 = + new MED_FIELD_RDWR_DRIVER21<double>(filename_rdwr, aField_2); + + //Check driver + CPPUNIT_ASSERT(aMedRdWrFieldDriver21); + + //Trying read/write field before open file + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->read(),MEDEXCEPTION); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->write(),MEDEXCEPTION); + //(BUG) No exception in this case +#endif + + //Test open() method + try + { + aMedRdWrFieldDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Trying read field from file if field name is empty + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(), MEDEXCEPTION); + + //Test setFieldName() and getFieldName + try + { + aMedRdWrFieldDriver21->setFieldName(fileldnotexist); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdWrFieldDriver21->getFieldName()); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->read(), MEDEXCEPTION); + + //Test read() method + aMedRdWrFieldDriver21->setFieldName(fieldnameDouble); + try + { + aMedRdWrFieldDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying write field in the file with empty name + aField_2->setName(emptyfilename); + aMedRdWrFieldDriver21->setFieldName(emptyfilename); + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->write(), MEDEXCEPTION); + + //Test write() method + aField_2->setName(fieldnameDouble_cpy); + aMedRdWrFieldDriver21->setFieldName(fieldnameDouble_cpy); +#ifdef ENABLE_FAULTS + try + { + aMedRdWrFieldDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + //=>Segmentation fault in this case +#endif + + //Test close() method + try + { + aMedRdWrFieldDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_RDWR_DRIVER21<double> aMedRdWrFieldDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedRdWrFieldDriver21Cpy_1 = *aMedRdWrFieldDriver21; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aMedRdWrFieldDriver21Cpy_1.GENDRIVER::operator==(*aMedRdWrFieldDriver21)); + + //Test copy constructor + MED_FIELD_RDWR_DRIVER21<double> aMedRdWrFieldDriver21Cpy_2 (*aMedRdWrFieldDriver21); + CPPUNIT_ASSERT_EQUAL(aMedRdWrFieldDriver21Cpy_2, *aMedRdWrFieldDriver21); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rwostr1, rwostr2; + rwostr1 << aMedRdWrFieldDriver21Cpy_1; + rwostr2 << aMedRdWrFieldDriver21Cpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aField; + delete aField_1; + delete aField_2; + + delete aInvalidMedRdFieldDriver21_1; + delete aInvalidMedRdFieldDriver21_2; + delete aInvalidMedRdFieldDriver21_3; + delete aMedRdFieldDriver21; + + delete aInvalidMedWrFieldDriver21_1; + delete aInvalidMedWrFieldDriver21_2; + delete aInvalidMedWrFieldDriver21_3; + delete aInvalidMedWrFieldDriver21_4; + delete aMedWrFieldDriver21; + + delete aInvalidMedRdWrFieldDriver21_1; + delete aInvalidMedRdWrFieldDriver21_2; + delete aInvalidMedRdWrFieldDriver21_3; + delete aInvalidMedRdWrFieldDriver21_4; + delete aInvalidMedRdWrFieldDriver21_5; + delete aMedRdWrFieldDriver21; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver21_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver21_fault.cxx new file mode 100644 index 000000000..1011762a1 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver21_fault.cxx @@ -0,0 +1,630 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Field.hxx> +#include <MEDMEM_MedFieldDriver21.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +/*! + * Check methods (17), defined in MEDMEM_MedFieldDriver21.hxx: + * template <class T> class MED_FIELD_DRIVER21 : public virtual MED_FIELD_DRIVER<T> { + * (+) MED_FIELD_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_DRIVER21(const string & fileName, + * FIELD<T, INTERLACING_TAG> * ptrField, MED_EN::med_mode_acces accessMode); + * (+) MED_FIELD_DRIVER21(const MED_FIELD_DRIVER21 & fieldDriver); + * (+) virtual ~MED_FIELD_DRIVER21(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * } + * template <class T> class MED_FIELD_RDONLY_DRIVER21 : public virtual MED_FIELD_DRIVER21<T>, + * public virtual IMED_FIELD_RDONLY_DRIVER<T> { + * (+) MED_FIELD_RDONLY_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_RDONLY_DRIVER21 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_RDONLY_DRIVER21(const MED_FIELD_RDONLY_DRIVER21 & fieldDriver); + * (+) virtual ~MED_FIELD_RDONLY_DRIVER21(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * template <class T> class MED_FIELD_WRONLY_DRIVER21 : public virtual MED_FIELD_DRIVER21<T>, + * public virtual IMED_FIELD_WRONLY_DRIVER<T> { + * (+) MED_FIELD_WRONLY_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_WRONLY_DRIVER21 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_WRONLY_DRIVER21(const MED_FIELD_WRONLY_DRIVER21 & fieldDriver); + * (+) virtual ~MED_FIELD_WRONLY_DRIVER21(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * template <class T> class MED_FIELD_RDWR_DRIVER21 : public MED_FIELD_RDONLY_DRIVER21<T>, + * public MED_FIELD_WRONLY_DRIVER21<T>, public IMED_FIELD_RDWR_DRIVER<T> { + * (+) MED_FIELD_RDWR_DRIVER21(); + * (+) template <class INTERLACING_TAG> MED_FIELD_RDWR_DRIVER21 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_RDWR_DRIVER21(const MED_FIELD_RDWR_DRIVER21 & fieldDriver); + * (+) ~MED_FIELD_RDWR_DRIVER21(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest_testMedFieldDriver21() +{ + FIELD<int> *aField = new FIELD<int> (); + FIELD<int> *aField_1 = new FIELD<int> (); + FIELD<double> *aField_2 = new FIELD<double> (); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string filenameWithOutFileds = data_dir + "/MedFiles/Mistrat.med"; + string fileldnotexist = "anyfield"; + string fieldname = "fieldnodeint"; + string fieldname_cpy = fieldname + "_cpy"; + string fileNotExist_rd = "notExist.med"; + string emptyfilename = ""; + + string filename_wr = tmp_dir + "/myWrField_pointe21.med"; + string cp_file_wr = "cp " + filename_rd + " " + filename_wr; + string fileNotExist_wr = "/path_not_exist/file_not_exist.med"; + string emptyfile_wr = tmp_dir + "/myWrField_pointe_empty21.med"; + string other_file = data_dir + "/MedFiles/fra.med"; + string other_file_wr = tmp_dir + "/myWRfra.med"; + string cp_other_file = "cp " + other_file + " " + other_file_wr; + + string filename_rdwr = tmp_dir + "/myRdWrField_pointe21.med"; + string cp_file_rdwr = "cp " + filename_rd + " " + filename_rdwr; + string emptyfile_rdwr = tmp_dir + "/myRdWrField_pointe_empty21.med"; + string fieldnameDouble = "fieldnodedouble"; + string fieldnameDouble_cpy = fieldnameDouble + "_cpy"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(emptyfile_wr); + aRemover.Register(other_file_wr); + aRemover.Register(filename_rdwr); + aRemover.Register(emptyfile_rdwr); + + //--------------------------Test READ ONLY part------------------------------// + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Read Only MedFieldDriver21 (file not exist) + MED_FIELD_RDONLY_DRIVER21<int> *aInvalidMedRdFieldDriver21_1 = + new MED_FIELD_RDONLY_DRIVER21<int>(fileNotExist_rd, aField); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver21_1->open(), MEDEXCEPTION); + + ////////////////////////////////////////////// + // TEST2: Open file with empty file name /// + ////////////////////////////////////////////// + + //Creation Invalid Read Only MedFieldDriver21 (empty file name) + MED_FIELD_RDONLY_DRIVER21<int> *aInvalidMedRdFieldDriver21_2 = + new MED_FIELD_RDONLY_DRIVER21<int>(emptyfilename, aField); + //Trying file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver21_2->open(), MEDEXCEPTION); + + ///////////////////////////////////////////////////// + // TEST3: Reading field from file without fields // + ///////////////////////////////////////////////////// + MED_FIELD_RDONLY_DRIVER21<int> *aInvalidMedRdFieldDriver21_3 = + new MED_FIELD_RDONLY_DRIVER21<int>(filenameWithOutFileds, aField); + aInvalidMedRdFieldDriver21_3->open(); + aInvalidMedRdFieldDriver21_3->setFieldName(fieldname); + //Trying read field from file + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver21_3->read(), MEDEXCEPTION); + aInvalidMedRdFieldDriver21_3->close(); + + //////////////////////// + // TEST4: Main test // + //////////////////////// + //Creation correct Read Only MedFieldDriver21 + MED_FIELD_RDONLY_DRIVER21<int> *aMedRdFieldDriver21 = + new MED_FIELD_RDONLY_DRIVER21<int>(filename_rd, aField); + + //Check driver + CPPUNIT_ASSERT(aMedRdFieldDriver21); + + //Trying read field before open file + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(),MEDEXCEPTION); + + //Test open() method + try + { + aMedRdFieldDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Trying read field form file if it name is empty + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(), MEDEXCEPTION); + + //Test setFieldName() and getFieldName() + try + { + aMedRdFieldDriver21->setFieldName(fileldnotexist); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdFieldDriver21->getFieldName()); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(), MEDEXCEPTION); + + //Test read() method + aMedRdFieldDriver21->setFieldName(fieldname); + try + { + aMedRdFieldDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() method for READ ONLY driver + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->write(), MEDEXCEPTION); + + //Test close() method + try + { + aMedRdFieldDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_RDONLY_DRIVER21<int> aMedRdFieldDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + aMedRdFieldDriver21Cpy_1 = *aMedRdFieldDriver21; + + //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aMedRdFieldDriver21Cpy_1 == *aMedRdFieldDriver21); + + //Test copy constructor + MED_FIELD_RDONLY_DRIVER21<int> aMedRdFieldDriver21Cpy_2 (*aMedRdFieldDriver21); + CPPUNIT_ASSERT_EQUAL(aMedRdFieldDriver21Cpy_2, *aMedRdFieldDriver21); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rostr1, rostr2; + rostr1<<aMedRdFieldDriver21Cpy_1; + rostr2<<aMedRdFieldDriver21Cpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT(rostr1.str() == rostr2.str()); + + + //--------------------------Test WRITE ONLY part------------------------------// + + //Copy file + system(cp_other_file.c_str()); + system(cp_file_wr.c_str()); + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Write Only MedFieldDriver21 (file not exist) + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_1 = + new MED_FIELD_WRONLY_DRIVER21<int>(fileNotExist_wr, aField_1); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_1->open(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid Write Only MedFieldDriver21 (empty file name) + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_2 = + new MED_FIELD_WRONLY_DRIVER21<int>(emptyfilename, aField_1); + //Trying open not existing file and file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_2->open(), MEDEXCEPTION); + + /////////////////////////////////////////////////////// + // TEST3: Writing field in empty file without mesh // + /////////////////////////////////////////////////////// + //Creation Invalid Write Only MedFieldDriver21 + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_3 = + new MED_FIELD_WRONLY_DRIVER21<int>(emptyfile_wr, aField); + + aInvalidMedWrFieldDriver21_3->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_3->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + ////////////////////////////////////////////// + // TEST4: Writing field in the other file // + ////////////////////////////////////////////// + + //Creation Invalid Write Only MedFieldDriver21 + MED_FIELD_WRONLY_DRIVER21<int> *aInvalidMedWrFieldDriver21_4 = + new MED_FIELD_WRONLY_DRIVER21<int>(other_file_wr, aField); + aInvalidMedWrFieldDriver21_4->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver21_4->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + //////////////////////// + // TEST5: Main test // + //////////////////////// + + //Creation correct Write Only MedFieldDriver21 + MED_FIELD_WRONLY_DRIVER21<int> *aMedWrFieldDriver21 = + new MED_FIELD_WRONLY_DRIVER21<int>(filename_wr, aField); + + //Check driver + CPPUNIT_ASSERT(aMedWrFieldDriver21); + + //Trying write field before open file +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver21->write(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Test open() method + try + { + aMedWrFieldDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver21->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Test setFieldName() and getFieldName + aField->setName(fieldname_cpy); + try + { + aMedWrFieldDriver21->setFieldName(fieldname_cpy); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fieldname_cpy, aMedWrFieldDriver21->getFieldName()); + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedWrFieldDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + //=>Segmentation fault in this case +#endif + + //Test read() method for Write only part + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver21->read(),MEDEXCEPTION); + + //Test close() method + try + { + aMedWrFieldDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_WRONLY_DRIVER21<int> aMedWrFieldDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedWrFieldDriver21Cpy_1 = *aMedWrFieldDriver21; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aMedWrFieldDriver21Cpy_1.GENDRIVER::operator==(*aMedWrFieldDriver21)); + + //Test copy constructor + MED_FIELD_WRONLY_DRIVER21<int> aMedWrFieldDriver21Cpy_2 (*aMedWrFieldDriver21); + CPPUNIT_ASSERT_EQUAL(aMedWrFieldDriver21Cpy_2, *aMedWrFieldDriver21); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream wostr1, wostr2; + wostr1 << aMedWrFieldDriver21Cpy_1; + wostr2 << aMedWrFieldDriver21Cpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + + //--------------------------Test READ/WRITE part------------------------------// + + //Copy files + system(cp_file_rdwr.c_str()); + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Read/Write MedFieldDriver21 (file not exist) + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_1 = + new MED_FIELD_RDWR_DRIVER21<int>(fileNotExist_wr, aField_1); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_1->open(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver21 (empty file name) + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_2 = + new MED_FIELD_RDWR_DRIVER21<int>(emptyfilename, aField_1); + //Trying open not existing file and file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_2->open(), MEDEXCEPTION); + + ///////////////////////////////////////////////////// + // TEST3: Reading field from file without fields // + ///////////////////////////////////////////////////// + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_3 = + new MED_FIELD_RDWR_DRIVER21<int>(filenameWithOutFileds, aField_1); + aInvalidMedRdWrFieldDriver21_3->open(); + aInvalidMedRdWrFieldDriver21_3->setFieldName(fieldname); + //Trying read field from file + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_3->read(), MEDEXCEPTION); + aInvalidMedRdWrFieldDriver21_3->close(); + + /////////////////////////////////////////////////////// + // TEST4: Writing field in empty file without mesh // + /////////////////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver21 + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_4 = + new MED_FIELD_RDWR_DRIVER21<int>(emptyfile_rdwr, aField); + + aInvalidMedRdWrFieldDriver21_4->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_4->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + ////////////////////////////////////////////// + // TEST6: Writing field in the other file // + ////////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver21 + MED_FIELD_RDWR_DRIVER21<int> *aInvalidMedRdWrFieldDriver21_5 = + new MED_FIELD_RDWR_DRIVER21<int>(other_file_wr, aField); + aInvalidMedRdWrFieldDriver21_5->open(); +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver21_5->write(), MEDEXCEPTION); + //=>Segmentation fault in this case +#endif + + //////////////////////// + // TEST7: Main test // + //////////////////////// + + //Creation correct Read/Write MedFieldDriver21 + MED_FIELD_RDWR_DRIVER21<double> *aMedRdWrFieldDriver21 = + new MED_FIELD_RDWR_DRIVER21<double>(filename_rdwr, aField_2); + + //Check driver + CPPUNIT_ASSERT(aMedRdWrFieldDriver21); + + //Trying read/write field before open file + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->read(),MEDEXCEPTION); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->write(),MEDEXCEPTION); + //(BUG) No exception in this case +#endif + + //Test open() method + try + { + aMedRdWrFieldDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Trying read field from file if field name is empty + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver21->read(), MEDEXCEPTION); + + //Test setFieldName() and getFieldName + try + { + aMedRdWrFieldDriver21->setFieldName(fileldnotexist); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdWrFieldDriver21->getFieldName()); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->read(), MEDEXCEPTION); + + //Test read() method + aMedRdWrFieldDriver21->setFieldName(fieldnameDouble); + try + { + aMedRdWrFieldDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying write field in the file with empty name + aField_2->setName(emptyfilename); + aMedRdWrFieldDriver21->setFieldName(emptyfilename); + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver21->write(), MEDEXCEPTION); + + //Test write() method + aField_2->setName(fieldnameDouble_cpy); + aMedRdWrFieldDriver21->setFieldName(fieldnameDouble_cpy); +#ifdef ENABLE_FAULTS + try + { + aMedRdWrFieldDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + //=>Segmentation fault in this case +#endif + + //Test close() method + try + { + aMedRdWrFieldDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_RDWR_DRIVER21<double> aMedRdWrFieldDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedRdWrFieldDriver21Cpy_1 = *aMedRdWrFieldDriver21; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aMedRdWrFieldDriver21Cpy_1.GENDRIVER::operator==(*aMedRdWrFieldDriver21)); + + //Test copy constructor + MED_FIELD_RDWR_DRIVER21<double> aMedRdWrFieldDriver21Cpy_2 (*aMedRdWrFieldDriver21); + CPPUNIT_ASSERT_EQUAL(aMedRdWrFieldDriver21Cpy_2, *aMedRdWrFieldDriver21); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rwostr1, rwostr2; + rwostr1 << aMedRdWrFieldDriver21Cpy_1; + rwostr2 << aMedRdWrFieldDriver21Cpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aField; + delete aField_1; + delete aField_2; + + delete aInvalidMedRdFieldDriver21_1; + delete aInvalidMedRdFieldDriver21_2; + delete aInvalidMedRdFieldDriver21_3; + delete aMedRdFieldDriver21; + + delete aInvalidMedWrFieldDriver21_1; + delete aInvalidMedWrFieldDriver21_2; + delete aInvalidMedWrFieldDriver21_3; + delete aInvalidMedWrFieldDriver21_4; + delete aMedWrFieldDriver21; + + delete aInvalidMedRdWrFieldDriver21_1; + delete aInvalidMedRdWrFieldDriver21_2; + delete aInvalidMedRdWrFieldDriver21_3; + delete aInvalidMedRdWrFieldDriver21_4; + delete aInvalidMedRdWrFieldDriver21_5; + delete aMedRdWrFieldDriver21; +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testMedFieldDriver21(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver22.cxx b/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver22.cxx new file mode 100644 index 000000000..f3bf94d98 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedFieldDriver22.cxx @@ -0,0 +1,619 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Field.hxx> +#include <MEDMEM_MedFieldDriver22.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +/*! + * Check methods (17), defined in MEDMEM_MedFieldDriver22.hxx: + * template <class T> class MED_FIELD_DRIVER22 : public virtual MED_FIELD_DRIVER<T> { + * (+) MED_FIELD_DRIVER22(); + * (+) template <class INTERLACING_TAG> MED_FIELD_DRIVER22(const string & fileName, + * FIELD<T, INTERLACING_TAG> * ptrField, MED_EN::med_mode_acces accessMode); + * (+) MED_FIELD_DRIVER22(const MED_FIELD_DRIVER22 & fieldDriver); + * (+) virtual ~MED_FIELD_DRIVER22(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * } + * template <class T> class MED_FIELD_RDONLY_DRIVER22 : public virtual MED_FIELD_DRIVER22<T>, + * public virtual IMED_FIELD_RDONLY_DRIVER<T> { + * (+) MED_FIELD_RDONLY_DRIVER22(); + * (+) template <class INTERLACING_TAG> MED_FIELD_RDONLY_DRIVER22 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_RDONLY_DRIVER22(const MED_FIELD_RDONLY_DRIVER22 & fieldDriver); + * (+) virtual ~MED_FIELD_RDONLY_DRIVER22(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * template <class T> class MED_FIELD_WRONLY_DRIVER22 : public virtual MED_FIELD_DRIVER22<T>, + * public virtual IMED_FIELD_WRONLY_DRIVER<T> { + * (+) MED_FIELD_WRONLY_DRIVER22(); + * (+) template <class INTERLACING_TAG> MED_FIELD_WRONLY_DRIVER22 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_WRONLY_DRIVER22(const MED_FIELD_WRONLY_DRIVER22 & fieldDriver); + * (+) virtual ~MED_FIELD_WRONLY_DRIVER22(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * template <class T> class MED_FIELD_RDWR_DRIVER22 : public MED_FIELD_RDONLY_DRIVER22<T>, + * public MED_FIELD_WRONLY_DRIVER22<T>, public IMED_FIELD_RDWR_DRIVER<T> { + * (+) MED_FIELD_RDWR_DRIVER22(); + * (+) template <class INTERLACING_TAG> MED_FIELD_RDWR_DRIVER22 + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField); + * (+) MED_FIELD_RDWR_DRIVER22(const MED_FIELD_RDWR_DRIVER22 & fieldDriver); + * (+) ~MED_FIELD_RDWR_DRIVER22(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testMedFieldDriver22() +{ + FIELD<int> *aField = new FIELD<int> (); + FIELD<int> *aField_1 = new FIELD<int> (); + FIELD<double> *aField_2 = new FIELD<double> (); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filenameWithOutFileds = data_dir + "/MedFiles/Mistrat_import22.med"; + string fileldnotexist = "anyfield"; + string fieldname = "fieldnodeint"; + string fieldname_cpy = fieldname + "_cpy"; + string fileNotExist_rd = "notExist22.med"; + string emptyfilename = ""; + + string filename_wr = tmp_dir + "/myWrField_pointe22.med"; + string cp_file_wr = "cp " + filename_rd + " " + filename_wr; + string fileNotExist_wr = "/path_not_exist/file_not_exist.med"; + string emptyfile_wr = tmp_dir + "/myWrField_pointe_empty22.med"; + string other_file = data_dir + "/MedFiles/cube_hexa8_import22.med"; + string other_file_wr = tmp_dir + "/myWRcube_hexa8_import22.med"; + string cp_other_file = "cp " + other_file + " " + other_file_wr; + + string filename_rdwr = tmp_dir + "/myRdWrField_pointe22.med"; + string cp_file_rdwr = "cp " + filename_rd + " " + filename_rdwr; + string emptyfile_rdwr = tmp_dir + "/myRdWrField_pointe_empty22.med"; + string fieldnameDouble = "fieldnodedouble"; + string fieldnameDouble_cpy = fieldnameDouble + "_cpy"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(emptyfile_wr); + aRemover.Register(other_file_wr); + aRemover.Register(filename_rdwr); + aRemover.Register(emptyfile_rdwr); + + //--------------------------Test READ ONLY part------------------------------// + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Read Only MedFieldDriver22 (file not exist) + MED_FIELD_RDONLY_DRIVER22<int> *aInvalidMedRdFieldDriver22_1 = + new MED_FIELD_RDONLY_DRIVER22<int>(fileNotExist_rd, aField); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver22_1->open(), MEDEXCEPTION); + + ////////////////////////////////////////////// + // TEST2: Open file with empty file name /// + ////////////////////////////////////////////// + + //Creation Invalid Read Only MedFieldDriver22 (empty file name) + MED_FIELD_RDONLY_DRIVER22<int> *aInvalidMedRdFieldDriver22_2 = + new MED_FIELD_RDONLY_DRIVER22<int>(emptyfilename, aField); + //Trying file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver22_2->open(), MEDEXCEPTION); + + ///////////////////////////////////////////////////// + // TEST3: Reading field from file without fields // + ///////////////////////////////////////////////////// + MED_FIELD_RDONLY_DRIVER22<int> *aInvalidMedRdFieldDriver22_3 = + new MED_FIELD_RDONLY_DRIVER22<int>(filenameWithOutFileds, aField); + aInvalidMedRdFieldDriver22_3->open(); + aInvalidMedRdFieldDriver22_3->setFieldName(fieldname); + //Trying read field from file + CPPUNIT_ASSERT_THROW(aInvalidMedRdFieldDriver22_3->read(), MEDEXCEPTION); + aInvalidMedRdFieldDriver22_3->close(); + + //////////////////////// + // TEST4: Main test // + //////////////////////// + //Creation correct Read Only MedFieldDriver22 + MED_FIELD_RDONLY_DRIVER22<int> *aMedRdFieldDriver22 = + new MED_FIELD_RDONLY_DRIVER22<int>(filename_rd, aField); + + //Check driver + CPPUNIT_ASSERT(aMedRdFieldDriver22); + + //Trying read field before open file + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(),MEDEXCEPTION); + + //Test open() method + try + { + aMedRdFieldDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Trying read field form file if it name is empty + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(), MEDEXCEPTION); + + //Test setFieldName() and getFieldName() + try + { + aMedRdFieldDriver22->setFieldName(fileldnotexist); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdFieldDriver22->getFieldName()); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(), MEDEXCEPTION); + + //Test read() method + aMedRdFieldDriver22->setFieldName(fieldname); + try + { + aMedRdFieldDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() method for READ ONLY driver + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->write(), MEDEXCEPTION); + + //Test close() method + try + { + aMedRdFieldDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_RDONLY_DRIVER22<int> aMedRdFieldDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + aMedRdFieldDriver22Cpy_1 = *aMedRdFieldDriver22; + + //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aMedRdFieldDriver22Cpy_1 == *aMedRdFieldDriver22); + + //Test copy constructor + MED_FIELD_RDONLY_DRIVER22<int> aMedRdFieldDriver22Cpy_2 (*aMedRdFieldDriver22); + CPPUNIT_ASSERT_EQUAL(aMedRdFieldDriver22Cpy_2, *aMedRdFieldDriver22); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rostr1, rostr2; + rostr1<<aMedRdFieldDriver22Cpy_1; + rostr2<<aMedRdFieldDriver22Cpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT(rostr1.str() == rostr2.str()); + + + //--------------------------Test WRITE ONLY part------------------------------// + + //Copy file + system(cp_other_file.c_str()); + system(cp_file_wr.c_str()); + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Write Only MedFieldDriver22 (file not exist) + MED_FIELD_WRONLY_DRIVER22<int> *aInvalidMedWrFieldDriver22_1 = + new MED_FIELD_WRONLY_DRIVER22<int>(fileNotExist_wr, aField_1); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_1->open(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid Write Only MedFieldDriver22 (empty file name) + MED_FIELD_WRONLY_DRIVER22<int> *aInvalidMedWrFieldDriver22_2 = + new MED_FIELD_WRONLY_DRIVER22<int>(emptyfilename, aField_1); + //Trying open not existing file and file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_2->open(), MEDEXCEPTION); + + /////////////////////////////////////////////////////// + // TEST3: Writing field in empty file without mesh // + /////////////////////////////////////////////////////// + //Creation Invalid Write Only MedFieldDriver22 + MED_FIELD_WRONLY_DRIVER22<int> *aInvalidMedWrFieldDriver22_3 = + new MED_FIELD_WRONLY_DRIVER22<int>(emptyfile_wr, aField); + + aInvalidMedWrFieldDriver22_3->open(); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_3->write(), MEDEXCEPTION); + //(Bug) No Exception in this case + aInvalidMedWrFieldDriver22_3->close(); +#endif + + ////////////////////////////////////////////// + // TEST4: Writing field in the other file // + ////////////////////////////////////////////// + + //Creation Invalid Write Only MedFieldDriver22 + MED_FIELD_WRONLY_DRIVER22<int> *aInvalidMedWrFieldDriver22_4 = + new MED_FIELD_WRONLY_DRIVER22<int>(other_file_wr, aField); + aInvalidMedWrFieldDriver22_4->open(); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aInvalidMedWrFieldDriver22_4->write(), MEDEXCEPTION); + //(Bug) No Exception in this case +#endif + + //////////////////////// + // TEST5: Main test // + //////////////////////// + + //Creation correct Write Only MedFieldDriver22 + MED_FIELD_WRONLY_DRIVER22<int> *aMedWrFieldDriver22 = + new MED_FIELD_WRONLY_DRIVER22<int>(filename_wr, aField); + + //Check driver + CPPUNIT_ASSERT(aMedWrFieldDriver22); + + //Trying write field before open file +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver22->write(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Test open() method + try + { + aMedWrFieldDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver22->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Test setFieldName() and getFieldName + aField->setName(fieldname_cpy); + try + { + aMedWrFieldDriver22->setFieldName(fieldname_cpy); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fieldname_cpy, aMedWrFieldDriver22->getFieldName()); + + //Test write() method + try + { + aMedWrFieldDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method for Write only part + CPPUNIT_ASSERT_THROW(aMedWrFieldDriver22->read(),MEDEXCEPTION); + + //Test close() method + try + { + aMedWrFieldDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_WRONLY_DRIVER22<int> aMedWrFieldDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedWrFieldDriver22Cpy_1 = *aMedWrFieldDriver22; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aMedWrFieldDriver22Cpy_1.GENDRIVER::operator==(*aMedWrFieldDriver22)); + + //Test copy constructor + MED_FIELD_WRONLY_DRIVER22<int> aMedWrFieldDriver22Cpy_2 (*aMedWrFieldDriver22); + CPPUNIT_ASSERT_EQUAL(aMedWrFieldDriver22Cpy_2, *aMedWrFieldDriver22); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream wostr1, wostr2; + wostr1 << aMedWrFieldDriver22Cpy_1; + wostr2 << aMedWrFieldDriver22Cpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + + //--------------------------Test READ/WRITE part------------------------------// + + //Copy files + system(cp_file_rdwr.c_str()); + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + + //Creation Invalid Read/Write MedFieldDriver22 (file not exist) + MED_FIELD_RDWR_DRIVER22<int> *aInvalidMedRdWrFieldDriver22_1 = + new MED_FIELD_RDWR_DRIVER22<int>(fileNotExist_wr, aField_1); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_1->open(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid Read/Write MedFieldDriver22 (empty file name) + MED_FIELD_RDWR_DRIVER22<int> *aInvalidMedRdWrFieldDriver22_2 = + new MED_FIELD_RDWR_DRIVER22<int>(emptyfilename, aField_1); + //Trying open not existing file and file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_2->open(), MEDEXCEPTION); + + ///////////////////////////////////////////////////// + // TEST3: Reading field from file without fields // + ///////////////////////////////////////////////////// + MED_FIELD_RDWR_DRIVER22<int> *aInvalidMedRdWrFieldDriver22_3 = + new MED_FIELD_RDWR_DRIVER22<int>(filenameWithOutFileds, aField_1); + aInvalidMedRdWrFieldDriver22_3->open(); + aInvalidMedRdWrFieldDriver22_3->setFieldName(fieldname); + //Trying read field from file + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_3->read(), MEDEXCEPTION); + aInvalidMedRdWrFieldDriver22_3->close(); + + /////////////////////////////////////////////////////// + // TEST4: Writing field in empty file without mesh // + /////////////////////////////////////////////////////// + + //Creation Invalid Read/Write MedFieldDriver22 + MED_FIELD_RDWR_DRIVER22<int> *aInvalidMedRdWrFieldDriver22_4 = + new MED_FIELD_RDWR_DRIVER22<int>(emptyfile_rdwr, aField); + + aInvalidMedRdWrFieldDriver22_4->open(); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_4->write(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + ////////////////////////////////////////////// + // TEST6: Writing field in the other file // + ////////////////////////////////////////////// + + //Creation Invalid Read/Write MedFieldDriver22 + MED_FIELD_RDWR_DRIVER22<int> *aInvalidMedRdWrFieldDriver22_5 = + new MED_FIELD_RDWR_DRIVER22<int>(other_file_wr, aField); + aInvalidMedRdWrFieldDriver22_5->open(); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aInvalidMedRdWrFieldDriver22_5->write(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //////////////////////// + // TEST7: Main test // + //////////////////////// + + //Creation correct Read/Write MedFieldDriver22 + MED_FIELD_RDWR_DRIVER22<double> *aMedRdWrFieldDriver22 = + new MED_FIELD_RDWR_DRIVER22<double>(filename_rdwr, aField_2); + + //Check driver + CPPUNIT_ASSERT(aMedRdWrFieldDriver22); + + //Trying read/write field before open file + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->read(),MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->write(),MEDEXCEPTION); + + //Test open() method + try + { + aMedRdWrFieldDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->open(), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + + //Trying read field from file if field name is empty + CPPUNIT_ASSERT_THROW(aMedRdFieldDriver22->read(), MEDEXCEPTION); + + //Test setFieldName() and getFieldName + try + { + aMedRdWrFieldDriver22->setFieldName(fileldnotexist); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fileldnotexist, aMedRdWrFieldDriver22->getFieldName()); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->read(), MEDEXCEPTION); + + //Test read() method + aMedRdWrFieldDriver22->setFieldName(fieldnameDouble); + try + { + aMedRdWrFieldDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying write field in the file with empty name + aField_2->setName(emptyfilename); + aMedRdWrFieldDriver22->setFieldName(emptyfilename); + CPPUNIT_ASSERT_THROW(aMedRdWrFieldDriver22->write(), MEDEXCEPTION); + + //Test write() method + aField_2->setName(fieldnameDouble_cpy); + aMedRdWrFieldDriver22->setFieldName(fieldnameDouble_cpy); + try + { + aMedRdWrFieldDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test close() method + try + { + aMedRdWrFieldDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_FIELD_RDWR_DRIVER22<double> aMedRdWrFieldDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedRdWrFieldDriver22Cpy_1 = *aMedRdWrFieldDriver22; + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aMedRdWrFieldDriver22Cpy_1.GENDRIVER::operator==(*aMedRdWrFieldDriver22)); + + //Test copy constructor + MED_FIELD_RDWR_DRIVER22<double> aMedRdWrFieldDriver22Cpy_2 (*aMedRdWrFieldDriver22); + CPPUNIT_ASSERT_EQUAL(aMedRdWrFieldDriver22Cpy_2, *aMedRdWrFieldDriver22); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rwostr1, rwostr2; + rwostr1 << aMedRdWrFieldDriver22Cpy_1; + rwostr2 << aMedRdWrFieldDriver22Cpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aField; + delete aField_1; + delete aField_2; + + delete aInvalidMedRdFieldDriver22_1; + delete aInvalidMedRdFieldDriver22_2; + delete aInvalidMedRdFieldDriver22_3; + delete aMedRdFieldDriver22; + + delete aInvalidMedWrFieldDriver22_1; + delete aInvalidMedWrFieldDriver22_2; + delete aInvalidMedWrFieldDriver22_3; + delete aInvalidMedWrFieldDriver22_4; + delete aMedWrFieldDriver22; + + delete aInvalidMedRdWrFieldDriver22_1; + delete aInvalidMedRdWrFieldDriver22_2; + delete aInvalidMedRdWrFieldDriver22_3; + delete aInvalidMedRdWrFieldDriver22_4; + delete aInvalidMedRdWrFieldDriver22_5; + delete aMedRdWrFieldDriver22; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedMedDriver21.cxx b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver21.cxx new file mode 100644 index 000000000..53bccf034 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver21.cxx @@ -0,0 +1,523 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Compatibility21_22.hxx> +#include <MEDMEM_MedMedDriver21.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (21), defined in MEDMEM_MedMedDriver21.hxx: + * class MED_MED_DRIVER21 : public virtual MED_MED_DRIVER { + * (+) MED_MED_DRIVER21(); + * (+) MED_MED_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_DRIVER21(const string & fileName, MED * const ptrMed, + * MED_EN::med_mode_acces accessMode); + * (+) MED_MED_DRIVER21(const MED_MED_DRIVER21 & driver); + * (+) virtual ~MED_MED_DRIVER21(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * (+) virtual void write (void) const; + * (+) virtual void writeFrom (void) const; + * (+) virtual void read (void); + * (+) virtual void readFileStruct (void); + * } + * class MED_MED_RDONLY_DRIVER21 : public virtual IMED_MED_RDONLY_DRIVER, + * public virtual MED_MED_DRIVER21 { + * (+) MED_MED_RDONLY_DRIVER21(); + * (+) MED_MED_RDONLY_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDONLY_DRIVER21(const MED_MED_RDONLY_DRIVER21 & driver); + * (+) virtual ~MED_MED_RDONLY_DRIVER21(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_WRONLY_DRIVER21 : public virtual IMED_MED_WRONLY_DRIVER, + * public virtual MED_MED_DRIVER21 { + * (+) MED_MED_WRONLY_DRIVER21(); + * (+) MED_MED_WRONLY_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_WRONLY_DRIVER21(const MED_MED_WRONLY_DRIVER21 & driver); + * (+) virtual ~MED_MED_WRONLY_DRIVER21(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_RDWR_DRIVER21 : public MED_MED_RDONLY_DRIVER21, + * public MED_MED_WRONLY_DRIVER21, + * public IMED_MED_RDWR_DRIVER { + * (+) MED_MED_RDWR_DRIVER21(); + * (+) MED_MED_RDWR_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDWR_DRIVER21(const MED_MED_RDWR_DRIVER21 & driver); + * (+) ~MED_MED_RDWR_DRIVER21(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testMedMedDriver21() { + MED *aMed = new MED(); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if(tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string emptyfilename = ""; + string filename_wr = tmp_dir + "/myMedWr_pointe21.med"; + string fileNotExistsName_rd = "notExists.med"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.med"; + string filename_rdwr = tmp_dir + "/myMedRdWr_pointe21.med"; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + + //Copy file in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + + //-------------------------------Test READ_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med read only driver (file is not exist) + MED_MED_RDONLY_DRIVER21 *aInvalidMedMedRdDriver21 = new MED_MED_RDONLY_DRIVER21(fileNotExistsName_rd, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver21->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read only driver (with empty file name) + MED_MED_RDONLY_DRIVER21 *aInvalidMedMedRdDriver21_1 = new MED_MED_RDONLY_DRIVER21(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver21_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read only driver (normal constructor) + MED_MED_RDONLY_DRIVER21 *aMedMedRdDriver21 = new MED_MED_RDONLY_DRIVER21(filename_rd, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdDriver21); + + //Trying read mesh from file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->readFileStruct(),MEDEXCEPTION); + + //Test open() method + try + { + aMedMedRdDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test read() method + try + { + aMedMedRdDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdDriver21->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() and WriteFrom() methods for READ_ONLY part + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->writeFrom(), MEDEXCEPTION); + + //Check MED + CPPUNIT_ASSERT(aMed); + + //Test close() method + try + { + aMedMedRdDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDONLY_DRIVER21 aMedMedRdDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedRdDriver21Cpy_1 = *aMedMedRdDriver21; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDONLY_DRIVER21 aMedMedRdDriver21Cpy_2 (*aMedMedRdDriver21); + // (BUG) => Segmentation fault, because _concreteMedDrv is NULL + // Process terminating with default action of signal 11 (SIGSEGV) + // Access not within mapped region at address 0x0 + // at 0x34881A7A: MEDMEM::MED_MED_DRIVER::MED_MED_DRIVER(MEDMEM::MED_MED_DRIVER const&) (MEDMEM_MedMedDriver.cxx:56) + // by 0x34A07786: MEDMEM::MED_MED_RDONLY_DRIVER21::MED_MED_RDONLY_DRIVER21(MEDMEM::MED_MED_RDONLY_DRIVER21 const&) (MEDMEM_MedMedDriver21.cxx:179) + // by 0x343A02AD: MEDMEMTest::testMedMedDriver21() (MEDMEMTest_MedMedDriver21.cxx:219) +#endif + + //CPPUNIT_ASSERT_EQUAL(aMedMedRdDriver21Cpy_2, *aMedMedRdDriver21); + + //Test (bool operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + //CPPUNIT_ASSERT(aMedMedRdDriver21Cpy_2.GENDRIVER::operator==(*aMedMedRdDriver21)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdDriver21Cpy_1; + //rwostr2<<aMedMedRdDriver21Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //-------------------------------Test WRITE_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med write only driver (file is not exist) + MED_MED_WRONLY_DRIVER21 *aInvalidMedMedWrDriver21 = new MED_MED_WRONLY_DRIVER21(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver21->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med write only driver (with empty file name) + MED_MED_WRONLY_DRIVER21 *aInvalidMedMedWrDriver21_1 = new MED_MED_WRONLY_DRIVER21(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver21_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med write only driver (normal constructor) + MED_MED_WRONLY_DRIVER21 *aMedMedWrDriver21 = new MED_MED_WRONLY_DRIVER21(filename_wr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedWrDriver21); + + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver21->writeFrom(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedWrDriver21->write(), MEDEXCEPTION); + //(BUG) => Segmentation fault +#endif + + //Test open() method + try + { + aMedMedWrDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver21->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test writeFrom() method + try + { + aMedMedWrDriver21->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedWrDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // (BUG) => terminate called after throwing an instance of 'std::length_error' + // what(): basic_string::_S_create +#endif + + //Test close method + try + { + aMedMedWrDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_WRONLY_DRIVER21 aMedMedWrDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedWrDriver21Cpy_1 = *aMedMedWrDriver21; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_WRONLY_DRIVER21 aMedMedWrDriver21Cpy_2 (*aMedMedWrDriver21); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedWrDriver21Cpy_2, *aMedMedWrDriver21); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedWrDriver21Cpy_2.GENDRIVER::operator==(*aMedMedWrDriver21)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedWrDriver21Cpy_1; + //rwostr2<<aMedMedWrDriver21Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + +//-------------------------------Test READ/WRITE part------------------------------------------------------- + //Creation incorrect Med_Med read/write driver (file is not exist) + MED_MED_RDWR_DRIVER21 *aInvalidMedMedRdWrDriver21 = new MED_MED_RDWR_DRIVER21(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver21->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read/write driver (with empty file name) + MED_MED_RDWR_DRIVER21 *aInvalidMedMedRdWrDriver21_1 = new MED_MED_RDWR_DRIVER21(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver21_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read/write driver (normal constructor) + MED_MED_RDWR_DRIVER21 *aMedMedRdWrDriver21 = new MED_MED_RDWR_DRIVER21(filename_rdwr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdWrDriver21); + + //Trying read MED from file if it is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->readFileStruct(),MEDEXCEPTION); + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver21->writeFrom(),MEDEXCEPTION); + // (BUG) => No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver21->write(), MEDEXCEPTION); + //(BUG) => Crash +#endif + + //Test open() method + try + { + aMedMedRdWrDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver21->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test readFileStruct() method + try + { + aMedMedRdWrDriver21->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdWrDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test writeFrom() method + try + { + aMedMedRdWrDriver21->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedRdWrDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#endif + + //Test close() method + try + { + aMedMedRdWrDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDWR_DRIVER21 aMedMedRdWrDriver21Cpy_1; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDWR_DRIVER21 aMedMedRdWrDriver21Cpy_2 (*aMedMedRdWrDriver21); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedRdWrDriver21Cpy_2, *aMedMedRdWrDriver21); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedRdWrDriver21Cpy_2.GENDRIVER::operator==(*aMedMedRdWrDriver21)); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdWrDriver21Cpy_1; + //rwostr2<<aMedMedRdWrDriver21Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aMed; + delete aInvalidMedMedRdDriver21; + delete aInvalidMedMedRdDriver21_1; + delete aMedMedRdDriver21; + + delete aInvalidMedMedWrDriver21; + delete aInvalidMedMedWrDriver21_1; + delete aMedMedWrDriver21; + + delete aInvalidMedMedRdWrDriver21; + delete aInvalidMedMedRdWrDriver21_1; + delete aMedMedRdWrDriver21; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedMedDriver21_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver21_fault.cxx new file mode 100644 index 000000000..fb5872052 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver21_fault.cxx @@ -0,0 +1,528 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Compatibility21_22.hxx> +#include <MEDMEM_MedMedDriver21.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (21), defined in MEDMEM_MedMedDriver21.hxx: + * class MED_MED_DRIVER21 : public virtual MED_MED_DRIVER { + * (+) MED_MED_DRIVER21(); + * (+) MED_MED_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_DRIVER21(const string & fileName, MED * const ptrMed, + * MED_EN::med_mode_acces accessMode); + * (+) MED_MED_DRIVER21(const MED_MED_DRIVER21 & driver); + * (+) virtual ~MED_MED_DRIVER21(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * (+) virtual void write (void) const; + * (+) virtual void writeFrom (void) const; + * (+) virtual void read (void); + * (+) virtual void readFileStruct (void); + * } + * class MED_MED_RDONLY_DRIVER21 : public virtual IMED_MED_RDONLY_DRIVER, + * public virtual MED_MED_DRIVER21 { + * (+) MED_MED_RDONLY_DRIVER21(); + * (+) MED_MED_RDONLY_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDONLY_DRIVER21(const MED_MED_RDONLY_DRIVER21 & driver); + * (+) virtual ~MED_MED_RDONLY_DRIVER21(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_WRONLY_DRIVER21 : public virtual IMED_MED_WRONLY_DRIVER, + * public virtual MED_MED_DRIVER21 { + * (+) MED_MED_WRONLY_DRIVER21(); + * (+) MED_MED_WRONLY_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_WRONLY_DRIVER21(const MED_MED_WRONLY_DRIVER21 & driver); + * (+) virtual ~MED_MED_WRONLY_DRIVER21(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_RDWR_DRIVER21 : public MED_MED_RDONLY_DRIVER21, + * public MED_MED_WRONLY_DRIVER21, + * public IMED_MED_RDWR_DRIVER { + * (+) MED_MED_RDWR_DRIVER21(); + * (+) MED_MED_RDWR_DRIVER21(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDWR_DRIVER21(const MED_MED_RDWR_DRIVER21 & driver); + * (+) ~MED_MED_RDWR_DRIVER21(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest_testMedMedDriver21() { + MED *aMed = new MED(); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if(tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string emptyfilename = ""; + string filename_wr = tmp_dir + "/myMedWr_pointe21.med"; + string fileNotExistsName_rd = "notExists.med"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.med"; + string filename_rdwr = tmp_dir + "/myMedRdWr_pointe21.med"; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + + //Copy file in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + + //-------------------------------Test READ_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med read only driver (file is not exist) + MED_MED_RDONLY_DRIVER21 *aInvalidMedMedRdDriver21 = new MED_MED_RDONLY_DRIVER21(fileNotExistsName_rd, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver21->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read only driver (with empty file name) + MED_MED_RDONLY_DRIVER21 *aInvalidMedMedRdDriver21_1 = new MED_MED_RDONLY_DRIVER21(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver21_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read only driver (normal constructor) + MED_MED_RDONLY_DRIVER21 *aMedMedRdDriver21 = new MED_MED_RDONLY_DRIVER21(filename_rd, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdDriver21); + + //Trying read mesh from file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->readFileStruct(),MEDEXCEPTION); + + //Test open() method + try + { + aMedMedRdDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test read() method + try + { + aMedMedRdDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdDriver21->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() and WriteFrom() methods for READ_ONLY part + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->writeFrom(), MEDEXCEPTION); + + //Check MED + CPPUNIT_ASSERT(aMed); + + //Test close() method + try + { + aMedMedRdDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDONLY_DRIVER21 aMedMedRdDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedRdDriver21Cpy_1 = *aMedMedRdDriver21; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDONLY_DRIVER21 aMedMedRdDriver21Cpy_2 (*aMedMedRdDriver21); + // (BUG) => Segmentation fault, because _concreteMedDrv is NULL + // Process terminating with default action of signal 11 (SIGSEGV) + // Access not within mapped region at address 0x0 + // at 0x34881A7A: MEDMEM::MED_MED_DRIVER::MED_MED_DRIVER(MEDMEM::MED_MED_DRIVER const&) (MEDMEM_MedMedDriver.cxx:56) + // by 0x34A07786: MEDMEM::MED_MED_RDONLY_DRIVER21::MED_MED_RDONLY_DRIVER21(MEDMEM::MED_MED_RDONLY_DRIVER21 const&) (MEDMEM_MedMedDriver21.cxx:179) + // by 0x343A02AD: MEDMEMTest::testMedMedDriver21() (MEDMEMTest_MedMedDriver21.cxx:219) +#endif + + //CPPUNIT_ASSERT_EQUAL(aMedMedRdDriver21Cpy_2, *aMedMedRdDriver21); + + //Test (bool operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + //CPPUNIT_ASSERT(aMedMedRdDriver21Cpy_2.GENDRIVER::operator==(*aMedMedRdDriver21)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdDriver21Cpy_1; + //rwostr2<<aMedMedRdDriver21Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //-------------------------------Test WRITE_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med write only driver (file is not exist) + MED_MED_WRONLY_DRIVER21 *aInvalidMedMedWrDriver21 = new MED_MED_WRONLY_DRIVER21(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver21->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med write only driver (with empty file name) + MED_MED_WRONLY_DRIVER21 *aInvalidMedMedWrDriver21_1 = new MED_MED_WRONLY_DRIVER21(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver21_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med write only driver (normal constructor) + MED_MED_WRONLY_DRIVER21 *aMedMedWrDriver21 = new MED_MED_WRONLY_DRIVER21(filename_wr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedWrDriver21); + + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver21->writeFrom(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedWrDriver21->write(), MEDEXCEPTION); + //(BUG) => Segmentation fault +#endif + + //Test open() method + try + { + aMedMedWrDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver21->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test writeFrom() method + try + { + aMedMedWrDriver21->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedWrDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // (BUG) => terminate called after throwing an instance of 'std::length_error' + // what(): basic_string::_S_create +#endif + + //Test close method + try + { + aMedMedWrDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_WRONLY_DRIVER21 aMedMedWrDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedWrDriver21Cpy_1 = *aMedMedWrDriver21; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_WRONLY_DRIVER21 aMedMedWrDriver21Cpy_2 (*aMedMedWrDriver21); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedWrDriver21Cpy_2, *aMedMedWrDriver21); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedWrDriver21Cpy_2.GENDRIVER::operator==(*aMedMedWrDriver21)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedWrDriver21Cpy_1; + //rwostr2<<aMedMedWrDriver21Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + +//-------------------------------Test READ/WRITE part------------------------------------------------------- + //Creation incorrect Med_Med read/write driver (file is not exist) + MED_MED_RDWR_DRIVER21 *aInvalidMedMedRdWrDriver21 = new MED_MED_RDWR_DRIVER21(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver21->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read/write driver (with empty file name) + MED_MED_RDWR_DRIVER21 *aInvalidMedMedRdWrDriver21_1 = new MED_MED_RDWR_DRIVER21(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver21_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read/write driver (normal constructor) + MED_MED_RDWR_DRIVER21 *aMedMedRdWrDriver21 = new MED_MED_RDWR_DRIVER21(filename_rdwr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdWrDriver21); + + //Trying read MED from file if it is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver21->readFileStruct(),MEDEXCEPTION); + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver21->writeFrom(),MEDEXCEPTION); + // (BUG) => No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver21->write(), MEDEXCEPTION); + //(BUG) => Crash +#endif + + //Test open() method + try + { + aMedMedRdWrDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver21->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test readFileStruct() method + try + { + aMedMedRdWrDriver21->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdWrDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test writeFrom() method + try + { + aMedMedRdWrDriver21->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedRdWrDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#endif + + //Test close() method + try + { + aMedMedRdWrDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDWR_DRIVER21 aMedMedRdWrDriver21Cpy_1; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDWR_DRIVER21 aMedMedRdWrDriver21Cpy_2 (*aMedMedRdWrDriver21); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedRdWrDriver21Cpy_2, *aMedMedRdWrDriver21); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedRdWrDriver21Cpy_2.GENDRIVER::operator==(*aMedMedRdWrDriver21)); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdWrDriver21Cpy_1; + //rwostr2<<aMedMedRdWrDriver21Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aMed; + delete aInvalidMedMedRdDriver21; + delete aInvalidMedMedRdDriver21_1; + delete aMedMedRdDriver21; + + delete aInvalidMedMedWrDriver21; + delete aInvalidMedMedWrDriver21_1; + delete aMedMedWrDriver21; + + delete aInvalidMedMedRdWrDriver21; + delete aInvalidMedMedRdWrDriver21_1; + delete aMedMedRdWrDriver21; +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testMedMedDriver21(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedMedDriver22.cxx b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver22.cxx new file mode 100644 index 000000000..dc09f5e03 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver22.cxx @@ -0,0 +1,517 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Compatibility21_22.hxx> +#include <MEDMEM_MedMedDriver22.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (21), defined in MEDMEM_MedMedDriver22.hxx: + * class MED_MED_DRIVER22 : public virtual MED_MED_DRIVER { + * (+) MED_MED_DRIVER22(); + * (+) MED_MED_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_DRIVER22(const string & fileName, MED * const ptrMed, + * MED_EN::med_mode_acces accessMode); + * (+) MED_MED_DRIVER22(const MED_MED_DRIVER22 & driver); + * (+) virtual ~MED_MED_DRIVER22(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * (+) virtual void write (void) const; + * (+) virtual void writeFrom (void) const; + * (+) virtual void read (void); + * (+) virtual void readFileStruct (void); + * } + * class MED_MED_RDONLY_DRIVER22 : public virtual IMED_MED_RDONLY_DRIVER, + * public virtual MED_MED_DRIVER22 { + * (+) MED_MED_RDONLY_DRIVER22(); + * (+) MED_MED_RDONLY_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDONLY_DRIVER22(const MED_MED_RDONLY_DRIVER22 & driver); + * (+) virtual ~MED_MED_RDONLY_DRIVER22(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_WRONLY_DRIVER22 : public virtual IMED_MED_WRONLY_DRIVER, + * public virtual MED_MED_DRIVER22 { + * (+) MED_MED_WRONLY_DRIVER22(); + * (+) MED_MED_WRONLY_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_WRONLY_DRIVER22(const MED_MED_WRONLY_DRIVER22 & driver); + * (+) virtual ~MED_MED_WRONLY_DRIVER22(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_RDWR_DRIVER22 : public virtual MED_MED_RDONLY_DRIVER22, + * public virtual MED_MED_WRONLY_DRIVER22, + * public virtual IMED_MED_RDWR_DRIVER { + * (+) MED_MED_RDWR_DRIVER22(); + * (+) MED_MED_RDWR_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDWR_DRIVER22(const MED_MED_RDWR_DRIVER22 & driver); + * (+) ~MED_MED_RDWR_DRIVER22(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testMedMedDriver22() { + MED *aMed = new MED(); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if(tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string emptyfilename = ""; + string filename_wr = tmp_dir + "/myMedWr_pointe22.med"; + string fileNotExistsName_rd = "notExists.med"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.med"; + string filename_rdwr = tmp_dir + "/myMedRdWr_pointe22.med"; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + + //Copy file in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + + //-------------------------------Test READ_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med read only driver (file is not exist) + MED_MED_RDONLY_DRIVER22 *aInvalidMedMedRdDriver22 = new MED_MED_RDONLY_DRIVER22(fileNotExistsName_rd, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver22->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read only driver (with empty file name) + MED_MED_RDONLY_DRIVER22 *aInvalidMedMedRdDriver22_1 = new MED_MED_RDONLY_DRIVER22(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver22_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read only driver (normal constructor) + MED_MED_RDONLY_DRIVER22 *aMedMedRdDriver22 = new MED_MED_RDONLY_DRIVER22(filename_rd, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdDriver22); + + //Trying read mesh from file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->readFileStruct(),MEDEXCEPTION); + + //Test open() method + try + { + aMedMedRdDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test read() method + try + { + aMedMedRdDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdDriver22->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() and WriteFrom() methods for READ_ONLY part + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->writeFrom(), MEDEXCEPTION); + + //Check MED + CPPUNIT_ASSERT(aMed); + + //Test close() method + try + { + aMedMedRdDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDONLY_DRIVER22 aMedMedRdDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedRdDriver22Cpy_1 = *aMedMedRdDriver22; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDONLY_DRIVER22 aMedMedRdDriver22Cpy_2 (*aMedMedRdDriver22); + // (BUG) => Segmentation fault, because _concreteMedDrv is NULL +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedRdDriver22Cpy_2, *aMedMedRdDriver22); + + //Test (bool operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + //CPPUNIT_ASSERT(aMedMedRdDriver22Cpy_2.GENDRIVER::operator==(*aMedMedRdDriver22)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdDriver22Cpy_1; + //rwostr2<<aMedMedRdDriver22Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //-------------------------------Test WRITE_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med write only driver (file is not exist) + MED_MED_WRONLY_DRIVER22 *aInvalidMedMedWrDriver22 = new MED_MED_WRONLY_DRIVER22(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver22->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med write only driver (with empty file name) + MED_MED_WRONLY_DRIVER22 *aInvalidMedMedWrDriver22_1 = new MED_MED_WRONLY_DRIVER22(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver22_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med write only driver (normal constructor) + MED_MED_WRONLY_DRIVER22 *aMedMedWrDriver22 = new MED_MED_WRONLY_DRIVER22(filename_wr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedWrDriver22); + + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver22->writeFrom(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedWrDriver22->write(), MEDEXCEPTION); + //(BUG) => Segmentation fault +#endif + + //Test open() method + try + { + aMedMedWrDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver22->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test writeFrom() method + try + { + aMedMedWrDriver22->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedWrDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // (BUG) => terminate called after throwing an instance of 'std::length_error' + // what(): basic_string::_S_create +#endif + + //Test close method + try + { + aMedMedWrDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_WRONLY_DRIVER22 aMedMedWrDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedWrDriver22Cpy_1 = *aMedMedWrDriver22; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_WRONLY_DRIVER22 aMedMedWrDriver22Cpy_2 (*aMedMedWrDriver22); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedWrDriver22Cpy_2, *aMedMedWrDriver22); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedWrDriver22Cpy_2.GENDRIVER::operator==(*aMedMedWrDriver22)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedWrDriver22Cpy_1; + //rwostr2<<aMedMedWrDriver22Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + +//-------------------------------Test READ/WRITE part------------------------------------------------------- + //Creation incorrect Med_Med read/write driver (file is not exist) + MED_MED_RDWR_DRIVER22 *aInvalidMedMedRdWrDriver22 = new MED_MED_RDWR_DRIVER22(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver22->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read/write driver (with empty file name) + MED_MED_RDWR_DRIVER22 *aInvalidMedMedRdWrDriver22_1 = new MED_MED_RDWR_DRIVER22(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver22_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read/write driver (normal constructor) + MED_MED_RDWR_DRIVER22 *aMedMedRdWrDriver22 = new MED_MED_RDWR_DRIVER22(filename_rdwr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdWrDriver22); + + //Trying read MED from file if it is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->readFileStruct(),MEDEXCEPTION); + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver22->writeFrom(),MEDEXCEPTION); + // (BUG) => No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver22->write(), MEDEXCEPTION); + //(BUG) => Crash +#endif + + //Test open() method + try + { + aMedMedRdWrDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver22->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test readFileStruct() method + try + { + aMedMedRdWrDriver22->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdWrDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test writeFrom() method + try + { + aMedMedRdWrDriver22->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedRdWrDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#endif + + //Test close() method + try + { + aMedMedRdWrDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDWR_DRIVER22 aMedMedRdWrDriver22Cpy_1; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDWR_DRIVER22 aMedMedRdWrDriver22Cpy_2 (*aMedMedRdWrDriver22); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedRdWrDriver22Cpy_2, *aMedMedRdWrDriver22); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedRdWrDriver22Cpy_2.GENDRIVER::operator==(*aMedMedRdWrDriver22)); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdWrDriver22Cpy_1; + //rwostr2<<aMedMedRdWrDriver22Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aMed; + delete aInvalidMedMedRdDriver22; + delete aInvalidMedMedRdDriver22_1; + delete aMedMedRdDriver22; + + delete aInvalidMedMedWrDriver22; + delete aInvalidMedMedWrDriver22_1; + delete aMedMedWrDriver22; + + delete aInvalidMedMedRdWrDriver22; + delete aInvalidMedMedRdWrDriver22_1; + delete aMedMedRdWrDriver22; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedMedDriver22_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver22_fault.cxx new file mode 100644 index 000000000..4c3806c3a --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedMedDriver22_fault.cxx @@ -0,0 +1,522 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Compatibility21_22.hxx> +#include <MEDMEM_MedMedDriver22.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (21), defined in MEDMEM_MedMedDriver22.hxx: + * class MED_MED_DRIVER22 : public virtual MED_MED_DRIVER { + * (+) MED_MED_DRIVER22(); + * (+) MED_MED_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_DRIVER22(const string & fileName, MED * const ptrMed, + * MED_EN::med_mode_acces accessMode); + * (+) MED_MED_DRIVER22(const MED_MED_DRIVER22 & driver); + * (+) virtual ~MED_MED_DRIVER22(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close(); + * (+) virtual void write (void) const; + * (+) virtual void writeFrom (void) const; + * (+) virtual void read (void); + * (+) virtual void readFileStruct (void); + * } + * class MED_MED_RDONLY_DRIVER22 : public virtual IMED_MED_RDONLY_DRIVER, + * public virtual MED_MED_DRIVER22 { + * (+) MED_MED_RDONLY_DRIVER22(); + * (+) MED_MED_RDONLY_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDONLY_DRIVER22(const MED_MED_RDONLY_DRIVER22 & driver); + * (+) virtual ~MED_MED_RDONLY_DRIVER22(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_WRONLY_DRIVER22 : public virtual IMED_MED_WRONLY_DRIVER, + * public virtual MED_MED_DRIVER22 { + * (+) MED_MED_WRONLY_DRIVER22(); + * (+) MED_MED_WRONLY_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_WRONLY_DRIVER22(const MED_MED_WRONLY_DRIVER22 & driver); + * (+) virtual ~MED_MED_WRONLY_DRIVER22(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + * class MED_MED_RDWR_DRIVER22 : public virtual MED_MED_RDONLY_DRIVER22, + * public virtual MED_MED_WRONLY_DRIVER22, + * public virtual IMED_MED_RDWR_DRIVER { + * (+) MED_MED_RDWR_DRIVER22(); + * (+) MED_MED_RDWR_DRIVER22(const string & fileName, MED * const ptrMed); + * (+) MED_MED_RDWR_DRIVER22(const MED_MED_RDWR_DRIVER22 & driver); + * (+) ~MED_MED_RDWR_DRIVER22(); + * (+) void write (void) const throw (MEDEXCEPTION); + * (+) void writeFrom (void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void readFileStruct (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest_testMedMedDriver22() { + MED *aMed = new MED(); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if(tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string emptyfilename = ""; + string filename_wr = tmp_dir + "/myMedWr_pointe22.med"; + string fileNotExistsName_rd = "notExists.med"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.med"; + string filename_rdwr = tmp_dir + "/myMedRdWr_pointe22.med"; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + + //Copy file in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + + //-------------------------------Test READ_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med read only driver (file is not exist) + MED_MED_RDONLY_DRIVER22 *aInvalidMedMedRdDriver22 = new MED_MED_RDONLY_DRIVER22(fileNotExistsName_rd, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver22->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read only driver (with empty file name) + MED_MED_RDONLY_DRIVER22 *aInvalidMedMedRdDriver22_1 = new MED_MED_RDONLY_DRIVER22(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdDriver22_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read only driver (normal constructor) + MED_MED_RDONLY_DRIVER22 *aMedMedRdDriver22 = new MED_MED_RDONLY_DRIVER22(filename_rd, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdDriver22); + + //Trying read mesh from file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->readFileStruct(),MEDEXCEPTION); + + //Test open() method + try + { + aMedMedRdDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test read() method + try + { + aMedMedRdDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdDriver22->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() and WriteFrom() methods for READ_ONLY part + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->writeFrom(), MEDEXCEPTION); + + //Check MED + CPPUNIT_ASSERT(aMed); + + //Test close() method + try + { + aMedMedRdDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDONLY_DRIVER22 aMedMedRdDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedRdDriver22Cpy_1 = *aMedMedRdDriver22; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDONLY_DRIVER22 aMedMedRdDriver22Cpy_2 (*aMedMedRdDriver22); + // (BUG) => Segmentation fault, because _concreteMedDrv is NULL +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedRdDriver22Cpy_2, *aMedMedRdDriver22); + + //Test (bool operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + //CPPUNIT_ASSERT(aMedMedRdDriver22Cpy_2.GENDRIVER::operator==(*aMedMedRdDriver22)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdDriver22Cpy_1; + //rwostr2<<aMedMedRdDriver22Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //-------------------------------Test WRITE_ONLY part------------------------------------------------------- + //Creation incorrect Med_Med write only driver (file is not exist) + MED_MED_WRONLY_DRIVER22 *aInvalidMedMedWrDriver22 = new MED_MED_WRONLY_DRIVER22(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver22->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med write only driver (with empty file name) + MED_MED_WRONLY_DRIVER22 *aInvalidMedMedWrDriver22_1 = new MED_MED_WRONLY_DRIVER22(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedWrDriver22_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med write only driver (normal constructor) + MED_MED_WRONLY_DRIVER22 *aMedMedWrDriver22 = new MED_MED_WRONLY_DRIVER22(filename_wr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedWrDriver22); + + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver22->writeFrom(),MEDEXCEPTION); + // (BUG) No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedWrDriver22->write(), MEDEXCEPTION); + //(BUG) => Segmentation fault +#endif + + //Test open() method + try + { + aMedMedWrDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedWrDriver22->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test writeFrom() method + try + { + aMedMedWrDriver22->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedWrDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // (BUG) => terminate called after throwing an instance of 'std::length_error' + // what(): basic_string::_S_create +#endif + + //Test close method + try + { + aMedMedWrDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_WRONLY_DRIVER22 aMedMedWrDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aMedMedWrDriver22Cpy_1 = *aMedMedWrDriver22; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_WRONLY_DRIVER22 aMedMedWrDriver22Cpy_2 (*aMedMedWrDriver22); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedWrDriver22Cpy_2, *aMedMedWrDriver22); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedWrDriver22Cpy_2.GENDRIVER::operator==(*aMedMedWrDriver22)); + + //Test (friend ostream & operator <<) defined GENDRIVER class + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedWrDriver22Cpy_1; + //rwostr2<<aMedMedWrDriver22Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + +//-------------------------------Test READ/WRITE part------------------------------------------------------- + //Creation incorrect Med_Med read/write driver (file is not exist) + MED_MED_RDWR_DRIVER22 *aInvalidMedMedRdWrDriver22 = new MED_MED_RDWR_DRIVER22(fileNotExistsName_wr, aMed); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver22->open(),MEDEXCEPTION); + + //Creation incorrect Med_Med read/write driver (with empty file name) + MED_MED_RDWR_DRIVER22 *aInvalidMedMedRdWrDriver22_1 = new MED_MED_RDWR_DRIVER22(emptyfilename, aMed); + + //Trying open file with empty name + CPPUNIT_ASSERT_THROW(aInvalidMedMedRdWrDriver22_1->open(),MEDEXCEPTION); + + + //Creation a correct Med_Med read/write driver (normal constructor) + MED_MED_RDWR_DRIVER22 *aMedMedRdWrDriver22 = new MED_MED_RDWR_DRIVER22(filename_rdwr, aMed); + + //Check driver + CPPUNIT_ASSERT(aMedMedRdWrDriver22); + + //Trying read MED from file if it is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->read(), MEDEXCEPTION); + // (BUG) No exception in this case. +#endif + + CPPUNIT_ASSERT_THROW(aMedMedRdDriver22->readFileStruct(),MEDEXCEPTION); + + //Trying write mesh to file, if file is not open +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver22->writeFrom(),MEDEXCEPTION); + // (BUG) => No exception in this case +#endif + +#ifdef ENABLE_FAULTS + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver22->write(), MEDEXCEPTION); + //(BUG) => Crash +#endif + + //Test open() method + try + { + aMedMedRdWrDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying open() file twice +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(aMedMedRdWrDriver22->open(),MEDEXCEPTION); + //(BUG) No exception in this case. +#endif + + //Test readFileStruct() method + try + { + aMedMedRdWrDriver22->readFileStruct(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method + try + { + aMedMedRdWrDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test writeFrom() method + try + { + aMedMedRdWrDriver22->writeFrom(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aMedMedRdWrDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#endif + + //Test close() method + try + { + aMedMedRdWrDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Default constructor + MED_MED_RDWR_DRIVER22 aMedMedRdWrDriver22Cpy_1; + + //Test copy constructor +#ifdef ENABLE_FAULTS + MED_MED_RDWR_DRIVER22 aMedMedRdWrDriver22Cpy_2 (*aMedMedRdWrDriver22); + // (BUG) => Segmentation fault +#endif + //CPPUNIT_ASSERT_EQUAL(aMedMedRdWrDriver22Cpy_2, *aMedMedRdWrDriver22); + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aMedMedRdWrDriver22Cpy_2.GENDRIVER::operator==(*aMedMedRdWrDriver22)); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + //ostringstream rwostr1, rwostr2; + //rwostr1<<aMedMedRdWrDriver22Cpy_1; + //rwostr2<<aMedMedRdWrDriver22Cpy_2; + //CPPUNIT_ASSERT(rwostr1.str() != ""); + //CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete aMed; + delete aInvalidMedMedRdDriver22; + delete aInvalidMedMedRdDriver22_1; + delete aMedMedRdDriver22; + + delete aInvalidMedMedWrDriver22; + delete aInvalidMedMedWrDriver22_1; + delete aMedMedWrDriver22; + + delete aInvalidMedMedRdWrDriver22; + delete aInvalidMedMedRdWrDriver22_1; + delete aMedMedRdWrDriver22; +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testMedMedDriver22(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedMeshDriver21.cxx b/src/MEDMEM/Test/MEDMEMTest_MedMeshDriver21.cxx new file mode 100644 index 000000000..d73c9ec6e --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedMeshDriver21.cxx @@ -0,0 +1,535 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_MedMeshDriver21.hxx> +#include <MEDMEM_Mesh.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +/*! + * Check methods (13), defined in MEDMEM_MedMeshDriver21.hxx: + * class MED_MESH_DRIVER21 : public virtual MED_MESH_DRIVER { + * (+) MED_MESH_DRIVER21(); + * (+) MED_MESH_DRIVER21(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces accessMode); + * (+) MED_MESH_DRIVER21(const MED_MESH_DRIVER21 & driver); + * (+) virtual ~MED_MESH_DRIVER21(); + * (+) void open(); + * (+) void close(); + * } + * class MED_MESH_RDONLY_DRIVER21 : public virtual IMED_MESH_RDONLY_DRIVER, + * public virtual MED_MESH_DRIVER21 { + * (+) MED_MESH_RDONLY_DRIVER21(); + * (+) MED_MESH_RDONLY_DRIVER21(const string & fileName, MESH * ptrMesh); + * (+) MED_MESH_RDONLY_DRIVER21(const MED_MESH_RDONLY_DRIVER21 & driver); + * (+) virtual ~MED_MESH_RDONLY_DRIVER21(); + * (+) void read (void); + * } + * class MED_MESH_WRONLY_DRIVER21 : public virtual IMED_MESH_WRONLY_DRIVER, + * public virtual MED_MESH_DRIVER21 { + * (+) MED_MESH_WRONLY_DRIVER21(); + * (+) MED_MESH_WRONLY_DRIVER21(const string & fileName, MESH * ptrMesh); + * (+) MED_MESH_WRONLY_DRIVER21(const MED_MESH_WRONLY_DRIVER21 & driver); + * (+) virtual ~MED_MESH_WRONLY_DRIVER21(); + * (+) void write(void) const; + * } + * class MED_MESH_RDWR_DRIVER21 : public IMED_MESH_RDWR_DRIVER, + * public MED_MESH_RDONLY_DRIVER21, public MED_MESH_WRONLY_DRIVER21 { + * (+) MED_MESH_RDWR_DRIVER21(); + * (+) MED_MESH_RDWR_DRIVER21(const string & fileName, MESH * ptrMesh); + * (+) MED_MESH_RDWR_DRIVER21(const MED_MESH_RDWR_DRIVER21 & driver); + * (+) ~MED_MESH_RDWR_DRIVER21(); + * (+) void write(void) const; + * (+) void read (void); + * } + */ +void MEDMEMTest::testMedMeshDriver21() +{ + MESH *aMesh = new MESH(); + MESH *aMesh_1 = new MESH(); + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string filename_wr = tmp_dir + "/myWr_pointe21.med"; + string tmpfile = tmp_dir + "/tmp.med"; + string meshname = "maa1"; + string newmeshname = "new" + meshname; + string fileNotExistsName_rd = "notExists.med"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.med"; + string filename_rdwr = tmp_dir + "/myRdWr_pointe22.med"; + char* longmeshname = new char[MED_TAILLE_NOM+2]; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + for (int i = 0; i<MED_TAILLE_NOM+2; ++i) + longmeshname[i] = 'a'; + + //Copy file in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + aRemover.Register(tmpfile); + + //----------------------------------Test READ ONLY part---------------------------------------------------// + + //Creation a incorrect read only driver + MED_MESH_RDONLY_DRIVER21 *aInvalidRdDriver21 = new MED_MESH_RDONLY_DRIVER21(fileNotExistsName_rd, aMesh); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidRdDriver21->open(), MEDEXCEPTION); + + //Creation a correct read only driver (normal constructor) + MED_MESH_RDONLY_DRIVER21 *aRdDriver21 = new MED_MESH_RDONLY_DRIVER21(filename_rd, aMesh); + + //Check driver + CPPUNIT_ASSERT(aRdDriver21); + + //Trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aRdDriver21->read(), MEDEXCEPTION); + + //Test open() method + try + { + aRdDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aRdDriver21->open(), MEDEXCEPTION); + //This case is not work, seems it BUG + + //Trying read mesh from file, if mesh name is not set, i.e. empty + CPPUNIT_ASSERT_THROW(aRdDriver21->read(), MEDEXCEPTION); + //No correct exception in this case + + //Trying read mesh from file with very long name + //aRdDriver21->setMeshName(longmeshname); + CPPUNIT_ASSERT_THROW(aRdDriver21->read(), MEDEXCEPTION); + //No correct exception in this case +#endif + + //Set correct Mesh name + //Test setMeshName() and getMeshName() methods + try + { + aRdDriver21->setMeshName(meshname); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(meshname, aRdDriver21->getMeshName()); + + + //Test read() method + try + { + aRdDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() method for READ ONLY driver + CPPUNIT_ASSERT_THROW(aRdDriver21->write(), MEDEXCEPTION); + + //Check Mesh + CPPUNIT_ASSERT(aMesh); + + //Default constructor + MED_MESH_RDONLY_DRIVER21 aRdDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + //aRdDriver21Cpy_1 = *aRdDriver21; + + //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aRdDriver21Cpy_1.GENDRIVER::operator==(*aRdDriver21)); + + //Test copy constructor + MED_MESH_RDONLY_DRIVER21 aRdDriver21Cpy_2 (aRdDriver21Cpy_1); + CPPUNIT_ASSERT_EQUAL(aRdDriver21Cpy_2, *aRdDriver21); + + //Test close() method + try + { + aRdDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying read mesh from copy closed driver + CPPUNIT_ASSERT_THROW(aRdDriver21Cpy_1.read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdDriver21Cpy_2.read(), MEDEXCEPTION); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rostr1, rostr2; + rostr1<<aRdDriver21Cpy_1; + rostr2<<aRdDriver21Cpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT(rostr1.str() == rostr2.str()); + + + //----------------------------------Test WRITE ONLY part------------------------------------------// + + //Creation a incorrect write only driver + MED_MESH_WRONLY_DRIVER21 *aInvalidWrDriver21 = new MED_MESH_WRONLY_DRIVER21(fileNotExistsName_wr, aMesh); + + //Trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidWrDriver21->open(), MEDEXCEPTION); + + //Trying write empty mesh + MED_MESH_WRONLY_DRIVER21 *aTmpWrDriver21 = new MED_MESH_WRONLY_DRIVER21(tmpfile, aMesh_1); + +#ifdef ENABLE_FORCED_FAILURES + aTmpWrDriver21->open(); + aTmpWrDriver21->setMeshName("EmptyMesh"); + CPPUNIT_ASSERT_THROW(aTmpWrDriver21->write(),MEDEXCEPTION); + aTmpWrDriver21->close(); + //Unknown exception in this case +#endif + + //Creation a correct write only driver + MED_MESH_WRONLY_DRIVER21 *aWrDriver21 = new MED_MESH_WRONLY_DRIVER21(filename_wr, aMesh); + + //Check driver + CPPUNIT_ASSERT(aWrDriver21); + + //Trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aWrDriver21->write(), MEDEXCEPTION); + + //Test open() method + try + { + aWrDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aWrDriver21->open(), MEDEXCEPTION); + //This case is not work, seems it BUG +#endif + +#ifdef ENABLE_FORCED_FAILURES + //Test case: trying write mesh to file, if mesh name is not set, i.e empty + aMesh->setName(""); + aWrDriver21->setMeshName(""); + CPPUNIT_ASSERT_THROW(aWrDriver21->write(), MEDEXCEPTION); + //No exception in this case + + //Trying write mesh to file with very long name + aWrDriver21->setMeshName(longmeshname); + CPPUNIT_ASSERT_THROW(aWrDriver21->write(), MEDEXCEPTION); + //No exception in this case +#endif + + //Set initialy mesh name + aMesh->setName(meshname); + //Test setMeshName() and getMeshName() methods + try + { + aWrDriver21->setMeshName(meshname); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(meshname, aWrDriver21->getMeshName()); + + //Test write() method + try + { + aWrDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method for WRITE ONLY driver + CPPUNIT_ASSERT_THROW(aWrDriver21->read(), MEDEXCEPTION); + + //Default constructor + MED_MESH_WRONLY_DRIVER21 aWrDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aWrDriver21Cpy_1 = *aWrDriver21; + + //Test (bool operator ==) defined GENDRIVER class + CPPUNIT_ASSERT(aWrDriver21Cpy_1.GENDRIVER::operator==(*aWrDriver21)); + + //Test copy constructor + MED_MESH_WRONLY_DRIVER21 aWrDriver21Cpy_2 (aWrDriver21Cpy_1); + CPPUNIT_ASSERT_EQUAL(aWrDriver21Cpy_2 , *aWrDriver21); + + try + { + aWrDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test case: Trying write mesh using copy closed driver + CPPUNIT_ASSERT_THROW(aWrDriver21Cpy_1.write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aWrDriver21Cpy_2.write(), MEDEXCEPTION); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream wostr1, wostr2; + wostr1<<aWrDriver21Cpy_1; + wostr2<<aWrDriver21Cpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + + //----------------------------------Test READ / WRITE part------------------------------------------// + + //Creation a incorrect read/write driver + MED_MESH_RDWR_DRIVER21 *aInvalidRdWrDriver21 = new MED_MESH_RDWR_DRIVER21(fileNotExistsName_wr, aMesh_1); + + //Test case: trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidRdWrDriver21->open(), MEDEXCEPTION); + + //Creation a correct read/write driver + MED_MESH_RDWR_DRIVER21 *aRdWrDriver21 = new MED_MESH_RDWR_DRIVER21(filename_rdwr, aMesh_1); + + //Check driver + CPPUNIT_ASSERT(aRdWrDriver21); + + //Test case: trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aRdWrDriver21->write(), MEDEXCEPTION); + + //Test case: trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aRdWrDriver21->read(), MEDEXCEPTION); + + //Test open() method + try + { + aRdWrDriver21->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Test case: trying open file secondary. + CPPUNIT_ASSERT_THROW(aRdWrDriver21->open(), MEDEXCEPTION); + //This case is not work, seems it BUG +#endif + +#ifdef ENABLE_FORCED_FAILURES + //Set mesh name + aMesh_1->setName("EmptyMesh"); + aRdWrDriver21->setMeshName("EmptyMesh"); + + //Trying write in file empty mesh + CPPUNIT_ASSERT_THROW(aRdWrDriver21->write(),MEDEXCEPTION); + //No exception in this case, seems it BUG +#endif + + //Set initialy mesh name + aMesh_1->setName(meshname); + //Test setMeshName() and getMeshName() methods + try + { + aRdWrDriver21->setMeshName(meshname); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(meshname, aRdWrDriver21->getMeshName()); + + //Test read() method + try + { + aRdWrDriver21->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying read mesh from file, if mesh name is not set, i.e. empty +#ifdef ENABLE_FORCED_FAILURES + aRdWrDriver21->setMeshName(""); + aMesh_1->setName(""); + CPPUNIT_ASSERT_THROW(aRdWrDriver21->read(), MEDEXCEPTION); + //No correct exception in this case + + //Trying write mesh to file, if mesh name is not set, i.e empty + CPPUNIT_ASSERT_THROW(aRdWrDriver21->write(), MEDEXCEPTION); + //No correct exception in this case + + //Trying read mesh from file with very long name + aRdWrDriver21->setMeshName(longmeshname); + aMesh_1->setName(longmeshname); + CPPUNIT_ASSERT_THROW(aRdWrDriver21->read(), MEDEXCEPTION); + //No correct exception in this case + + //Trying write mesh to file with very long name + CPPUNIT_ASSERT_THROW(aRdWrDriver21->write(), MEDEXCEPTION); + //No correct exception in this case +#endif + + //Test write() method + aRdWrDriver21->setMeshName(newmeshname); + aMesh_1->setName(newmeshname); + try + { + aRdWrDriver21->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Check Mesh + CPPUNIT_ASSERT(aMesh_1); + + //Default constructor + MED_MESH_RDWR_DRIVER21 aRdWrDriver21Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aRdWrDriver21Cpy_1 = *aRdWrDriver21; + + //Test (bool operator ==) defined GENDRIVER class + CPPUNIT_ASSERT(aRdWrDriver21Cpy_1.GENDRIVER::operator==(*aRdWrDriver21)); + + //Test copy constructor + MED_MESH_RDWR_DRIVER21 aRdWrDriver21Cpy_2 (aRdWrDriver21Cpy_1); + CPPUNIT_ASSERT_EQUAL(aRdWrDriver21Cpy_2, *aRdWrDriver21); + + try + { + aRdWrDriver21->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test case: trying read/write mesh using copy closed driver + CPPUNIT_ASSERT_THROW(aRdWrDriver21Cpy_1.read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdWrDriver21Cpy_2.read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdWrDriver21Cpy_1.write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdWrDriver21Cpy_2.write(), MEDEXCEPTION); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rwostr1, rwostr2; + rwostr1<<aRdWrDriver21Cpy_1; + rwostr2<<aRdWrDriver21Cpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete longmeshname; + + delete aInvalidRdDriver21; + delete aRdDriver21; + + delete aInvalidWrDriver21; + delete aWrDriver21; + delete aTmpWrDriver21; + + delete aInvalidRdWrDriver21; + delete aRdWrDriver21; + + delete aMesh; + delete aMesh_1; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedMeshDriver22.cxx b/src/MEDMEM/Test/MEDMEMTest_MedMeshDriver22.cxx new file mode 100644 index 000000000..043e26253 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedMeshDriver22.cxx @@ -0,0 +1,523 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_MedMeshDriver22.hxx> +#include <MEDMEM_Mesh.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +/*! + * Check methods (13), defined in MEDMEM_MedMeshDriver22.hxx: + * class MED_MESH_DRIVER22 : public virtual MED_MESH_DRIVER { + * (+) MED_MESH_DRIVER22(); + * (+) MED_MESH_DRIVER22(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces accessMode); + * (+) MED_MESH_DRIVER22(const MED_MESH_DRIVER22 & driver); + * (+) virtual ~MED_MESH_DRIVER22(); + * (+) void open(); + * (+) void close(); + * } + * class MED_MESH_RDONLY_DRIVER22 : public virtual IMED_MESH_RDONLY_DRIVER, + * public virtual MED_MESH_DRIVER22 { + * (+) MED_MESH_RDONLY_DRIVER22(); + * (+) MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh); + * (+) MED_MESH_RDONLY_DRIVER22(const MED_MESH_RDONLY_DRIVER22 & driver); + * (+) virtual ~MED_MESH_RDONLY_DRIVER22(); + * (+) void read (void); + * } + * class MED_MESH_WRONLY_DRIVER22 : public virtual IMED_MESH_WRONLY_DRIVER, + * public virtual MED_MESH_DRIVER22 { + * (+) MED_MESH_WRONLY_DRIVER22(); + * (+) MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh); + * (+) MED_MESH_WRONLY_DRIVER22(const MED_MESH_WRONLY_DRIVER22 & driver); + * (+) virtual ~MED_MESH_WRONLY_DRIVER22(); + * (+) void write(void) const; + * } + * class MED_MESH_RDWR_DRIVER22 : public IMED_MESH_RDWR_DRIVER, + * public MED_MESH_RDONLY_DRIVER22, public MED_MESH_WRONLY_DRIVER22 { + * (+) MED_MESH_RDWR_DRIVER22(); + * (+) MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh); + * (+) MED_MESH_RDWR_DRIVER22(const MED_MESH_RDWR_DRIVER22 & driver); + * (+) ~MED_MESH_RDWR_DRIVER22(); + * (+) void write(void) const; + * (+) void read (void); + * } + */ +void MEDMEMTest::testMedMeshDriver22() +{ + MESH *aMesh = new MESH(); + MESH *aMesh_1 = new MESH(); + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filename_wr = tmp_dir + "/myWr_pointe22.med"; + string tmpfile = tmp_dir + "/tmp.med"; + string meshname = "maa1"; + string newmeshname = "new" + meshname; + string fileNotExistsName_rd = "notExists.med"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.med"; + string filename_rdwr = tmp_dir + "/myRdWr_pointe22.med"; + char* longmeshname = new char[MED_TAILLE_NOM+2]; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + for (int i = 0; i<MED_TAILLE_NOM+2; ++i) + longmeshname[i] = 'a'; + + //Copy file in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + aRemover.Register(tmpfile); + + //----------------------------------Test READ ONLY part---------------------------------------------------// + + //Creation a incorrect read only driver + MED_MESH_RDONLY_DRIVER22 *aInvalidRdDriver22 = new MED_MESH_RDONLY_DRIVER22(fileNotExistsName_rd, aMesh); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidRdDriver22->open(), MEDEXCEPTION); + + //Creation a correct read only driver (normal constructor) + MED_MESH_RDONLY_DRIVER22 *aRdDriver22 = new MED_MESH_RDONLY_DRIVER22(filename_rd, aMesh); + + //Check driver + CPPUNIT_ASSERT(aRdDriver22); + + //Trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aRdDriver22->read(), MEDEXCEPTION); + + //Test open() method + try + { + aRdDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aRdDriver22->open(), MEDEXCEPTION); + //This case is not work, seems it BUG +#endif + + //Trying read mesh from file, if mesh name is not set, i.e. empty + CPPUNIT_ASSERT_THROW(aRdDriver22->read(), MEDEXCEPTION); + + //Trying read mesh from file with very long name + aRdDriver22->setMeshName(longmeshname); + CPPUNIT_ASSERT_THROW(aRdDriver22->read(), MEDEXCEPTION); + + //Set correct Mesh name + //Test setMeshName() and getMeshName() methods + try + { + aRdDriver22->setMeshName(meshname); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(meshname, aRdDriver22->getMeshName()); + + + //Test read() method + try + { + aRdDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test write() method for READ ONLY driver + CPPUNIT_ASSERT_THROW(aRdDriver22->write(), MEDEXCEPTION); + + //Check Mesh + CPPUNIT_ASSERT(aMesh); + + //Default constructor + MED_MESH_RDONLY_DRIVER22 aRdDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + //aRdDriver22Cpy_1 = *aRdDriver22; + + //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aRdDriver22Cpy_1.GENDRIVER::operator==(*aRdDriver22)); + + //Test copy constructor + MED_MESH_RDONLY_DRIVER22 aRdDriver22Cpy_2 (aRdDriver22Cpy_1); + CPPUNIT_ASSERT_EQUAL(aRdDriver22Cpy_2, *aRdDriver22); + + //Test close() method + try + { + aRdDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying read mesh from copy closed driver + CPPUNIT_ASSERT_THROW(aRdDriver22Cpy_1.read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdDriver22Cpy_2.read(), MEDEXCEPTION); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rostr1, rostr2; + rostr1<<aRdDriver22Cpy_1; + rostr2<<aRdDriver22Cpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT(rostr1.str() == rostr2.str()); + + + //----------------------------------Test WRITE ONLY part------------------------------------------// + + //Creation a incorrect write only driver + MED_MESH_WRONLY_DRIVER22 *aInvalidWrDriver22 = new MED_MESH_WRONLY_DRIVER22(fileNotExistsName_wr, aMesh); + + //Trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidWrDriver22->open(), MEDEXCEPTION); + + //Trying write empty mesh + MED_MESH_WRONLY_DRIVER22 *aTmpWrDriver22 = new MED_MESH_WRONLY_DRIVER22(tmpfile, aMesh_1); + +#ifdef ENABLE_FORCED_FAILURES + aTmpWrDriver22->open(); + aTmpWrDriver22->setMeshName("EmptyMesh"); + CPPUNIT_ASSERT_THROW(aTmpWrDriver22->write(),MEDEXCEPTION); + aTmpWrDriver22->close(); + //Unknown exception in this case +#endif + + //Creation a correct write only driver + MED_MESH_WRONLY_DRIVER22 *aWrDriver22 = new MED_MESH_WRONLY_DRIVER22(filename_wr, aMesh); + + //Check driver + CPPUNIT_ASSERT(aWrDriver22); + + //Trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aWrDriver22->write(), MEDEXCEPTION); + + //Test open() method + try + { + aWrDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary. + CPPUNIT_ASSERT_THROW(aWrDriver22->open(), MEDEXCEPTION); + //This case is not work, seems it BUG +#endif + + //Test case: trying write mesh to file, if mesh name is not set, i.e empty + aMesh->setName(""); + aWrDriver22->setMeshName(""); + CPPUNIT_ASSERT_THROW(aWrDriver22->write(), MEDEXCEPTION); + + //Trying write mesh to file with very long name + aWrDriver22->setMeshName(longmeshname); + CPPUNIT_ASSERT_THROW(aWrDriver22->write(), MEDEXCEPTION); + + //Set initialy mesh name + aMesh->setName(meshname); + //Test setMeshName() and getMeshName() methods + try + { + aWrDriver22->setMeshName(meshname); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(meshname, aWrDriver22->getMeshName()); + + //Test write() method + try + { + aWrDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test read() method for WRITE ONLY driver + CPPUNIT_ASSERT_THROW(aWrDriver22->read(), MEDEXCEPTION); + + //Default constructor + MED_MESH_WRONLY_DRIVER22 aWrDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aWrDriver22Cpy_1 = *aWrDriver22; + + //Test (bool operator ==) defined GENDRIVER class + CPPUNIT_ASSERT(aWrDriver22Cpy_1.GENDRIVER::operator==(*aWrDriver22)); + + //Test copy constructor + MED_MESH_WRONLY_DRIVER22 aWrDriver22Cpy_2 (aWrDriver22Cpy_1); + CPPUNIT_ASSERT_EQUAL(aWrDriver22Cpy_2 , *aWrDriver22); + + try + { + aWrDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test case: Trying write mesh using copy closed driver + CPPUNIT_ASSERT_THROW(aWrDriver22Cpy_1.write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aWrDriver22Cpy_2.write(), MEDEXCEPTION); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream wostr1, wostr2; + wostr1<<aWrDriver22Cpy_1; + wostr2<<aWrDriver22Cpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + + //----------------------------------Test READ / WRITE part------------------------------------------// + + //Creation a incorrect read/write driver + MED_MESH_RDWR_DRIVER22 *aInvalidRdWrDriver22 = new MED_MESH_RDWR_DRIVER22(fileNotExistsName_wr, aMesh_1); + + //Test case: trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidRdWrDriver22->open(), MEDEXCEPTION); + + //Creation a correct read/write driver + MED_MESH_RDWR_DRIVER22 *aRdWrDriver22 = new MED_MESH_RDWR_DRIVER22(filename_rdwr, aMesh_1); + + //Check driver + CPPUNIT_ASSERT(aRdWrDriver22); + + //Test case: trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aRdWrDriver22->write(), MEDEXCEPTION); + + //Test case: trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aRdWrDriver22->read(), MEDEXCEPTION); + + //Test open() method + try + { + aRdWrDriver22->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FORCED_FAILURES + //Test case: trying open file secondary. + CPPUNIT_ASSERT_THROW(aRdWrDriver22->open(), MEDEXCEPTION); + //This case is not work, seems it BUG +#endif + +#ifdef ENABLE_FORCED_FAILURES + //Set mesh name + aMesh_1->setName("EmptyMesh"); + aRdWrDriver22->setMeshName("EmptyMesh"); + //Trying write in file empty mesh + CPPUNIT_ASSERT_THROW(aRdWrDriver22->write(),MEDEXCEPTION); + //No exception in this case, seems it BUG +#endif + + //Set initialy mesh name + aMesh_1->setName(meshname); + //Test setMeshName() and getMeshName() methods + try + { + aRdWrDriver22->setMeshName(meshname); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_EQUAL(meshname, aRdWrDriver22->getMeshName()); + + //Test read() method + try + { + aRdWrDriver22->read(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Trying read mesh from file, if mesh name is not set, i.e. empty + aRdWrDriver22->setMeshName(""); + aMesh_1->setName(""); + CPPUNIT_ASSERT_THROW(aRdWrDriver22->read(), MEDEXCEPTION); + + //Trying write mesh to file, if mesh name is not set, i.e empty + CPPUNIT_ASSERT_THROW(aRdWrDriver22->write(), MEDEXCEPTION); + + //Trying read mesh from file with very long name + aRdWrDriver22->setMeshName(longmeshname); + aMesh_1->setName(longmeshname); + CPPUNIT_ASSERT_THROW(aRdWrDriver22->read(), MEDEXCEPTION); + + //Trying write mesh to file with very long name + CPPUNIT_ASSERT_THROW(aRdWrDriver22->write(), MEDEXCEPTION); + + //Test write() method + aRdWrDriver22->setMeshName(newmeshname); + aMesh_1->setName(newmeshname); + try + { + aRdWrDriver22->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Check Mesh + CPPUNIT_ASSERT(aMesh_1); + + //Default constructor + MED_MESH_RDWR_DRIVER22 aRdWrDriver22Cpy_1; + + //Test (void operator =) defined in GENDRIVER class + //aRdWrDriver22Cpy_1 = *aRdWrDriver22; + + //Test (bool operator ==) defined GENDRIVER class + CPPUNIT_ASSERT(aRdWrDriver22Cpy_1.GENDRIVER::operator==(*aRdWrDriver22)); + + //Test copy constructor + MED_MESH_RDWR_DRIVER22 aRdWrDriver22Cpy_2 (aRdWrDriver22Cpy_1); + CPPUNIT_ASSERT_EQUAL(aRdWrDriver22Cpy_2, *aRdWrDriver22); + + try + { + aRdWrDriver22->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test case: trying read/write mesh using copy closed driver + CPPUNIT_ASSERT_THROW(aRdWrDriver22Cpy_1.read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdWrDriver22Cpy_2.read(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdWrDriver22Cpy_1.write(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aRdWrDriver22Cpy_2.write(), MEDEXCEPTION); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rwostr1, rwostr2; + rwostr1<<aRdWrDriver22Cpy_1; + rwostr2<<aRdWrDriver22Cpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + //Delete all objects + delete longmeshname; + + delete aInvalidRdDriver22; + delete aRdDriver22; + + delete aInvalidWrDriver22; + delete aWrDriver22; + + delete aInvalidRdWrDriver22; + delete aRdWrDriver22; + delete aTmpWrDriver22; + + delete aMesh; + delete aMesh_1; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MedVersion.cxx b/src/MEDMEM/Test/MEDMEMTest_MedVersion.cxx new file mode 100644 index 000000000..fecc5a8ed --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MedVersion.cxx @@ -0,0 +1,81 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <cstdlib> +#include <exception> + +#include <MEDMEM_MedVersion.hxx> +#include "MEDMEM_Compatibility21_22.hxx" + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (not in spec), defined in MEDMEM_MedVersion.hxx: + * (+) MED_EN::medFileVersion getMedFileVersion(const string & fileName) throw (MEDEXCEPTION); + * (+) int getMedAccessMode(MED_EN::med_mode_acces mode, + * MED_EN::medFileVersion medVersion) throw (MEDEXCEPTION); + */ + +void MEDMEMTest::testMedVersion() +{ + string filename = getenv("DATA_DIR"); + filename += "/MedFiles/pointe.med"; + string notExistFileName = "anyfile"; + medFileVersion myFileVersion; + medFileVersion myEmptyFileVersion; + + // Test - getMedFileVersion + CPPUNIT_ASSERT_THROW(getMedFileVersion(notExistFileName),MEDEXCEPTION); + + try + { + myFileVersion = getMedFileVersion(filename); + CPPUNIT_ASSERT(myFileVersion == V21); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test - getMedAccessMode + CPPUNIT_ASSERT_THROW(getMedAccessMode(MED_REMP,myEmptyFileVersion),MEDEXCEPTION); + + try + { + CPPUNIT_ASSERT_EQUAL(med_2_1::MED_ECRI, + (med_2_1::med_mode_acces)getMedAccessMode(MED_REMP,myFileVersion)); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MeshAndMeshing.cxx b/src/MEDMEM/Test/MEDMEMTest_MeshAndMeshing.cxx new file mode 100644 index 000000000..fb63b63eb --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MeshAndMeshing.cxx @@ -0,0 +1,1844 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Grid.hxx" + +#include "MEDMEM_Med.hxx" +#include "MEDMEM_MedMeshDriver22.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +double dmax(double x, double y) { return (x>y)?x:y;} + +double dmin(double x, double y) { return (x>y)?y:x;} + +void addMedFacesGroup (MESHING& meshing, int nFaces, const int *groupValue, + string groupName, const MED_EN::medGeometryElement *mytypes, + const int *index, const int *myNumberOfElements, int nbOfGeomTypes) +{ + GROUP faces; + faces.setName(groupName); + faces.setMesh(&meshing); + faces.setEntity(MED_EN::MED_FACE); + faces.setNumberOfGeometricType(nbOfGeomTypes); + faces.setGeometricType(mytypes); + faces.setNumberOfElements(myNumberOfElements); + faces.setNumber(index, groupValue); + meshing.addGroup(faces); +} + +void addMedFacesGroupAll (MESHING& meshing, string groupName) +{ + GROUP faces; + faces.setName(groupName); + faces.setMesh(&meshing); + faces.setEntity(MED_EN::MED_FACE); + meshing.addGroup(faces); +} + +/*! + * Check methods (18), defined in MEDMEM_Meshing.hxx: + * class MESHING: public MESH { + * (+) MESHING(); + * (+) ~MESHING(); + * (+) void setSpaceDimension (const int SpaceDimension); + * (+) void setMeshDimension (const int MeshDimension); + * (+) void setNumberOfNodes (const int NumberOfNodes); + * (+) void setCoordinates (const int SpaceDimension, const int NumberOfNodes, + * const double * Coordinates, + * const string System, const MED_EN::medModeSwitch Mode); + * (+) void setCoordinatesSystem(const string System) throw (MEDEXCEPTION); + * (+) void setCoordinatesNames (const string * names); + * (+) void setCoordinateName (const string name, const int i); + * (+) void setCoordinatesUnits (const string * units); + * (+) void setCoordinateUnit (const string unit, const int i); + * (+) void setNumberOfTypes (const int NumberOfTypes, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setTypes (const MED_EN::medGeometryElement * Types, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setNumberOfElements (const int * NumberOfElements, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setConnectivity (const int * Connectivity, const MED_EN::medEntityMesh Entity, + * const MED_EN::medGeometryElement Type) throw (MEDEXCEPTION); + * (+) void setPolygonsConnectivity (const int * ConnectivityIndex, const int * ConnectivityValue, + * int nbOfPolygons, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setPolyhedraConnectivity (const int * PolyhedronIndex, const int * FacesIndex, + * const int * Nodes, int nbOfPolyhedra, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (NOT YET IMPLEMENTED!!!) void setConnectivities (const int * ConnectivityIndex, + * const int * ConnectivityValue, + * const MED_EN::medConnectivity ConnectivityType, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void addGroup (const GROUP & Group) throw (MEDEXCEPTION); + * } + */ + +/*! + * Check methods (87), defined in MEDMEM_Mesh.hxx: + * class MESH : public RCBASE { + * (+) void init(); + * (+) MESH(); + * (+) MESH(MESH &m); + * (+) MESH & operator=(const MESH &m); + * (+) virtual bool operator==(const MESH& other) const; + * (+) virtual bool deepCompare(const MESH& other) const; + * (+) MESH(driverTypes driverType, const string & fileName="", + * const string & meshName="") throw (MEDEXCEPTION); + * (+) virtual ~MESH(); + * (+) friend ostream & operator<<(ostream &os, const MESH &my); + * (+) int addDriver(driverTypes driverType, + * const string & fileName="Default File Name.med", + * const string & driverName="Default Mesh Name", + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (+) int addDriver(GENDRIVER & driver); + * (+) void rmDriver(int index=0); + * (+) virtual void read(int index=0); + * (must be private) inline void read(const GENDRIVER & genDriver); + * (+) inline void write(int index=0, const string & driverName = ""); + * (must be private) inline void write(const GENDRIVER & genDriver); + * (+) inline void setName(string name); + * (+) inline void setDescription(string description); + * (+) inline string getName() const; + * (+) inline string getDescription() const; + * (+) inline int getSpaceDimension() const; + * (+) inline int getMeshDimension() const; + * (+) inline bool getIsAGrid(); + * (+) inline int getNumberOfNodes() const; + * (+) virtual inline const COORDINATE * getCoordinateptr() const; + * (+) inline string getCoordinatesSystem() const; + * (+) virtual inline const double * getCoordinates(MED_EN::medModeSwitch Mode) const; + * (+) virtual inline const double getCoordinate(int Number,int Axis) const; + * (+) inline const string * getCoordinatesNames() const; + * (+) inline const string * getCoordinatesUnits() const; + * (+) virtual inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const; + * (+) virtual int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const; + * (+) virtual MED_EN::medGeometryElement * getTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const CELLMODEL * getCellsTypes(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline string * getCellTypeNames(MED_EN::medEntityMesh Entity) const; + * (+) virtual const int * getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline int getNumberOfElements(MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual inline bool existConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline bool existPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline bool existPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) virtual inline MED_EN::medGeometryElement getElementType + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) virtual inline MED_EN::medGeometryElement getElementTypeWithPoly + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) virtual inline void calculateConnectivity(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) virtual inline int getConnectivityLength(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual inline const int * getConnectivity(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual inline const int * getConnectivityIndex + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline int getPolygonsConnectivityLength + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline const int * getPolygonsConnectivity + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline const int * getPolygonsConnectivityIndex + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline int getNumberOfPolygons(MED_EN::medEntityMesh Entity=MED_EN::MED_ALL_ENTITIES) const; + * (+) inline int getPolyhedronConnectivityLength(MED_EN::medConnectivity ConnectivityType) const; + * (+) inline const int * getPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType) const; + * (+) inline const int * getPolyhedronFacesIndex() const; + * (+) inline const int * getPolyhedronIndex(MED_EN::medConnectivity ConnectivityType) const; + * (+) inline int getNumberOfPolyhedronFaces() const; + * (+) inline int getNumberOfPolyhedron() const; + * (+) virtual int getElementNumber(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type, + * int * connectivity) const; + * (+) virtual inline int getReverseConnectivityLength + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual inline const int * getReverseConnectivity + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual inline int getReverseConnectivityIndexLength + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual inline const int * getReverseConnectivityIndex + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual int getNumberOfFamilies(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const vector<FAMILY*> getFamilies(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const FAMILY* getFamily(MED_EN::medEntityMesh Entity,int i) const; + * (+) virtual int getNumberOfGroups(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const vector<GROUP*> getGroups(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const GROUP* getGroup(MED_EN::medEntityMesh Entity,int i) const; + * (+) virtual inline const CONNECTIVITY* getConnectivityptr() const; + * (+) virtual SUPPORT * getBoundaryElements(MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) SUPPORT * getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getVolume (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getArea (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getLength (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getNormal (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) static SUPPORT * mergeSupports(const vector<SUPPORT *> Supports) throw (MEDEXCEPTION); + * (+) static SUPPORT * intersectSupports(const vector<SUPPORT *> Supports) throw (MEDEXCEPTION); + * (+) void createFamilies(); + * (+) SUPPORT *buildSupportOnNodeFromElementList + * (const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); + * (do the same thing as buildSupportOnNodeFromElementList except that a SUPPORT is not created) void fillSupportOnNodeFromElementList + * (const list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION); + * (+) SUPPORT *buildSupportOnElementsFromElementList + * (const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); + * (+) int getElementContainingPoint(const double *coord); + * (+) vector< vector<double> > getBoundingBox() const; + * (+) template<class T> static + * FIELD<T> * mergeFields(const vector< FIELD<T> * > & others, bool meshCompare=false); + * (Presently disconnected in C++) virtual void addReference() const; + * (Presently disconnected in C++) virtual void removeReference() const; + * } + */ +void MEDMEMTest::testMeshAndMeshing() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filenameout21 = tmp_dir + "/myMeshWrite4_pointe21.med"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filenameout21); + + //////////// + // TEST 1 // + //////////// + + MESH * myMesh= new MESH(); + myMesh->setName("FIRST_MESH"); + CPPUNIT_ASSERT(myMesh != NULL); + + //test operator << + //#ifdef ENABLE_FAULTS + //CPPUNIT_ASSERT_NO_THROW(cout << *myMesh << endl); + //#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: operator << : if mesh is empty then attempt" + " to get values from null object causes error"); +#endif + + //test operator = + MESH myMesh1 = *myMesh; + + //deepCompare +#ifdef ENABLE_FAULTS + bool isEqual = false; + CPPUNIT_ASSERT_NO_THROW(isEqual = myMesh1.deepCompare(*myMesh)); + CPPUNIT_ASSERT(isEqual); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: deepCompare(...) fails if mesh is empty"); +#endif + + //ensure it imposible to compare meshes + MESH *myMeshPointer = myMesh; + //test operator == + CPPUNIT_ASSERT(*myMeshPointer == *myMesh); + + delete myMesh; + + //set a MESH object + MESHING myMeshing; + myMeshing.setName("meshing"); + // define coordinates + + int SpaceDimension = 3; + int NumberOfNodes = 19; + double Coordinates[57] = { + 0.0, 0.0, 0.0, + 0.0, 0.0, 1.0, + 2.0, 0.0, 1.0, + 0.0, 2.0, 1.0, + -2.0, 0.0, 1.0, + 0.0, -2.0, 1.0, + 1.0, 1.0, 2.0, + -1.0, 1.0, 2.0, + -1.0, -1.0, 2.0, + 1.0, -1.0, 2.0, + 1.0, 1.0, 3.0, + -1.0, 1.0, 3.0, + -1.0, -1.0, 3.0, + 1.0, -1.0, 3.0, + 1.0, 1.0, 4.0, + -1.0, 1.0, 4.0, + -1.0, -1.0, 4.0, + 1.0, -1.0, 4.0, + 0.0, 0.0, 5.0 + }; + try + { + myMeshing.setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + string Names[3] = { "X","Y","Z" }; + try + { + myMeshing.setCoordinatesNames(Names); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + string Units[3] = { "cm","cm","cm" }; + try + { + myMeshing.setCoordinatesUnits(Units); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // define conectivities + + // cell part + + const int NumberOfTypes = 3; + medGeometryElement Types[NumberOfTypes] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; + const int NumberOfElements[NumberOfTypes] = {12,2,2}; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfTypes(NumberOfTypes,MED_CELL)); + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setTypes(Types,MED_CELL)); + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfElements(NumberOfElements,MED_CELL)); + + const int sizeTetra = 12*4; + int ConnectivityTetra[sizeTetra]= + { + 1,2,3,6, + 1,2,4,3, + 1,2,5,4, + 1,2,6,5, + 2,7,4,3, + 2,8,5,4, + 2,9,6,5, + 2,10,3,6, + 2,7,3,10, + 2,8,4,7, + 2,9,5,8, + 2,10,6,9 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityTetra,MED_CELL,MED_TETRA4)); + + int ConnectivityPyra[2*5]= + { + 7,8,9,10,2, + 15,18,17,16,19 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityPyra,MED_CELL,MED_PYRA5)); + + int ConnectivityHexa[2*8]= + { + 11,12,13,14,7,8,9,10, + 15,16,17,18,11,12,13,14 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityHexa,MED_CELL,MED_HEXA8)); + + // face part + const int NumberOfFacesTypes = 2; + medGeometryElement FacesTypes[NumberOfFacesTypes] = {MED_TRIA3,MED_QUAD4}; + const int NumberOfFacesElements[NumberOfFacesTypes] = {4,4}; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfTypes(NumberOfFacesTypes,MED_FACE)); + CPPUNIT_ASSERT_NO_THROW(myMeshing.setTypes(FacesTypes,MED_FACE)); + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfElements(NumberOfFacesElements,MED_FACE)); + const int nbTria = 4; + const int sizeTria = nbTria*3; + int ConnectivityTria[sizeTria]= + { + 1,4,3, + 1,5,4, + 1,6,5, + 1,3,6 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityTria,MED_FACE,MED_TRIA3)); + const int nbQua = 4; + int ConnectivityQua[nbQua*4]= + { + 7,8,9,10, + 11,12,13,14, + 11,7,8,12, + 12,8,9,13 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityQua,MED_FACE,MED_QUAD4)); + + int meshDimension = SpaceDimension; // because there 3D cells in the mesh + try + { + myMeshing.setMeshDimension(meshDimension); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // edge part + + // not yet implemented : if set, results are unpredictable. + + // Some groups : + + // Node : + { + GROUP myGroup; + myGroup.setName("SomeNodes"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_NODE); + myGroup.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_NONE}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {4}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,5}; + const int value[4]= { 1,4,5,7}; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + { + GROUP myGroup; + myGroup.setName("OtherNodes"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_NODE); + myGroup.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_NONE}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {3}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,4}; + const int value[3]= { 2,3,6}; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + + // Cell : + { + GROUP myGroup; + myGroup.setName("SomeCells"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_CELL); + myGroup.setNumberOfGeometricType(3); + medGeometryElement myTypes[3] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[3] = {4,1,2}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[3+1] = {1,5,6,8}; + const int value[4+1+2]= + { + 2,7,8,12, + 13, + 15,16 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + { + GROUP myGroup; + myGroup.setName("OtherCells"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_CELL); + myGroup.setNumberOfGeometricType(2); + medGeometryElement myTypes[] = {MED_TETRA4,MED_PYRA5}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[] = {4,1}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[2+1] = {1,5,6}; + const int value[4+1]= + { + 3,4,5,9, + 14 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + + // Face : + { + GROUP myGroup; + myGroup.setName("SomeFaces"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_FACE); + myGroup.setNumberOfGeometricType(2); + medGeometryElement myTypes[2] = {MED_TRIA3,MED_QUAD4}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[2] = {2,3}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[2+1] = {1,3,6}; + const int value[2+3]= + { + 2,4, + 5,6,8 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + { + GROUP myGroup; + myGroup.setName("OtherFaces"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_FACE); + myGroup.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_TRIA3}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {2}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,3}; + const int value[2]= + { + 1,3 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + + //test Mesh(MESH &m) + { + MESH * myMesh2 = new MESH( myMeshing ); + CPPUNIT_ASSERT(myMesh2->deepCompare(myMeshing)); + + cout<<*myMesh2<<endl; + ostringstream os; + os << * myMesh2; + CPPUNIT_ASSERT(os.str() != ""); + + CPPUNIT_ASSERT_EQUAL(myMesh2->getName(),(string)"meshing"); + CPPUNIT_ASSERT((myMesh2->getDescription()).size() == 0); + myMesh2->setDescription("This class contains all information related to a 'meshing' mesh "); + CPPUNIT_ASSERT((myMesh2->getDescription()).size() != 0); + + CPPUNIT_ASSERT(myMesh2->getSpaceDimension() == SpaceDimension); + CPPUNIT_ASSERT(myMesh2->getMeshDimension() == meshDimension); + CPPUNIT_ASSERT(myMesh2->getNumberOfNodes() == NumberOfNodes); + + const COORDINATE* coord = myMesh2->getCoordinateptr(); + try + { + CPPUNIT_ASSERT(myMesh2->getCoordinatesSystem() != "catresian"); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const string * units; + try + { + units = myMesh2->getCoordinatesUnits(); + for (int axe = 0; axe < SpaceDimension; axe++) { + string verif = coord->getCoordinateUnit(axe+1); + CPPUNIT_ASSERT(verif == units[axe]); + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const string * noms; + try + { + noms = myMesh2->getCoordinatesNames(); + for (int axe = 0; axe < SpaceDimension; axe++) { + string verif = coord->getCoordinateName(axe+1); + CPPUNIT_ASSERT(verif == noms[axe]); + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + const double * coor2 = myMesh2->getCoordinates(MED_FULL_INTERLACE); + + for (int axe = 0; axe < SpaceDimension; axe++) { + try + { + for (int num = 0; num < NumberOfNodes; num++) { + try + { + const double d = myMesh2->getCoordinate(num + 1, axe + 1); + CPPUNIT_ASSERT(fabs(d - coor2[(num * SpaceDimension)+axe]) < 0.001); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const CONNECTIVITY * myConnectivity = myMesh2->getConnectivityptr(); + + // MED_EN::MED_CELL + MED_EN::medEntityMesh entity = myConnectivity->getEntity(); + CPPUNIT_ASSERT_EQUAL(MED_CELL, entity); + + int typesNb; + CPPUNIT_ASSERT_NO_THROW(typesNb= myConnectivity->getNumberOfTypes(entity)); + CPPUNIT_ASSERT_EQUAL(NumberOfTypes, typesNb); + + const MED_EN::medGeometryElement * Types1; + CPPUNIT_ASSERT_NO_THROW(Types1 = myMesh2->getTypes(entity)); + + medConnectivity myMedConnect; + bool existConnect = false; + if (myMesh2->existConnectivity(MED_NODAL, entity)) + { + existConnect = true; + myMedConnect = MED_NODAL; + } + else if(myMesh2->existConnectivity(MED_DESCENDING, entity)) + { + existConnect = true; + myMedConnect = MED_DESCENDING; + } + + for(int t = 0; t < NumberOfTypes; t++ ) + { + CPPUNIT_ASSERT_EQUAL(Types1[t], Types[t]); + int NumberOfElements1 = 0; + CPPUNIT_ASSERT_NO_THROW(NumberOfElements1 = myMesh2->getNumberOfElements(entity, Types1[t])); + CPPUNIT_ASSERT_EQUAL(NumberOfElements1, NumberOfElements[t]); + if(existConnect) + { + const int * connectivity; + const int * connectivity_index; + CPPUNIT_ASSERT_NO_THROW(connectivity = myMesh2->getConnectivity + (MED_FULL_INTERLACE, myMedConnect, entity, Types1[t])); + connectivity_index = myMesh2->getConnectivityIndex(myMedConnect, entity); + for (int j = 0; j < NumberOfElements1; j++) { + cout<<"!!!!!!!!!!!!!!!"<<endl; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + } + } + + const CELLMODEL* myCellModel = myMesh2->getCellsTypes(entity); + string* TypeNames; + CPPUNIT_ASSERT_NO_THROW(TypeNames = myMesh2->getCellTypeNames(entity)); + + for(int k = 0; k < NumberOfTypes; k++ ) + { + CPPUNIT_ASSERT_EQUAL(TypeNames[k], myCellModel[k].getName()); + } + delete [] TypeNames; + + const int* myGlobalNbIdx; + CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = myMesh2->getGlobalNumberingIndex(MED_FACE)); + for(int i = 0; i <= NumberOfFacesTypes; i++) + { + if(i == NumberOfFacesTypes) + { + CPPUNIT_ASSERT_EQUAL(myGlobalNbIdx[i],nbTria+nbQua+1); + CPPUNIT_ASSERT_THROW(myMesh2->getElementType(MED_FACE, myGlobalNbIdx[i]), MEDEXCEPTION); + break; + } + cout<<"Global number of first element of each geom type : "<<myGlobalNbIdx[i]<<endl; + } + + { + const int * ReverseNodalConnectivity; + + // Show Reverse Nodal Connectivity +#ifndef ENABLE_FAULTS + // (BUG) CONNECTIVITY::_numberOfNodes is not set + ((CONNECTIVITY*)myConnectivity)->setNumberOfNodes(NumberOfNodes); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR in CONNECTIVITY::calculateReverseNodalConnectivity()" + " because myMesh2->_connectivity->_numberOfNodes is not set"); +#endif + + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = myMesh2->getReverseConnectivity(MED_NODAL, entity)); + CPPUNIT_ASSERT_NO_THROW(myMesh2->getReverseConnectivityLength(MED_NODAL, entity)); + const int * ReverseNodalConnectivityIndex = myMesh2->getReverseConnectivityIndex(MED_NODAL, entity); + const int ReverseIdxLength = myMesh2->getReverseConnectivityIndexLength(MED_NODAL, entity); + CPPUNIT_ASSERT(ReverseIdxLength == NumberOfNodes+1); + for (int i = 0; i < NumberOfNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + // Show Descending Connectivity + int NumberOfElements1; + const int * connectivity; + const int * connectivity_index; + myMesh2->calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, entity); + try { + NumberOfElements1 = myMesh2->getNumberOfElements(entity, MED_ALL_ELEMENTS); + connectivity = myMesh2->getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, entity, MED_ALL_ELEMENTS); + connectivity_index = myMesh2->getConnectivityIndex(MED_DESCENDING, entity); + } + catch (MEDEXCEPTION m) { + CPPUNIT_FAIL(m.what()); + } + + for (int j = 0; j < NumberOfElements1; j++) { + cout << "Element " << j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + + // getElementNumber + if (myMesh2->existConnectivity(MED_NODAL, MED_FACE)) { + int myTr[3] = {1,5,4}; + CPPUNIT_ASSERT_NO_THROW(myMesh2->getElementNumber(MED_NODAL,MED_FACE,MED_TRIA3,myTr)); + } + } + + //test family and group + int NumberOfGroups; + CPPUNIT_ASSERT_THROW(myMesh2->getNumberOfGroups(MED_ALL_ENTITIES), MEDEXCEPTION); + CPPUNIT_ASSERT_NO_THROW(NumberOfGroups = myMesh2->getNumberOfGroups(MED_CELL)); + CPPUNIT_ASSERT_EQUAL(NumberOfGroups, 2); + vector<GROUP*> groups; + CPPUNIT_ASSERT_NO_THROW(groups = myMesh2->getGroups(MED_CELL)); + CPPUNIT_ASSERT(groups.size() != 0); + for(int nb = 1; nb <= NumberOfGroups; nb++ ) + { + const GROUP* group; + CPPUNIT_ASSERT_NO_THROW(group = myMesh2->getGroup(MED_CELL, nb)); + CPPUNIT_ASSERT_EQUAL(group->getName(), groups[nb-1]->getName()); + } + + int NumberOfFamilies; + CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies = myMesh2->getNumberOfFamilies(MED_CELL)); + CPPUNIT_ASSERT_MESSAGE("Current mesh hasn't Families", NumberOfFamilies == 0); + + //create families - it's not possible to create, becase not all entities are defined + CPPUNIT_ASSERT_THROW( myMesh2->createFamilies(),MEDEXCEPTION); + + /*CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies = myMesh2->getNumberOfFamilies(MED_CELL)); + CPPUNIT_ASSERT( NumberOfFamilies != 0);*/ + + delete myMesh2; + } + + ////////////////////////////////////////////////////////////// + // TEST 2: Polygon and Polyhedron(only NODAL connectivity) // + ///////////////////////////////////////////////////////////// + + double CoordinatesPoly[57] = { + 2.0, 3.0, 2.0, + 3.0, 2.0, 2.0, + 4.0, 1.0, 2.0, + 2.0, 0.0, 2.0, + 0.0, 1.0, 2.0, + 1.0, 2.0, 2.0, + 2.0, 3.0, 1.0, + 3.0, 2.0, 0.0, + 4.0, 1.0, 0.0, + 2.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 1.0, 2.0, 0.0, + 5.0, 3.0, 2.0, + 7.0, 2.0, 2.0, + 6.0, 0.0, 2.0, + 6.0, 3.0, 0.0, + 7.0, 2.0, 0.0, + 6.0, 0.0, -1.0, + 5.0, 1.0, -3.0}; + + const int REFnodalConnOfFaces[74] = { + 1, 2, 3, 4, 5, 6, // Polyhedron 1 + 1, 7, 8, 2, + 2, 8, 9, 3, + 4, 3, 9, 10, + 5, 4, 10, 11, + 6, 5, 11, 12, + 1, 6, 12, 7, + 7, 12, 8, + 10, 9, 8, 12, 11, + + 13, 14, 15, 3, 2, // Polyhedron 2 + 13, 2, 8, 16, + 14, 13, 16, 17, + 15, 14, 17, + 15, 17, 18, + 15, 18, 9, + 3, 15, 9, + 2, 3, 9, 8, + 8, 9, 17, 16, + 9, 18, 17}; + const int NumberOfFaces = 19; + const int NumberOfPolyhedron = 2; + const int nbOfPolygons = 2; + const int REFfacesIndex[NumberOfFaces+1] = { + 1, 7, 11, 15, 19, 23, 27, 31, 34, + 39, 44, 48, 52, 55, 58, 61, 64, 68, 72, 75}; + + const int REFpolyIndex[NumberOfPolyhedron+1] = {1, 10, 20}; + + double PolygonCoordinates[27] = { + 2.0, 3.0, 12.0, + 3.0, 2.0, 12.0, + 4.0, 1.0, 12.0, + 2.0, 0.0, 12.0, + 0.0, 1.0, 12.0, + 1.0, 2.0, 12.0, + 5.0, 3.0, 12.0, + 7.0, 2.0, 12.0, + 6.0, 0.0, 12.0}; + + const int REFpolygonFaces[11] = { + 1, 2, 3, 4, 5, 6, // Polygon 1 + 7, 8, 9, 3, 2}; // Polygon 2 + + const int REFpolygonIndex[nbOfPolygons+1] = {1, 7, 12}; + + MESHING myMeshingPoly; + myMeshingPoly.setName("meshingpoly"); + + int MeshDimension = 3; + + const int NbOfTypes = 1; + medGeometryElement TypesPoly[NbOfTypes] = {MED_TETRA4}; + const int NbOfElements[NbOfTypes] = {1}; + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setNumberOfTypes(NbOfTypes, MED_CELL)); + + try + { + myMeshingPoly.setCoordinates(SpaceDimension, NumberOfNodes, CoordinatesPoly, + "CARTESIAN", MED_FULL_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myMeshingPoly.setSpaceDimension(SpaceDimension); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myMeshingPoly.setMeshDimension(MeshDimension); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setTypes(TypesPoly, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setNumberOfElements(NbOfElements, MED_CELL)); + + string Unit ="cm"; + for(int i = 0; i < SpaceDimension; i++ ) + { + try + { + myMeshingPoly.setCoordinateName(Names[i],i); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + try + { + myMeshingPoly.setCoordinateUnit(Unit, i); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + + int ConnectivityTetraPoly[4*1]= + { + 17, 9, 18, 19 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setConnectivity(ConnectivityTetraPoly, MED_CELL, MED_TETRA4)); + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setPolyhedraConnectivity(REFpolyIndex, REFfacesIndex, + REFnodalConnOfFaces, NumberOfPolyhedron, MED_CELL)); + + bool PolyConn = false; + CPPUNIT_ASSERT_NO_THROW(PolyConn = myMeshingPoly.existPolyhedronConnectivity(MED_NODAL, MED_CELL)); + if(PolyConn) + { + CPPUNIT_ASSERT_EQUAL(myMeshingPoly.getNumberOfPolyhedron(),NumberOfPolyhedron); + CPPUNIT_ASSERT_EQUAL(myMeshingPoly.getNumberOfPolyhedronFaces(),NumberOfFaces); + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.getPolyhedronConnectivityLength(MED_NODAL)); + const int * PolyConn; + const int * PolyFaceIdx; + const int * PolyIdx; + CPPUNIT_ASSERT_NO_THROW(PolyConn = myMeshingPoly.getPolyhedronConnectivity(MED_NODAL)); + CPPUNIT_ASSERT_NO_THROW(PolyFaceIdx = myMeshingPoly.getPolyhedronFacesIndex()); + CPPUNIT_ASSERT_NO_THROW(PolyIdx = myMeshingPoly.getPolyhedronIndex(MED_NODAL)); + for(int i = 0; i<NumberOfPolyhedron; i++) + { + int FaceIdxBegin = PolyIdx[i]; + int FaceIdxEnd = PolyIdx[i+1]; + for(int k = FaceIdxBegin; k < FaceIdxEnd; k++) + { + int IdxBegin = PolyFaceIdx[k-1]; + int IdxEnd = PolyFaceIdx[k]; + for(int j = IdxBegin; j < IdxEnd; j++ ) + CPPUNIT_ASSERT_EQUAL(PolyConn[j-1],REFnodalConnOfFaces[j-1]); + } + } + } + + MESHING myPolygonMeshing; + myPolygonMeshing.setName("PolygonMeshing"); + + medGeometryElement PolygonTypes[NbOfTypes] = {MED_TRIA3}; + const int PolygonNumberOfElements[NbOfTypes] = {2}; + + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setNumberOfTypes(NbOfTypes, MED_CELL)); + + try + { + myPolygonMeshing.setCoordinates(SpaceDimension, NumberOfNodes, PolygonCoordinates, + "CARTESIAN", MED_FULL_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + NumberOfNodes = 9; + SpaceDimension = 3; + MeshDimension = 2; + + myPolygonMeshing.setSpaceDimension(SpaceDimension); + CPPUNIT_ASSERT(myPolygonMeshing.getSpaceDimension() == 3); + myPolygonMeshing.setMeshDimension(MeshDimension); + CPPUNIT_ASSERT(myPolygonMeshing.getMeshDimension() == 2); + myPolygonMeshing.setNumberOfNodes(NumberOfNodes); + CPPUNIT_ASSERT(myPolygonMeshing.getNumberOfNodes() == 9); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setTypes(PolygonTypes, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setNumberOfElements(PolygonNumberOfElements, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setCoordinatesSystem("CARTESIAN")); + + try + { + myPolygonMeshing.setCoordinatesNames(Names); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myPolygonMeshing.setCoordinatesUnits(Units); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const int sizeTri = 3*2; + int ConnectivityTri[sizeTri]= + { + 1, 7, 2, 3, 9, 4 + }; + + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setConnectivity(ConnectivityTri, MED_CELL, MED_TRIA3)); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setPolygonsConnectivity + (REFpolygonIndex, REFpolygonFaces, nbOfPolygons, MED_CELL)); + + bool PolygonConn = false; + CPPUNIT_ASSERT_NO_THROW(PolygonConn = myPolygonMeshing.existPolygonsConnectivity(MED_NODAL, MED_CELL)); + if(PolygonConn) + { + int Polytypes; + CPPUNIT_ASSERT_NO_THROW(Polytypes = myPolygonMeshing.getNumberOfTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT(NbOfTypes != Polytypes); + + const MED_EN::medGeometryElement * PolyTypes; + CPPUNIT_ASSERT_NO_THROW(PolyTypes = myPolygonMeshing.getTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT_EQUAL(PolyTypes[NbOfTypes],MED_POLYGON); + + for(int t = 0; t < Polytypes; t++) + { + CPPUNIT_ASSERT_NO_THROW( myPolygonMeshing.getNumberOfElementsWithPoly(MED_CELL, PolyTypes[t])); + } + + medGeometryElement geomPolyElem; + CPPUNIT_ASSERT_NO_THROW(geomPolyElem = myPolygonMeshing.getElementTypeWithPoly(MED_CELL, 1)); + CPPUNIT_ASSERT_EQUAL(geomPolyElem, MED_TRIA3); + + CPPUNIT_ASSERT_EQUAL(myPolygonMeshing.getNumberOfPolygons(),nbOfPolygons); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.getPolygonsConnectivityLength(MED_NODAL,MED_CELL)); + const int * PolygonConn; + const int * PolygonIdx; + CPPUNIT_ASSERT_THROW(PolygonConn = myMeshingPoly.getPolygonsConnectivity(MED_NODAL,MED_CELL),MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(PolygonIdx = myMeshingPoly.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL),MEDEXCEPTION); + } + + ///////////////////////////////////////////////////// + // TEST : SUPPORT* sup = new SUPPORT(myMeshPointe) // + ///////////////////////////////////////////////////// + +#ifdef ENABLE_FAULTS + { + MESH * myMeshPointe = new MESH(); + myMeshPointe->setName(meshname); + MED_MESH_RDONLY_DRIVER myMeshDriver (filename, myMeshPointe); + myMeshDriver.setMeshName(meshname); + myMeshDriver.open(); + myMeshDriver.read(); + myMeshDriver.close(); + + SUPPORT* sup = new SUPPORT(myMeshPointe); + delete sup; + delete myMeshPointe; + } +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: can not create SUPPORT on mesh, read from pointe.med"); +#endif + + //////////////////////////////////////////////////////// + // TEST 3: test MESH on MEDMEMTest::createTestMesh()// + /////////////////////////////////////////////////////// + + MESH* myMesh3 = MEDMEMTest_createTestMesh(); + + int MeshDim = myMesh3->getMeshDimension(); + medEntityMesh constituentEntity; + if (MeshDim==3) { + constituentEntity = MED_CELL; + } + if (MeshDim==2) { + constituentEntity = MED_FACE; + } + if (MeshDim==1) { + constituentEntity = MED_EDGE; + } + + int SpaceDim = myMesh3->getSpaceDimension(); + + // Show Reverse Nodal Connectivity + const int* ReverseNodalConnectivity; + const int* ReverseNodalConnectivityIndex; + int ReverseLength; + int ReverseIdxLength; + + CONNECTIVITY* myConnectivity3 = (CONNECTIVITY*)myMesh3->getConnectivityptr(); + myConnectivity3->setNumberOfNodes(myMesh3->getNumberOfNodes()); + + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity= myMesh3->getReverseConnectivity(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(ReverseLength = myMesh3->getReverseConnectivityLength(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivityIndex = myMesh3->getReverseConnectivityIndex(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(ReverseIdxLength = myMesh3->getReverseConnectivityIndexLength(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT(ReverseIdxLength == myMesh3->getNumberOfNodes()+1); + + for (int i = 0; i < myMesh3->getNumberOfNodes(); i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + // Show Descending Connectivity + int NumberOfElements1; + const int * connectivity; + const int * connectivity_index; + myMesh3->calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_EN::MED_CELL); + try { + NumberOfElements1 = myMesh3->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS); + connectivity = myMesh3->getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_CELL, MED_ALL_ELEMENTS); + connectivity_index = myMesh3->getConnectivityIndex(MED_DESCENDING, MED_CELL); + } + catch (MEDEXCEPTION m) { + CPPUNIT_FAIL(m.what()); + } + + for (int j = 0; j < NumberOfElements1; j++) { + cout << "Element " << j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + + //test 3D mesh + for(int ind = SpaceDim; ind > 1; ind-- ) + { + int NumberOfElem = myMesh3->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS); + if(NumberOfElem < 1) continue; + + SUPPORT * sup = (SUPPORT*) NULL; + sup = new SUPPORT(myMesh3,"",constituentEntity); + + if (ind == 2) + { + // test of normal(for 1d or 2d elements) + FIELD<double>* normal; + CPPUNIT_ASSERT_NO_THROW(normal = myMesh3->getNormal(sup)); + + double normal_square, norm; + double maxnorm=0.; + double minnorm=0.; + double tmp_value; + for (int i = 1; i<=NumberOfElem; i++) { + normal_square = 0.; + cout << "Normal " << i << " "; + for (int j=1; j<=SpaceDim; j++) { + tmp_value = normal->getValueIJ(i,j); + normal_square += tmp_value*tmp_value; + cout << tmp_value << " "; + } + norm = sqrt(normal_square); + maxnorm = dmax(maxnorm,norm); + minnorm = dmin(minnorm,norm); + cout << ", Norm = " << norm << endl; + } + cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl; + delete normal; + + // test of area(for 2d elements) + FIELD<double>* area; + CPPUNIT_ASSERT_NO_THROW(area = myMesh3->getArea(sup)); + + double maxarea,minarea,areatot; + maxarea = 0.; + minarea = 0.; + areatot = 0.0; + for (int i = 1; i<=NumberOfElem;i++) + { + cout << "Area " << i << " " << area->getValueIJ(i,1) << endl; + maxarea = dmax(maxarea,area->getValueIJ(i,1)); + minarea = dmin(minarea,area->getValueIJ(i,1)); + areatot = areatot + area->getValueIJ(i,1); + } + + cout << "Max Area " << maxarea << " Min Area " << minarea << endl; + cout << "Support Area " << areatot << endl; + + delete area; + } + + // test of barycenter(for 3d and 2d elements) + FIELD<double>* barycenter; + CPPUNIT_ASSERT_NO_THROW(barycenter = myMesh3->getBarycenter(sup)); + + CPPUNIT_ASSERT_NO_THROW(NumberOfElem = myMesh3->getNumberOfElements(constituentEntity,MED_ALL_ELEMENTS)); + + for (int i = 1; i<=NumberOfElem;i++) + { + if (ind == 3) + cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << " " << barycenter->getValueIJ(i,3) << endl; + + if (ind == 2) + cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << endl; + } + delete barycenter; + + // test of volume(for 3d elements) + if (ind == 3) + { + FIELD<double>* volume; + CPPUNIT_ASSERT_NO_THROW(volume= myMesh3->getVolume(sup)); + + double maxvol,minvol,voltot; + maxvol = 0.; + minvol = 0.; + voltot = 0.0; + for (int i = 1; i<=NumberOfElem;i++) + { + cout << "Volume " << i << " " << volume->getValueIJ(i,1) << endl; + maxvol = dmax(maxvol,volume->getValueIJ(i,1)); + minvol = dmin(minvol,volume->getValueIJ(i,1)); + voltot = voltot + volume->getValueIJ(i,1); + } + + cout << "Max Volume " << maxvol << " Min Volume " << minvol << endl; + cout << "Support Volume " << voltot << endl; + + delete volume; + + // test of skin + SUPPORT *skin; + CPPUNIT_ASSERT_NO_THROW(skin = myMesh3->getSkin(sup)); + + //test mergeSupports and intersectSupports. vactor contains only 1 elements + vector<SUPPORT *> myVectSup; + myVectSup.push_back(skin); + + //method return a copy of skin object + SUPPORT *copyMergeSkin; + CPPUNIT_ASSERT_NO_THROW(copyMergeSkin = myMesh3->mergeSupports(myVectSup)); + try{ + CPPUNIT_ASSERT(copyMergeSkin->deepCompare(*skin)); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //method return a copy of skin object + SUPPORT *copyIntersectSkin; + CPPUNIT_ASSERT_NO_THROW(copyIntersectSkin = myMesh3->intersectSupports(myVectSup)); + try{ + CPPUNIT_ASSERT(copyIntersectSkin->deepCompare(*skin)); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + delete skin; + delete copyMergeSkin; + delete copyIntersectSkin; + } + + constituentEntity++; + } + + + // Testing length and normal vectors on 1d elements + { + // coordinates + int NumberOfNodes3 = 4; + + string Names3[3] = { "X","Y","Z" }; + string Units3[3] = { "cm","cm","cm" }; + + double Coordinates3[4*2] = {0.0, 0.0, // n1 + 1.0, 1.0, // n2 + 0.0, 1.0, // n3 + 1.0, 0.0}; // n4 + + const int NumberOfEdgeTypes = 1; + MED_EN::medGeometryElement EdgeTypes[NumberOfEdgeTypes] = {MED_SEG2}; + const int NumberOfEdges[NumberOfEdgeTypes] = {4}; + int ConnectivityEdge[4*2] = {1,2, 2,3, 3,4, 4,1}; + + // CREATE THE MESH + MEDMEM::MESHING* myMeshing3 = new MEDMEM::MESHING; + myMeshing3->setName("meshing3"); + myMeshing3->setCoordinates(/*SpaceDimension*/2, NumberOfNodes3, Coordinates3, + "CARTESIAN", MED_EN::MED_FULL_INTERLACE); + myMeshing3->setCoordinatesNames(Names3); + myMeshing3->setCoordinatesUnits(Units3); + + // define connectivities + // cell part + const int NumberOfTypes3 = 1; + medGeometryElement Types3[NumberOfTypes3] = {MED_QUAD4}; + const int NumberOfElements3[NumberOfTypes3] = {1}; + + myMeshing3->setNumberOfTypes(NumberOfTypes3,MED_CELL); + myMeshing3->setTypes(Types3,MED_CELL); + myMeshing3->setNumberOfElements(NumberOfElements3,MED_CELL); + + int Connectivityquad[1*4] = {1,2,3,4}; + + myMeshing3->setConnectivity(Connectivityquad,MED_CELL,MED_QUAD4); + + myMeshing3->setNumberOfTypes(NumberOfEdgeTypes, MED_EDGE); + myMeshing3->setTypes(EdgeTypes, MED_EDGE); + myMeshing3->setNumberOfElements(NumberOfEdges, MED_EDGE); + + myMeshing3->setConnectivity(ConnectivityEdge, MED_EDGE, MED_SEG2); + + // mesh dimension + myMeshing3->setMeshDimension(2); + + //test 2D mesh + int NumberOfElem = myMeshing3->getNumberOfElements (MED_EDGE, MED_ALL_ELEMENTS); + + SUPPORT * sup = new SUPPORT (myMeshing3, "", MED_EDGE); + + // test of normal(for 1d or 2d elements) + FIELD<double>* normal; + CPPUNIT_ASSERT_NO_THROW(normal = myMeshing3->getNormal(sup)); + + double normal_square, norm; + double maxnorm=0.; + double minnorm=0.; + double tmp_value; + for (int i = 1; i<=NumberOfElem; i++) { + normal_square = 0.; + cout << "Normal " << i << " "; + for (int j=1; j<=/*SpaceDimension*/2; j++) { + tmp_value = normal->getValueIJ(i,j); + normal_square += tmp_value*tmp_value; + cout << tmp_value << " "; + } + norm = sqrt(normal_square); + maxnorm = dmax(maxnorm,norm); + minnorm = dmin(minnorm,norm); + cout << ", Norm = " << norm << endl; + } + cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl; + + // test of length(for 1d elements) + FIELD<double>* length; + CPPUNIT_ASSERT_NO_THROW(length = myMeshing3->getLength(sup)); + + double length_value,maxlength,minlength; + maxlength = 0; + minlength = 0; + for (int i = 1; i<=NumberOfElem;i++) { + length_value = length->getValueIJ(i,1); + cout << "Length " << i << " " << length_value << endl; + maxlength = dmax(maxlength,length_value); + minlength = dmin(minlength,length_value); + } + cout << "Max Length " << maxlength << " Min Length " << minlength << endl; + + vector< FIELD<double> *> myVectField1; + myVectField1.push_back(normal); + myVectField1.push_back(length); + CPPUNIT_ASSERT_NO_THROW(myMeshing3->mergeFields(myVectField1)); + + delete normal; + delete length; + delete sup; + +#ifdef ENABLE_FAULTS + { + // (BUG) Segmentation fault if vector is empty + vector<SUPPORT *> myVectSupEmpty; + CPPUNIT_ASSERT_THROW(myMesh3->mergeSupports(myVectSupEmpty), MEDEXCEPTION); + } +#endif + + // test mergeFields method: Fields have the same value type + //intersectSupports and mergeSupports methods + { + SUPPORT * sup1 = new SUPPORT (myMeshing3, "", MED_EDGE); + SUPPORT * sup2 = new SUPPORT (myMeshing3, "", MED_EDGE); + MED_EN::medGeometryElement gtEdges[1] = {MED_SEG2}; + int nbEdges1[1] = {1}; + int edges1[1] = {1}; + int nbEdges2[1] = {2}; + int edges2[2] = {2,3}; + sup1->setpartial("description 1", 1, 1, gtEdges, nbEdges1, edges1); + sup2->setpartial("description 1", 1, 2, gtEdges, nbEdges2, edges2); + + vector<SUPPORT *> myVectSup3; + myVectSup3.push_back(sup1); + myVectSup3.push_back(sup2); + //method return a MergeSup on the union of all SUPPORTs in Supports. + SUPPORT *MergeSup; + CPPUNIT_ASSERT_NO_THROW(MergeSup = myMesh3->mergeSupports(myVectSup3)); + cout << *MergeSup << endl; + delete MergeSup; + + //method return a intersection of all SUPPORTs in IntersectSup + SUPPORT *IntersectSup; + CPPUNIT_ASSERT_NO_THROW(IntersectSup = myMesh3->intersectSupports(myVectSup3)); + if (IntersectSup != NULL) cout<< *IntersectSup <<endl; + delete IntersectSup; + + FIELD<double> * length1 = myMeshing3->getLength(sup1); + FIELD<double> * length2 = myMeshing3->getLength(sup2); + + vector< FIELD<double> *> myVect12; + myVect12.push_back(length1); + myVect12.push_back(length2); + + FIELD<double> * length12; + CPPUNIT_ASSERT_NO_THROW(length12 = myMeshing3->mergeFields(myVect12)); + delete length12; + + delete sup1; + delete sup2; + delete length1; + delete length2; + } + } + + ///////////////////////////////////////////////////////// + // TEST 4: test MESH constructed from file pointe.med // + //////////////////////////////////////////////////////// + MESH * myMesh4 = new MESH(); + myMesh4->setName(meshname); + MED_MESH_RDONLY_DRIVER myMeshDriver (filename, myMesh4); + myMeshDriver.setMeshName(meshname); + + //Mesh has no driver->segmentation violation + //CPPUNIT_ASSERT_THROW(myMesh4->read(), MEDEXCEPTION); + + //Add an existing MESH driver. + int myDriver4; + CPPUNIT_ASSERT_NO_THROW(myDriver4 = myMesh4->addDriver(myMeshDriver)); + + //read all objects in the file + CPPUNIT_ASSERT_NO_THROW(myMesh4->read(myDriver4)); + + if (myMesh4->getIsAGrid()) { + GRID* myGrid = dynamic_cast<GRID*>(myMesh4); + CPPUNIT_ASSERT(myGrid); + } + + //myDriver4->DRONLY->can't write + CPPUNIT_ASSERT_THROW(myMesh4->write(myDriver4), MEDEXCEPTION); + + // add new driver + int idMeshV21; + CPPUNIT_ASSERT_NO_THROW(idMeshV21 = myMesh4->addDriver(MED_DRIVER,filenameout21)); + + //Write all the content of the MESH using driver referenced by the integer handler index. + CPPUNIT_ASSERT_NO_THROW(myMesh4->write(idMeshV21)); + + // remove driver from mesh + CPPUNIT_ASSERT_NO_THROW(myMesh4->rmDriver(myDriver4)); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: driver with index idMedV21 has not been removed"); +#endif + // ensure exception is raised on second attempt to remove driver + //CPPUNIT_ASSERT_THROW(myMesh4->rmDriver(myDriver4),MEDEXCEPTION); + + // Create a MESH object using a MESH driver of type MED_DRIVER associated with file fileName. + MESH* myMesh5; + CPPUNIT_ASSERT_NO_THROW(myMesh5 = new MESH(MED_DRIVER, filename, meshname)); + if(myMesh5->getIsAGrid()){ + GRID* myGrid = dynamic_cast<GRID*>(myMesh4); + CPPUNIT_ASSERT(myGrid); + } + + //ensure two meshes constracted from one file in two different ways are equal + CPPUNIT_ASSERT(myMesh5->deepCompare(*myMesh4)); + + int myDriver6; + MESH* myMesh6 = new MESH(); + try{ + myDriver6 = myMesh6->addDriver(MED_DRIVER, filename, meshname, MED_LECT); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try{ + myMesh6->read(myDriver6); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //ensure two meshes constracted from one file in two different ways are equal + CPPUNIT_ASSERT(myMesh6->deepCompare(*myMesh4)); + + //test FAMILY + int NumberOfFamilies4; + CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies4 = myMesh6->getNumberOfFamilies(MED_CELL)); + CPPUNIT_ASSERT_MESSAGE("Current mesh hasn't Families", NumberOfFamilies4 != 0); + + vector<FAMILY*> families4; + CPPUNIT_ASSERT_NO_THROW(families4 = myMesh6->getFamilies(MED_CELL)); + CPPUNIT_ASSERT(families4.size() == NumberOfFamilies4); + for(int nb = 1; nb <= NumberOfFamilies4; nb++ ) + { + const FAMILY* family; + CPPUNIT_ASSERT_NO_THROW(family = myMesh6->getFamily(MED_CELL, nb)); + CPPUNIT_ASSERT_EQUAL(family->getName(), families4[nb-1]->getName()); + } + + //get support which reference all elements on the boundary of mesh. + SUPPORT*myBndSup; + CPPUNIT_ASSERT_THROW(myMesh6->getBoundaryElements(MED_CELL), MEDEXCEPTION); + //get only face in 3D. + CPPUNIT_ASSERT_NO_THROW(myBndSup = myMesh6->getBoundaryElements(MED_FACE)); + + //test buildSupportOnElementsFromElementList and buildSupportOnNodeFromElementList + const int * myConnectivityValue6; + CPPUNIT_ASSERT_NO_THROW(myConnectivityValue6 = myMesh6->getReverseConnectivity(MED_DESCENDING)); + const int * myConnectivityIndex6; + CPPUNIT_ASSERT_NO_THROW(myConnectivityIndex6 = myMesh6->getReverseConnectivityIndex(MED_DESCENDING)); + int numberOfElem6; + CPPUNIT_ASSERT_NO_THROW(numberOfElem6 = myMesh6->getNumberOfElementsWithPoly(MED_FACE,MED_ALL_ELEMENTS)); + list<int> myElementsList6; + + for (int i=0; i<numberOfElem6; i++) + if (myConnectivityValue6[myConnectivityIndex6[i]] == 0) { + myElementsList6.push_back(i+1); + } + + SUPPORT * mySupportOnNode; + SUPPORT * mySupportOnElem; + CPPUNIT_ASSERT_NO_THROW(mySupportOnElem = myMesh6->buildSupportOnElementsFromElementList(myElementsList6,MED_FACE)); + CPPUNIT_ASSERT(mySupportOnElem->deepCompare(*myBndSup)); + CPPUNIT_ASSERT_EQUAL(MED_FACE, mySupportOnElem->getEntity()); + + list<int>::const_iterator iteronelem = myElementsList6.begin(); + for (int i = 1; i <= 3; i++, iteronelem++) { + CPPUNIT_ASSERT_EQUAL(i, mySupportOnElem->getValIndFromGlobalNumber(*iteronelem)); + } + + CPPUNIT_ASSERT_NO_THROW(mySupportOnNode = myMesh6->buildSupportOnNodeFromElementList(myElementsList6,MED_FACE)); + CPPUNIT_ASSERT(mySupportOnNode->deepCompare( *(myMesh6->getBoundaryElements(MED_NODE)))); + + //sets mesh fields to initial values + try{ + myMesh6->init(); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //ensure two meshes constracted from one file in two different ways are equal + CPPUNIT_ASSERT(!myMesh6->deepCompare(*myMesh4)); + + //ensure mesh is empty + CPPUNIT_ASSERT(myMesh6->getSpaceDimension() == MED_INVALID); + CPPUNIT_ASSERT(myMesh6->getNumberOfNodes() == MED_INVALID); + CPPUNIT_ASSERT(myMesh6->getCoordinateptr() == NULL); + + delete myMesh4; + delete myMesh5; + delete myMesh6; + + MESH* myMesh7 = MEDMEMTest_createTestMesh(); + vector< vector<double> > myBndBox; + try{ + myBndBox = myMesh7->getBoundingBox(); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + cout<<"Bounding box for createTestMesh()"<<endl; + for(int i = 0; i < myBndBox.size(); i++) + { + for(int j = 0; j < myBndBox[i].size(); j++) + cout<<" "<< myBndBox[i][j]<<" "; + cout<<endl; + } + + double CoorPoint[3] = {0.0, 0.0, 1.0}; //n2 + int idxElem; + try{ + idxElem = myMesh7->getElementContainingPoint(CoorPoint); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(idxElem != -1); + + double CoorNoPoint[3] = {5.0, 0.0, -5.0}; //there is no such point + int idxNoElem; + try{ + idxNoElem = myMesh7->getElementContainingPoint(CoorNoPoint); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(idxNoElem == -1); + + /////////////////////////////////////////////////////// + // TEST 5: test desactivateFacesComputation() method // + // of driver: NPAL17670 // + /////////////////////////////////////////////////////// + double coords[54] = { + -0.215040, -0.107520, +0.000000, + +0.000000, -0.107520, +0.000000, + +0.000000, +0.107520, +0.000000, + -0.215040, +0.107520, +0.000000, + +0.215040, -0.107520, +0.000000, + +0.215040, +0.107520, +0.000000, + -0.215040, -0.107520, +1.500000, + -0.215040, -0.107520, +4.080623, + +0.000000, -0.107520, +1.500000, + +0.000000, -0.107520, +4.080623, + +0.000000, +0.107520, +1.500000, + +0.000000, +0.107520, +4.080623, + -0.215040, +0.107520, +1.500000, + -0.215040, +0.107520, +4.080623, + +0.215040, -0.107520, +1.500000, + +0.215040, -0.107520, +4.080623, + +0.215040, +0.107520, +1.500000, + +0.215040, +0.107520, +4.080623 + }; + + int connQuad4[] = { + 2 , 5 , 15 , 9 , + 10, 16 , 18 , 12, + 11 , 13 , 14 , 12, + 7 , 9 , 11 , 13, + 3 , 4 , 13 , 11, + 1 , 2 , 9 , 7, + 1 , 2 , 3 , 4, + 15 , 17 , 18 , 16 , + 5 , 6 , 17 , 15, + 9 , 15 , 17 , 11 , + 13 , 7 , 8 , 14, + 4 , 1 , 7 , 13, + 9 , 11 , 12 , 10, + 8 , 10 , 12 , 14, + 2 , 5 , 6 , 3, + 17 , 11, 12 , 18 , + 2 , 3 , 11 , 9, + 6 , 3 , 11 , 17, + 7 , 9 , 10 , 8, + 9 , 15 , 16 , 10 + }; + + int connHexa8[] = { + 3 , 2 , 1 , 4 , 11 , 9 , 7 , 13, + 17 , 15 , 9 , 11 , 18 , 16 , 10 , 12, + 11 , 9 , 7 , 13 , 12 , 10 , 8 , 14 , + 6 , 5 , 2 , 3 , 17 , 15 , 9 , 11 + }; + + int bottom[2] = {7,15}; + MED_EN::medGeometryElement bottomTypes[1] = {MED_EN::MED_QUAD4}; + int bottomIndex[2] = {1,3}; + int bottomNbOfElts[1] = {2}; + + MESHING* meshing = new MESHING(); + meshing->setName( "TESTMESH" ); + meshing->setSpaceDimension(3); + const int nFaces=20; + const int nNodes=18; + meshing->setNumberOfNodes(nNodes); + meshing->setCoordinates(3, nNodes, coords, "CARTESIAN", + MED_EN::MED_FULL_INTERLACE); + string coordname[3] = { "x", "y", "z" }; + meshing->setCoordinatesNames(coordname); + string coordunit[3] = { "m", "m", "m" }; + meshing->setCoordinatesUnits(coordunit); + //Cell connectivity info for classical elts + const MED_EN::medGeometryElement classicalTypesCell[1]={MED_EN::MED_HEXA8}; + const int nbOfCellElts[1]={4}; + meshing->setNumberOfTypes(1,MED_EN::MED_CELL); + meshing->setTypes(classicalTypesCell,MED_EN::MED_CELL); + meshing->setNumberOfElements(nbOfCellElts,MED_EN::MED_CELL); + meshing->setMeshDimension(3); + //Face connectivity info for classical elts + const MED_EN::medGeometryElement classicalTypesFace[1]={MED_EN::MED_QUAD4}; + const int nbOfFaceElts[1]={nFaces}; + meshing->setNumberOfTypes(1,MED_EN::MED_FACE); + meshing->setTypes(classicalTypesFace,MED_EN::MED_FACE); + meshing->setNumberOfElements(nbOfFaceElts,MED_EN::MED_FACE); + //All cell conn + meshing->setConnectivity(connHexa8,MED_EN::MED_CELL,MED_EN::MED_HEXA8); + //All face conn + meshing->setConnectivity(connQuad4,MED_EN::MED_FACE,MED_EN::MED_QUAD4); + //Adding some groups on faces + addMedFacesGroup( *meshing, 4, bottom, "BottomFaces",bottomTypes,bottomIndex,bottomNbOfElts,1) ; + //addMedFacesGroupAll( *meshing, "AllFaces"); + //writing... + int id=meshing->addDriver(MED_DRIVER,"out.med",meshing->getName()); + meshing->write(id); + // Field writing + SUPPORT *sup=new SUPPORT(meshing,"AllFaces",MED_FACE); + FIELD<double> * field = new FIELD<double>(sup, 1); + field->setName("temperature"); + field->setComponentName(1,"T"); field->setMEDComponentUnit(1,"K"); + double *tab=(double *)field->getValue(); + for(int i=0;i<nFaces;i++) + tab[i]=i*(1.22); + //field->setIterationNumber(-1); + field->setTime(12.); + id=field->addDriver(MED_DRIVER,"out.med",field->getName()); + field->write(id); + delete field; + delete meshing; + // + MED medObj(MED_DRIVER,"out.med"); + MESH *mesh=medObj.getMesh("TESTMESH"); + MED_MESH_RDONLY_DRIVER22 *drv=new MED_MESH_RDONLY_DRIVER22("out.med",mesh); + drv->desactivateFacesComputation(); + int newDrv=mesh->addDriver(*drv); + delete drv; + mesh->read(newDrv); + FIELD<double> *f=(FIELD<double> *)medObj.getField("temperature",-1,-1); + f->read(); + const int *conn=mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_ALL_ELEMENTS); + for (int j = 0; j < nFaces; j++) { + for (int k = 0; k < 4; k++) { + cout << conn[4*j+k] << " "; + CPPUNIT_ASSERT_EQUAL(conn[4*j+k], connQuad4[4*j+k]); + } + cout << endl; + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_MeshAndMeshing_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_MeshAndMeshing_fault.cxx new file mode 100644 index 000000000..c8aabee89 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_MeshAndMeshing_fault.cxx @@ -0,0 +1,1694 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_Group.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Grid.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +double dmax(double x, double y) { return (x>y)?x:y;} + +double dmin(double x, double y) { return (x>y)?y:x;} + +/*! + * Check methods (18), defined in MEDMEM_Meshing.hxx: + * class MESHING: public MESH { + * (+) MESHING(); + * (+) ~MESHING(); + * (+) void setSpaceDimension (const int SpaceDimension); + * (+) void setMeshDimension (const int MeshDimension); + * (+) void setNumberOfNodes (const int NumberOfNodes); + * (+) void setCoordinates (const int SpaceDimension, const int NumberOfNodes, + * const double * Coordinates, + * const string System, const MED_EN::medModeSwitch Mode); + * (+) void setCoordinatesSystem(const string System) throw (MEDEXCEPTION); + * (+) void setCoordinatesNames (const string * names); + * (+) void setCoordinateName (const string name, const int i); + * (+) void setCoordinatesUnits (const string * units); + * (+) void setCoordinateUnit (const string unit, const int i); + * (+) void setNumberOfTypes (const int NumberOfTypes, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setTypes (const MED_EN::medGeometryElement * Types, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setNumberOfElements (const int * NumberOfElements, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setConnectivity (const int * Connectivity, const MED_EN::medEntityMesh Entity, + * const MED_EN::medGeometryElement Type) throw (MEDEXCEPTION); + * (+) void setPolygonsConnectivity (const int * ConnectivityIndex, const int * ConnectivityValue, + * int nbOfPolygons, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void setPolyhedraConnectivity (const int * PolyhedronIndex, const int * FacesIndex, + * const int * Nodes, int nbOfPolyhedra, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (NOT YET IMPLEMENTED!!!) void setConnectivities (const int * ConnectivityIndex, + * const int * ConnectivityValue, + * const MED_EN::medConnectivity ConnectivityType, + * const MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) void addGroup (const GROUP & Group) throw (MEDEXCEPTION); + * } + */ + +/*! + * Check methods (87), defined in MEDMEM_Mesh.hxx: + * class MESH : public RCBASE { + * (+) void init(); + * (+) MESH(); + * (+) MESH(MESH &m); + * (+) MESH & operator=(const MESH &m); + * (+) virtual bool operator==(const MESH& other) const; + * (+) virtual bool deepCompare(const MESH& other) const; + * (+) MESH(driverTypes driverType, const string & fileName="", + * const string & meshName="") throw (MEDEXCEPTION); + * (+) virtual ~MESH(); + * (+) friend ostream & operator<<(ostream &os, const MESH &my); + * (+) int addDriver(driverTypes driverType, + * const string & fileName="Default File Name.med", + * const string & driverName="Default Mesh Name", + * MED_EN::med_mode_acces access=MED_EN::MED_REMP); + * (+) int addDriver(GENDRIVER & driver); + * (+) void rmDriver(int index=0); + * (+) virtual void read(int index=0); + * (must be private) inline void read(const GENDRIVER & genDriver); + * (+) inline void write(int index=0, const string & driverName = ""); + * (must be private) inline void write(const GENDRIVER & genDriver); + * (+) inline void setName(string name); + * (+) inline void setDescription(string description); + * (+) inline string getName() const; + * (+) inline string getDescription() const; + * (+) inline int getSpaceDimension() const; + * (+) inline int getMeshDimension() const; + * (+) inline bool getIsAGrid(); + * (+) inline int getNumberOfNodes() const; + * (+) virtual inline const COORDINATE * getCoordinateptr() const; + * (+) inline string getCoordinatesSystem() const; + * (+) virtual inline const double * getCoordinates(MED_EN::medModeSwitch Mode) const; + * (+) virtual inline const double getCoordinate(int Number,int Axis) const; + * (+) inline const string * getCoordinatesNames() const; + * (+) inline const string * getCoordinatesUnits() const; + * (+) virtual inline int getNumberOfTypes(MED_EN::medEntityMesh Entity) const; + * (+) virtual int getNumberOfTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const MED_EN::medGeometryElement * getTypes(MED_EN::medEntityMesh Entity) const; + * (+) virtual MED_EN::medGeometryElement * getTypesWithPoly(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const CELLMODEL * getCellsTypes(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline string * getCellTypeNames(MED_EN::medEntityMesh Entity) const; + * (+) virtual const int * getGlobalNumberingIndex(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline int getNumberOfElements(MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual int getNumberOfElementsWithPoly(MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual inline bool existConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline bool existPolygonsConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) inline bool existPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) virtual inline MED_EN::medGeometryElement getElementType + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) virtual inline MED_EN::medGeometryElement getElementTypeWithPoly + * (MED_EN::medEntityMesh Entity, int Number) const; + * (+) virtual inline void calculateConnectivity(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity) const; + * (+) virtual inline int getConnectivityLength(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual inline const int * getConnectivity(MED_EN::medModeSwitch Mode, + * MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, + * MED_EN::medGeometryElement Type) const; + * (+) virtual inline const int * getConnectivityIndex + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline int getPolygonsConnectivityLength + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline const int * getPolygonsConnectivity + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline const int * getPolygonsConnectivityIndex + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity) const; + * (+) inline int getNumberOfPolygons(MED_EN::medEntityMesh Entity=MED_EN::MED_ALL_ENTITIES) const; + * (+) inline int getPolyhedronConnectivityLength(MED_EN::medConnectivity ConnectivityType) const; + * (+) inline const int * getPolyhedronConnectivity(MED_EN::medConnectivity ConnectivityType) const; + * (+) inline const int * getPolyhedronFacesIndex() const; + * (+) inline const int * getPolyhedronIndex(MED_EN::medConnectivity ConnectivityType) const; + * (+) inline int getNumberOfPolyhedronFaces() const; + * (+) inline int getNumberOfPolyhedron() const; + * (+) virtual int getElementNumber(MED_EN::medConnectivity ConnectivityType, + * MED_EN::medEntityMesh Entity, MED_EN::medGeometryElement Type, + * int * connectivity) const; + * (+) virtual inline int getReverseConnectivityLength + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual inline const int * getReverseConnectivity + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual inline int getReverseConnectivityIndexLength + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual inline const int * getReverseConnectivityIndex + * (MED_EN::medConnectivity ConnectivityType, MED_EN::medEntityMesh Entity=MED_EN::MED_CELL) const; + * (+) virtual int getNumberOfFamilies(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const vector<FAMILY*> getFamilies(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const FAMILY* getFamily(MED_EN::medEntityMesh Entity,int i) const; + * (+) virtual int getNumberOfGroups(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const vector<GROUP*> getGroups(MED_EN::medEntityMesh Entity) const; + * (+) virtual inline const GROUP* getGroup(MED_EN::medEntityMesh Entity,int i) const; + * (+) virtual inline const CONNECTIVITY* getConnectivityptr() const; + * (+) virtual SUPPORT * getBoundaryElements(MED_EN::medEntityMesh Entity) throw (MEDEXCEPTION); + * (+) SUPPORT * getSkin(const SUPPORT * Support3D) throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getVolume (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getArea (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getLength (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getNormal (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) virtual FIELD<double>* getBarycenter (const SUPPORT * Support) const throw (MEDEXCEPTION); + * (+) static SUPPORT * mergeSupports(const vector<SUPPORT *> Supports) throw (MEDEXCEPTION); + * (+) static SUPPORT * intersectSupports(const vector<SUPPORT *> Supports) throw (MEDEXCEPTION); + * (+) void createFamilies(); + * (+) SUPPORT *buildSupportOnNodeFromElementList + * (const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); + * (do the same thing as buildSupportOnNodeFromElementList except that a SUPPORT is not created) void fillSupportOnNodeFromElementList + * (const list<int>& listOfElt, SUPPORT *supportToFill) const throw (MEDEXCEPTION); + * (+) SUPPORT *buildSupportOnElementsFromElementList + * (const list<int>& listOfElt, MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION); + * (+) int getElementContainingPoint(const double *coord); + * (+) vector< vector<double> > getBoundingBox() const; + * (+) template<class T> static + * FIELD<T> * mergeFields(const vector< FIELD<T> * > & others, bool meshCompare=false); + * (Presently disconnected in C++) virtual void addReference() const; + * (Presently disconnected in C++) virtual void removeReference() const; + * } + */ +void MEDMEMTest_testMeshAndMeshing() +{ + string datadir = getenv("DATA_DIR"); + string filename = datadir + "/MedFiles/pointe.med"; + string meshname = "maa1"; + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filenameout21 = tmp_dir + "/myMeshWrite4_pointe21.med"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filenameout21); + + //////////// + // TEST 1 // + //////////// + + MESH * myMesh= new MESH(); + myMesh->setName("FIRST_MESH"); + CPPUNIT_ASSERT(myMesh != NULL); + + //test operator << + //#ifdef ENABLE_FAULTS + //CPPUNIT_ASSERT_NO_THROW(cout << *myMesh << endl); + //#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: operator << : if mesh is empty then attempt" + " to get values from null object causes error"); +#endif + + //test operator = + MESH myMesh1 = *myMesh; + + //deepCompare +#ifdef ENABLE_FAULTS + bool isEqual = false; + CPPUNIT_ASSERT_NO_THROW(isEqual = myMesh1.deepCompare(*myMesh)); + CPPUNIT_ASSERT(isEqual); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: deepCompare(...) fails if mesh is empty"); +#endif + + //ensure it imposible to compare meshes + MESH *myMeshPointer = myMesh; + //test operator == + CPPUNIT_ASSERT(*myMeshPointer == *myMesh); + + delete myMesh; + + //set a MESH object + MESHING myMeshing; + myMeshing.setName("meshing"); + // define coordinates + + int SpaceDimension = 3; + int NumberOfNodes = 19; + double Coordinates[57] = { + 0.0, 0.0, 0.0, + 0.0, 0.0, 1.0, + 2.0, 0.0, 1.0, + 0.0, 2.0, 1.0, + -2.0, 0.0, 1.0, + 0.0, -2.0, 1.0, + 1.0, 1.0, 2.0, + -1.0, 1.0, 2.0, + -1.0, -1.0, 2.0, + 1.0, -1.0, 2.0, + 1.0, 1.0, 3.0, + -1.0, 1.0, 3.0, + -1.0, -1.0, 3.0, + 1.0, -1.0, 3.0, + 1.0, 1.0, 4.0, + -1.0, 1.0, 4.0, + -1.0, -1.0, 4.0, + 1.0, -1.0, 4.0, + 0.0, 0.0, 5.0 + }; + try + { + myMeshing.setCoordinates(SpaceDimension,NumberOfNodes,Coordinates,"CARTESIAN",MED_FULL_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + string Names[3] = { "X","Y","Z" }; + try + { + myMeshing.setCoordinatesNames(Names); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + string Units[3] = { "cm","cm","cm" }; + try + { + myMeshing.setCoordinatesUnits(Units); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // define conectivities + + // cell part + + const int NumberOfTypes = 3; + medGeometryElement Types[NumberOfTypes] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; + const int NumberOfElements[NumberOfTypes] = {12,2,2}; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfTypes(NumberOfTypes,MED_CELL)); + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setTypes(Types,MED_CELL)); + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfElements(NumberOfElements,MED_CELL)); + + const int sizeTetra = 12*4; + int ConnectivityTetra[sizeTetra]= + { + 1,2,3,6, + 1,2,4,3, + 1,2,5,4, + 1,2,6,5, + 2,7,4,3, + 2,8,5,4, + 2,9,6,5, + 2,10,3,6, + 2,7,3,10, + 2,8,4,7, + 2,9,5,8, + 2,10,6,9 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityTetra,MED_CELL,MED_TETRA4)); + + int ConnectivityPyra[2*5]= + { + 7,8,9,10,2, + 15,18,17,16,19 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityPyra,MED_CELL,MED_PYRA5)); + + int ConnectivityHexa[2*8]= + { + 11,12,13,14,7,8,9,10, + 15,16,17,18,11,12,13,14 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityHexa,MED_CELL,MED_HEXA8)); + + // face part + const int NumberOfFacesTypes = 2; + medGeometryElement FacesTypes[NumberOfFacesTypes] = {MED_TRIA3,MED_QUAD4}; + const int NumberOfFacesElements[NumberOfFacesTypes] = {4,4}; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfTypes(NumberOfFacesTypes,MED_FACE)); + CPPUNIT_ASSERT_NO_THROW(myMeshing.setTypes(FacesTypes,MED_FACE)); + CPPUNIT_ASSERT_NO_THROW(myMeshing.setNumberOfElements(NumberOfFacesElements,MED_FACE)); + const int nbTria = 4; + const int sizeTria = nbTria*3; + int ConnectivityTria[sizeTria]= + { + 1,4,3, + 1,5,4, + 1,6,5, + 1,3,6 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityTria,MED_FACE,MED_TRIA3)); + const int nbQua = 4; + int ConnectivityQua[nbQua*4]= + { + 7,8,9,10, + 11,12,13,14, + 11,7,8,12, + 12,8,9,13 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshing.setConnectivity(ConnectivityQua,MED_FACE,MED_QUAD4)); + + int meshDimension = SpaceDimension; // because there 3D cells in the mesh + try + { + myMeshing.setMeshDimension(meshDimension); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + // edge part + + // not yet implemented : if set, results are unpredictable. + + // Some groups : + + // Node : + { + GROUP myGroup; + myGroup.setName("SomeNodes"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_NODE); + myGroup.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_NONE}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {4}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,5}; + const int value[4]= { 1,4,5,7}; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + { + GROUP myGroup; + myGroup.setName("OtherNodes"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_NODE); + myGroup.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_NONE}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {3}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,4}; + const int value[3]= { 2,3,6}; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + + // Cell : + { + GROUP myGroup; + myGroup.setName("SomeCells"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_CELL); + myGroup.setNumberOfGeometricType(3); + medGeometryElement myTypes[3] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[3] = {4,1,2}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[3+1] = {1,5,6,8}; + const int value[4+1+2]= + { + 2,7,8,12, + 13, + 15,16 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + { + GROUP myGroup; + myGroup.setName("OtherCells"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_CELL); + myGroup.setNumberOfGeometricType(2); + medGeometryElement myTypes[] = {MED_TETRA4,MED_PYRA5}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[] = {4,1}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[2+1] = {1,5,6}; + const int value[4+1]= + { + 3,4,5,9, + 14 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + + // Face : + { + GROUP myGroup; + myGroup.setName("SomeFaces"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_FACE); + myGroup.setNumberOfGeometricType(2); + medGeometryElement myTypes[2] = {MED_TRIA3,MED_QUAD4}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[2] = {2,3}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[2+1] = {1,3,6}; + const int value[2+3]= + { + 2,4, + 5,6,8 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + { + GROUP myGroup; + myGroup.setName("OtherFaces"); + myGroup.setMesh(&myMeshing); + myGroup.setEntity(MED_FACE); + myGroup.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_TRIA3}; + myGroup.setGeometricType(myTypes); + const int myNumberOfElements[1] = {2}; + myGroup.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,3}; + const int value[2]= + { + 1,3 + }; + myGroup.setNumber(index,value); + CPPUNIT_ASSERT_NO_THROW(myMeshing.addGroup(myGroup)); + } + + //test Mesh(MESH &m) + { + MESH * myMesh2 = new MESH( myMeshing ); + CPPUNIT_ASSERT(myMesh2->deepCompare(myMeshing)); + + cout<<*myMesh2<<endl; + ostringstream os; + os << * myMesh2; + CPPUNIT_ASSERT(os.str() != ""); + + CPPUNIT_ASSERT_EQUAL(myMesh2->getName(),(string)"meshing"); + CPPUNIT_ASSERT((myMesh2->getDescription()).size() == 0); + myMesh2->setDescription("This class contains all information related to a 'meshing' mesh "); + CPPUNIT_ASSERT((myMesh2->getDescription()).size() != 0); + + CPPUNIT_ASSERT(myMesh2->getSpaceDimension() == SpaceDimension); + CPPUNIT_ASSERT(myMesh2->getMeshDimension() == meshDimension); + CPPUNIT_ASSERT(myMesh2->getNumberOfNodes() == NumberOfNodes); + + const COORDINATE* coord = myMesh2->getCoordinateptr(); + try + { + CPPUNIT_ASSERT(myMesh2->getCoordinatesSystem() != "catresian"); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const string * units; + try + { + units = myMesh2->getCoordinatesUnits(); + for (int axe = 0; axe < SpaceDimension; axe++) { + string verif = coord->getCoordinateUnit(axe+1); + CPPUNIT_ASSERT(verif == units[axe]); + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const string * noms; + try + { + noms = myMesh2->getCoordinatesNames(); + for (int axe = 0; axe < SpaceDimension; axe++) { + string verif = coord->getCoordinateName(axe+1); + CPPUNIT_ASSERT(verif == noms[axe]); + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + const double * coor2 = myMesh2->getCoordinates(MED_FULL_INTERLACE); + + for (int axe = 0; axe < SpaceDimension; axe++) { + try + { + for (int num = 0; num < NumberOfNodes; num++) { + try + { + const double d = myMesh2->getCoordinate(num + 1, axe + 1); + CPPUNIT_ASSERT(fabs(d - coor2[(num * SpaceDimension)+axe]) < 0.001); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const CONNECTIVITY * myConnectivity = myMesh2->getConnectivityptr(); + + // MED_EN::MED_CELL + MED_EN::medEntityMesh entity = myConnectivity->getEntity(); + CPPUNIT_ASSERT_EQUAL(MED_CELL, entity); + + int typesNb; + CPPUNIT_ASSERT_NO_THROW(typesNb= myConnectivity->getNumberOfTypes(entity)); + CPPUNIT_ASSERT_EQUAL(NumberOfTypes, typesNb); + + const MED_EN::medGeometryElement * Types1; + CPPUNIT_ASSERT_NO_THROW(Types1 = myMesh2->getTypes(entity)); + + medConnectivity myMedConnect; + bool existConnect = false; + if (myMesh2->existConnectivity(MED_NODAL, entity)) + { + existConnect = true; + myMedConnect = MED_NODAL; + } + else if(myMesh2->existConnectivity(MED_DESCENDING, entity)) + { + existConnect = true; + myMedConnect = MED_DESCENDING; + } + + for(int t = 0; t < NumberOfTypes; t++ ) + { + CPPUNIT_ASSERT_EQUAL(Types1[t], Types[t]); + int NumberOfElements1 = 0; + CPPUNIT_ASSERT_NO_THROW(NumberOfElements1 = myMesh2->getNumberOfElements(entity, Types1[t])); + CPPUNIT_ASSERT_EQUAL(NumberOfElements1, NumberOfElements[t]); + if(existConnect) + { + const int * connectivity; + const int * connectivity_index; + CPPUNIT_ASSERT_NO_THROW(connectivity = myMesh2->getConnectivity + (MED_FULL_INTERLACE, myMedConnect, entity, Types1[t])); + connectivity_index = myMesh2->getConnectivityIndex(myMedConnect, entity); + for (int j = 0; j < NumberOfElements1; j++) { + cout<<"!!!!!!!!!!!!!!!"<<endl; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + } + } + + const CELLMODEL* myCellModel = myMesh2->getCellsTypes(entity); + string* TypeNames; + CPPUNIT_ASSERT_NO_THROW(TypeNames = myMesh2->getCellTypeNames(entity)); + + for(int k = 0; k < NumberOfTypes; k++ ) + { + CPPUNIT_ASSERT_EQUAL(TypeNames[k], myCellModel[k].getName()); + } + delete [] TypeNames; + + const int* myGlobalNbIdx; + CPPUNIT_ASSERT_NO_THROW(myGlobalNbIdx = myMesh2->getGlobalNumberingIndex(MED_FACE)); + for(int i = 0; i <= NumberOfFacesTypes; i++) + { + if(i == NumberOfFacesTypes) + { + CPPUNIT_ASSERT_EQUAL(myGlobalNbIdx[i],nbTria+nbQua+1); + CPPUNIT_ASSERT_THROW(myMesh2->getElementType(MED_FACE, myGlobalNbIdx[i]), MEDEXCEPTION); + break; + } + cout<<"Global number of first element of each geom type : "<<myGlobalNbIdx[i]<<endl; + } + + { + const int * ReverseNodalConnectivity; + + // Show Reverse Nodal Connectivity +#ifndef ENABLE_FAULTS + // (BUG) CONNECTIVITY::_numberOfNodes is not set + ((CONNECTIVITY*)myConnectivity)->setNumberOfNodes(NumberOfNodes); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR in CONNECTIVITY::calculateReverseNodalConnectivity()" + " because myMesh2->_connectivity->_numberOfNodes is not set"); +#endif + + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity = myMesh2->getReverseConnectivity(MED_NODAL, entity)); + CPPUNIT_ASSERT_NO_THROW(myMesh2->getReverseConnectivityLength(MED_NODAL, entity)); + const int * ReverseNodalConnectivityIndex = myMesh2->getReverseConnectivityIndex(MED_NODAL, entity); + const int ReverseIdxLength = myMesh2->getReverseConnectivityIndexLength(MED_NODAL, entity); + CPPUNIT_ASSERT(ReverseIdxLength == NumberOfNodes+1); + for (int i = 0; i < NumberOfNodes; i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + // Show Descending Connectivity + int NumberOfElements1; + const int * connectivity; + const int * connectivity_index; + myMesh2->calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, entity); + try { + NumberOfElements1 = myMesh2->getNumberOfElements(entity, MED_ALL_ELEMENTS); + connectivity = myMesh2->getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, entity, MED_ALL_ELEMENTS); + connectivity_index = myMesh2->getConnectivityIndex(MED_DESCENDING, entity); + } + catch (MEDEXCEPTION m) { + CPPUNIT_FAIL(m.what()); + } + + for (int j = 0; j < NumberOfElements1; j++) { + cout << "Element " << j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + + // getElementNumber + if (myMesh2->existConnectivity(MED_NODAL, MED_FACE)) { + int myTr[3] = {1,5,4}; + CPPUNIT_ASSERT_NO_THROW(myMesh2->getElementNumber(MED_NODAL,MED_FACE,MED_TRIA3,myTr)); + } + } + + //test family and group + int NumberOfGroups; + CPPUNIT_ASSERT_THROW(myMesh2->getNumberOfGroups(MED_ALL_ENTITIES), MEDEXCEPTION); + CPPUNIT_ASSERT_NO_THROW(NumberOfGroups = myMesh2->getNumberOfGroups(MED_CELL)); + CPPUNIT_ASSERT_EQUAL(NumberOfGroups, 2); + vector<GROUP*> groups; + CPPUNIT_ASSERT_NO_THROW(groups = myMesh2->getGroups(MED_CELL)); + CPPUNIT_ASSERT(groups.size() != 0); + for(int nb = 1; nb <= NumberOfGroups; nb++ ) + { + const GROUP* group; + CPPUNIT_ASSERT_NO_THROW(group = myMesh2->getGroup(MED_CELL, nb)); + CPPUNIT_ASSERT_EQUAL(group->getName(), groups[nb-1]->getName()); + } + + int NumberOfFamilies; + CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies = myMesh2->getNumberOfFamilies(MED_CELL)); + CPPUNIT_ASSERT_MESSAGE("Current mesh hasn't Families", NumberOfFamilies == 0); + + //create families - it's not possible to create, becase not all entities are defined + CPPUNIT_ASSERT_THROW( myMesh2->createFamilies(),MEDEXCEPTION); + + /*CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies = myMesh2->getNumberOfFamilies(MED_CELL)); + CPPUNIT_ASSERT( NumberOfFamilies != 0);*/ + + delete myMesh2; + } + + ////////////////////////////////////////////////////////////// + // TEST 2: Polygon and Polyhedron(only NODAL connectivity) // + ///////////////////////////////////////////////////////////// + + double CoordinatesPoly[57] = { + 2.0, 3.0, 2.0, + 3.0, 2.0, 2.0, + 4.0, 1.0, 2.0, + 2.0, 0.0, 2.0, + 0.0, 1.0, 2.0, + 1.0, 2.0, 2.0, + 2.0, 3.0, 1.0, + 3.0, 2.0, 0.0, + 4.0, 1.0, 0.0, + 2.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 1.0, 2.0, 0.0, + 5.0, 3.0, 2.0, + 7.0, 2.0, 2.0, + 6.0, 0.0, 2.0, + 6.0, 3.0, 0.0, + 7.0, 2.0, 0.0, + 6.0, 0.0, -1.0, + 5.0, 1.0, -3.0}; + + const int REFnodalConnOfFaces[74] = { + 1, 2, 3, 4, 5, 6, // Polyhedron 1 + 1, 7, 8, 2, + 2, 8, 9, 3, + 4, 3, 9, 10, + 5, 4, 10, 11, + 6, 5, 11, 12, + 1, 6, 12, 7, + 7, 12, 8, + 10, 9, 8, 12, 11, + + 13, 14, 15, 3, 2, // Polyhedron 2 + 13, 2, 8, 16, + 14, 13, 16, 17, + 15, 14, 17, + 15, 17, 18, + 15, 18, 9, + 3, 15, 9, + 2, 3, 9, 8, + 8, 9, 17, 16, + 9, 18, 17}; + const int NumberOfFaces = 19; + const int NumberOfPolyhedron = 2; + const int nbOfPolygons = 2; + const int REFfacesIndex[NumberOfFaces+1] = { + 1, 7, 11, 15, 19, 23, 27, 31, 34, + 39, 44, 48, 52, 55, 58, 61, 64, 68, 72, 75}; + + const int REFpolyIndex[NumberOfPolyhedron+1] = {1, 10, 20}; + + double PolygonCoordinates[27] = { + 2.0, 3.0, 12.0, + 3.0, 2.0, 12.0, + 4.0, 1.0, 12.0, + 2.0, 0.0, 12.0, + 0.0, 1.0, 12.0, + 1.0, 2.0, 12.0, + 5.0, 3.0, 12.0, + 7.0, 2.0, 12.0, + 6.0, 0.0, 12.0}; + + const int REFpolygonFaces[11] = { + 1, 2, 3, 4, 5, 6, // Polygon 1 + 7, 8, 9, 3, 2}; // Polygon 2 + + const int REFpolygonIndex[nbOfPolygons+1] = {1, 7, 12}; + + MESHING myMeshingPoly; + myMeshingPoly.setName("meshingpoly"); + + int MeshDimension = 3; + + const int NbOfTypes = 1; + medGeometryElement TypesPoly[NbOfTypes] = {MED_TETRA4}; + const int NbOfElements[NbOfTypes] = {1}; + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setNumberOfTypes(NbOfTypes, MED_CELL)); + + try + { + myMeshingPoly.setCoordinates(SpaceDimension, NumberOfNodes, CoordinatesPoly, + "CARTESIAN", MED_FULL_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myMeshingPoly.setSpaceDimension(SpaceDimension); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myMeshingPoly.setMeshDimension(MeshDimension); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setTypes(TypesPoly, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setNumberOfElements(NbOfElements, MED_CELL)); + + string Unit ="cm"; + for(int i = 0; i < SpaceDimension; i++ ) + { + try + { + myMeshingPoly.setCoordinateName(Names[i],i); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + try + { + myMeshingPoly.setCoordinateUnit(Unit, i); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + + int ConnectivityTetraPoly[4*1]= + { + 17, 9, 18, 19 + }; + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setConnectivity(ConnectivityTetraPoly, MED_CELL, MED_TETRA4)); + + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.setPolyhedraConnectivity(REFpolyIndex, REFfacesIndex, + REFnodalConnOfFaces, NumberOfPolyhedron, MED_CELL)); + + bool PolyConn = false; + CPPUNIT_ASSERT_NO_THROW(PolyConn = myMeshingPoly.existPolyhedronConnectivity(MED_NODAL, MED_CELL)); + if(PolyConn) + { + CPPUNIT_ASSERT_EQUAL(myMeshingPoly.getNumberOfPolyhedron(),NumberOfPolyhedron); + CPPUNIT_ASSERT_EQUAL(myMeshingPoly.getNumberOfPolyhedronFaces(),NumberOfFaces); + CPPUNIT_ASSERT_NO_THROW(myMeshingPoly.getPolyhedronConnectivityLength(MED_NODAL)); + const int * PolyConn; + const int * PolyFaceIdx; + const int * PolyIdx; + CPPUNIT_ASSERT_NO_THROW(PolyConn = myMeshingPoly.getPolyhedronConnectivity(MED_NODAL)); + CPPUNIT_ASSERT_NO_THROW(PolyFaceIdx = myMeshingPoly.getPolyhedronFacesIndex()); + CPPUNIT_ASSERT_NO_THROW(PolyIdx = myMeshingPoly.getPolyhedronIndex(MED_NODAL)); + for(int i = 0; i<NumberOfPolyhedron; i++) + { + int FaceIdxBegin = PolyIdx[i]; + int FaceIdxEnd = PolyIdx[i+1]; + for(int k = FaceIdxBegin; k < FaceIdxEnd; k++) + { + int IdxBegin = PolyFaceIdx[k-1]; + int IdxEnd = PolyFaceIdx[k]; + for(int j = IdxBegin; j < IdxEnd; j++ ) + CPPUNIT_ASSERT_EQUAL(PolyConn[j-1],REFnodalConnOfFaces[j-1]); + } + } + } + + MESHING myPolygonMeshing; + myPolygonMeshing.setName("PolygonMeshing"); + + medGeometryElement PolygonTypes[NbOfTypes] = {MED_TRIA3}; + const int PolygonNumberOfElements[NbOfTypes] = {2}; + + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setNumberOfTypes(NbOfTypes, MED_CELL)); + + try + { + myPolygonMeshing.setCoordinates(SpaceDimension, NumberOfNodes, PolygonCoordinates, + "CARTESIAN", MED_FULL_INTERLACE); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + NumberOfNodes = 9; + SpaceDimension = 3; + MeshDimension = 2; + + myPolygonMeshing.setSpaceDimension(SpaceDimension); + CPPUNIT_ASSERT(myPolygonMeshing.getSpaceDimension() == 3); + myPolygonMeshing.setMeshDimension(MeshDimension); + CPPUNIT_ASSERT(myPolygonMeshing.getMeshDimension() == 2); + myPolygonMeshing.setNumberOfNodes(NumberOfNodes); + CPPUNIT_ASSERT(myPolygonMeshing.getNumberOfNodes() == 9); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setTypes(PolygonTypes, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setNumberOfElements(PolygonNumberOfElements, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setCoordinatesSystem("CARTESIAN")); + + try + { + myPolygonMeshing.setCoordinatesNames(Names); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myPolygonMeshing.setCoordinatesUnits(Units); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const int sizeTri = 3*2; + int ConnectivityTri[sizeTri]= + { + 1, 7, 2, 3, 9, 4 + }; + + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setConnectivity(ConnectivityTri, MED_CELL, MED_TRIA3)); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.setPolygonsConnectivity + (REFpolygonIndex, REFpolygonFaces, nbOfPolygons, MED_CELL)); + + bool PolygonConn = false; + CPPUNIT_ASSERT_NO_THROW(PolygonConn = myPolygonMeshing.existPolygonsConnectivity(MED_NODAL, MED_CELL)); + if(PolygonConn) + { + int Polytypes; + CPPUNIT_ASSERT_NO_THROW(Polytypes = myPolygonMeshing.getNumberOfTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT(NbOfTypes != Polytypes); + + const MED_EN::medGeometryElement * PolyTypes; + CPPUNIT_ASSERT_NO_THROW(PolyTypes = myPolygonMeshing.getTypesWithPoly(MED_CELL)); + CPPUNIT_ASSERT_EQUAL(PolyTypes[NbOfTypes],MED_POLYGON); + + for(int t = 0; t < Polytypes; t++) + { + CPPUNIT_ASSERT_NO_THROW( myPolygonMeshing.getNumberOfElementsWithPoly(MED_CELL, PolyTypes[t])); + } + + medGeometryElement geomPolyElem; + CPPUNIT_ASSERT_NO_THROW(geomPolyElem = myPolygonMeshing.getElementTypeWithPoly(MED_CELL, 1)); + CPPUNIT_ASSERT_EQUAL(geomPolyElem, MED_TRIA3); + + CPPUNIT_ASSERT_EQUAL(myPolygonMeshing.getNumberOfPolygons(),nbOfPolygons); + CPPUNIT_ASSERT_NO_THROW(myPolygonMeshing.getPolygonsConnectivityLength(MED_NODAL,MED_CELL)); + const int * PolygonConn; + const int * PolygonIdx; + CPPUNIT_ASSERT_THROW(PolygonConn = myMeshingPoly.getPolygonsConnectivity(MED_NODAL,MED_CELL),MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(PolygonIdx = myMeshingPoly.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL),MEDEXCEPTION); + } + + ///////////////////////////////////////////////////// + // TEST : SUPPORT* sup = new SUPPORT(myMeshPointe) // + ///////////////////////////////////////////////////// + +#ifdef ENABLE_FAULTS + { + MESH * myMeshPointe = new MESH(); + myMeshPointe->setName(meshname); + MED_MESH_RDONLY_DRIVER myMeshDriver (filename, myMeshPointe); + myMeshDriver.setMeshName(meshname); + myMeshDriver.open(); + myMeshDriver.read(); + myMeshDriver.close(); + + SUPPORT* sup = new SUPPORT(myMeshPointe); + delete sup; + delete myMeshPointe; + } +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: can not create SUPPORT on mesh, read from pointe.med"); +#endif + + //////////////////////////////////////////////////////// + // TEST 3: test MESH on MEDMEMTest::createTestMesh()// + /////////////////////////////////////////////////////// + + MESH* myMesh3 = MEDMEMTest_createTestMesh(); + + int MeshDim = myMesh3->getMeshDimension(); + medEntityMesh constituentEntity; + if (MeshDim==3) { + constituentEntity = MED_CELL; + } + if (MeshDim==2) { + constituentEntity = MED_FACE; + } + if (MeshDim==1) { + constituentEntity = MED_EDGE; + } + + int SpaceDim = myMesh3->getSpaceDimension(); + + // Show Reverse Nodal Connectivity + const int* ReverseNodalConnectivity; + const int* ReverseNodalConnectivityIndex; + int ReverseLength; + int ReverseIdxLength; + + CONNECTIVITY* myConnectivity3 = (CONNECTIVITY*)myMesh3->getConnectivityptr(); + myConnectivity3->setNumberOfNodes(myMesh3->getNumberOfNodes()); + + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivity= myMesh3->getReverseConnectivity(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(ReverseLength = myMesh3->getReverseConnectivityLength(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(ReverseNodalConnectivityIndex = myMesh3->getReverseConnectivityIndex(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT_NO_THROW(ReverseIdxLength = myMesh3->getReverseConnectivityIndexLength(MED_NODAL, MED_CELL)); + CPPUNIT_ASSERT(ReverseIdxLength == myMesh3->getNumberOfNodes()+1); + + for (int i = 0; i < myMesh3->getNumberOfNodes(); i++) { + cout << "Node "<< i+1 << " : "; + for (int j = ReverseNodalConnectivityIndex[i]; j < ReverseNodalConnectivityIndex[i+1]; j++) + cout << ReverseNodalConnectivity[j-1] << " "; + cout << endl; + } + + // Show Descending Connectivity + int NumberOfElements1; + const int * connectivity; + const int * connectivity_index; + myMesh3->calculateConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_EN::MED_CELL); + try { + NumberOfElements1 = myMesh3->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS); + connectivity = myMesh3->getConnectivity(MED_FULL_INTERLACE, MED_DESCENDING, MED_CELL, MED_ALL_ELEMENTS); + connectivity_index = myMesh3->getConnectivityIndex(MED_DESCENDING, MED_CELL); + } + catch (MEDEXCEPTION m) { + CPPUNIT_FAIL(m.what()); + } + + for (int j = 0; j < NumberOfElements1; j++) { + cout << "Element " << j+1 << " : "; + for (int k = connectivity_index[j]; k < connectivity_index[j+1]; k++) + cout << connectivity[k-1] << " "; + cout << endl; + } + + //test 3D mesh + for(int ind = SpaceDim; ind > 1; ind-- ) + { + int NumberOfElem = myMesh3->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS); + if(NumberOfElem < 1) continue; + + SUPPORT * sup = (SUPPORT*) NULL; + sup = new SUPPORT(myMesh3,"",constituentEntity); + + if (ind == 2) + { + // test of normal(for 1d or 2d elements) + FIELD<double>* normal; + CPPUNIT_ASSERT_NO_THROW(normal = myMesh3->getNormal(sup)); + + double normal_square, norm; + double maxnorm=0.; + double minnorm=0.; + double tmp_value; + for (int i = 1; i<=NumberOfElem; i++) { + normal_square = 0.; + cout << "Normal " << i << " "; + for (int j=1; j<=SpaceDim; j++) { + tmp_value = normal->getValueIJ(i,j); + normal_square += tmp_value*tmp_value; + cout << tmp_value << " "; + } + norm = sqrt(normal_square); + maxnorm = dmax(maxnorm,norm); + minnorm = dmin(minnorm,norm); + cout << ", Norm = " << norm << endl; + } + cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl; + delete normal; + + // test of area(for 2d elements) + FIELD<double>* area; + CPPUNIT_ASSERT_NO_THROW(area = myMesh3->getArea(sup)); + + double maxarea,minarea,areatot; + maxarea = 0.; + minarea = 0.; + areatot = 0.0; + for (int i = 1; i<=NumberOfElem;i++) + { + cout << "Area " << i << " " << area->getValueIJ(i,1) << endl; + maxarea = dmax(maxarea,area->getValueIJ(i,1)); + minarea = dmin(minarea,area->getValueIJ(i,1)); + areatot = areatot + area->getValueIJ(i,1); + } + + cout << "Max Area " << maxarea << " Min Area " << minarea << endl; + cout << "Support Area " << areatot << endl; + + delete area; + } + + // test of barycenter(for 3d and 2d elements) + FIELD<double>* barycenter; + CPPUNIT_ASSERT_NO_THROW(barycenter = myMesh3->getBarycenter(sup)); + + CPPUNIT_ASSERT_NO_THROW(NumberOfElem = myMesh3->getNumberOfElements(constituentEntity,MED_ALL_ELEMENTS)); + + for (int i = 1; i<=NumberOfElem;i++) + { + if (ind == 3) + cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << " " << barycenter->getValueIJ(i,3) << endl; + + if (ind == 2) + cout << "Barycenter " << i << " " << barycenter->getValueIJ(i,1) << " " << barycenter->getValueIJ(i,2) << endl; + } + delete barycenter; + + // test of volume(for 3d elements) + if (ind == 3) + { + FIELD<double>* volume; + CPPUNIT_ASSERT_NO_THROW(volume= myMesh3->getVolume(sup)); + + double maxvol,minvol,voltot; + maxvol = 0.; + minvol = 0.; + voltot = 0.0; + for (int i = 1; i<=NumberOfElem;i++) + { + cout << "Volume " << i << " " << volume->getValueIJ(i,1) << endl; + maxvol = dmax(maxvol,volume->getValueIJ(i,1)); + minvol = dmin(minvol,volume->getValueIJ(i,1)); + voltot = voltot + volume->getValueIJ(i,1); + } + + cout << "Max Volume " << maxvol << " Min Volume " << minvol << endl; + cout << "Support Volume " << voltot << endl; + + delete volume; + + // test of skin + SUPPORT *skin; + CPPUNIT_ASSERT_NO_THROW(skin = myMesh3->getSkin(sup)); + + //test mergeSupports and intersectSupports. vactor contains only 1 elements + vector<SUPPORT *> myVectSup; + myVectSup.push_back(skin); + + //method return a copy of skin object + SUPPORT *copyMergeSkin; + CPPUNIT_ASSERT_NO_THROW(copyMergeSkin = myMesh3->mergeSupports(myVectSup)); + try{ + CPPUNIT_ASSERT(copyMergeSkin->deepCompare(*skin)); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //method return a copy of skin object + SUPPORT *copyIntersectSkin; + CPPUNIT_ASSERT_NO_THROW(copyIntersectSkin = myMesh3->intersectSupports(myVectSup)); + try{ + CPPUNIT_ASSERT(copyIntersectSkin->deepCompare(*skin)); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + delete skin; + delete copyMergeSkin; + delete copyIntersectSkin; + } + + constituentEntity++; + } + + + // Testing length and normal vectors on 1d elements + { + // coordinates + int NumberOfNodes3 = 4; + + string Names3[3] = { "X","Y","Z" }; + string Units3[3] = { "cm","cm","cm" }; + + double Coordinates3[4*2] = {0.0, 0.0, // n1 + 1.0, 1.0, // n2 + 0.0, 1.0, // n3 + 1.0, 0.0}; // n4 + + const int NumberOfEdgeTypes = 1; + MED_EN::medGeometryElement EdgeTypes[NumberOfEdgeTypes] = {MED_SEG2}; + const int NumberOfEdges[NumberOfEdgeTypes] = {4}; + int ConnectivityEdge[4*2] = {1,2, 2,3, 3,4, 4,1}; + + // CREATE THE MESH + MEDMEM::MESHING* myMeshing3 = new MEDMEM::MESHING; + myMeshing3->setName("meshing3"); + myMeshing3->setCoordinates(/*SpaceDimension*/2, NumberOfNodes3, Coordinates3, + "CARTESIAN", MED_EN::MED_FULL_INTERLACE); + myMeshing3->setCoordinatesNames(Names3); + myMeshing3->setCoordinatesUnits(Units3); + + // define connectivities + // cell part + const int NumberOfTypes3 = 1; + medGeometryElement Types3[NumberOfTypes3] = {MED_QUAD4}; + const int NumberOfElements3[NumberOfTypes3] = {1}; + + myMeshing3->setNumberOfTypes(NumberOfTypes3,MED_CELL); + myMeshing3->setTypes(Types3,MED_CELL); + myMeshing3->setNumberOfElements(NumberOfElements3,MED_CELL); + + int Connectivityquad[1*4] = {1,2,3,4}; + + myMeshing3->setConnectivity(Connectivityquad,MED_CELL,MED_QUAD4); + + myMeshing3->setNumberOfTypes(NumberOfEdgeTypes, MED_EDGE); + myMeshing3->setTypes(EdgeTypes, MED_EDGE); + myMeshing3->setNumberOfElements(NumberOfEdges, MED_EDGE); + + myMeshing3->setConnectivity(ConnectivityEdge, MED_EDGE, MED_SEG2); + + // mesh dimension + myMeshing3->setMeshDimension(2); + + //test 2D mesh + int NumberOfElem = myMeshing3->getNumberOfElements (MED_EDGE, MED_ALL_ELEMENTS); + + SUPPORT * sup = new SUPPORT (myMeshing3, "", MED_EDGE); + + // test of normal(for 1d or 2d elements) + FIELD<double>* normal; + CPPUNIT_ASSERT_NO_THROW(normal = myMeshing3->getNormal(sup)); + + double normal_square, norm; + double maxnorm=0.; + double minnorm=0.; + double tmp_value; + for (int i = 1; i<=NumberOfElem; i++) { + normal_square = 0.; + cout << "Normal " << i << " "; + for (int j=1; j<=/*SpaceDimension*/2; j++) { + tmp_value = normal->getValueIJ(i,j); + normal_square += tmp_value*tmp_value; + cout << tmp_value << " "; + } + norm = sqrt(normal_square); + maxnorm = dmax(maxnorm,norm); + minnorm = dmin(minnorm,norm); + cout << ", Norm = " << norm << endl; + } + cout << "Max Norm " << maxnorm << " Min Norm " << minnorm << endl; + + // test of length(for 1d elements) + FIELD<double>* length; + CPPUNIT_ASSERT_NO_THROW(length = myMeshing3->getLength(sup)); + + double length_value,maxlength,minlength; + maxlength = 0; + minlength = 0; + for (int i = 1; i<=NumberOfElem;i++) { + length_value = length->getValueIJ(i,1); + cout << "Length " << i << " " << length_value << endl; + maxlength = dmax(maxlength,length_value); + minlength = dmin(minlength,length_value); + } + cout << "Max Length " << maxlength << " Min Length " << minlength << endl; + + vector< FIELD<double> *> myVectField1; + myVectField1.push_back(normal); + myVectField1.push_back(length); + CPPUNIT_ASSERT_NO_THROW(myMeshing3->mergeFields(myVectField1)); + + delete normal; + delete length; + delete sup; + +#ifdef ENABLE_FAULTS + { + // (BUG) Segmentation fault if vector is empty + vector<SUPPORT *> myVectSupEmpty; + CPPUNIT_ASSERT_THROW(myMesh3->mergeSupports(myVectSupEmpty), MEDEXCEPTION); + } +#endif + + // test mergeFields method: Fields have the same value type + //intersectSupports and mergeSupports methods + { + SUPPORT * sup1 = new SUPPORT (myMeshing3, "", MED_EDGE); + SUPPORT * sup2 = new SUPPORT (myMeshing3, "", MED_EDGE); + MED_EN::medGeometryElement gtEdges[1] = {MED_SEG2}; + int nbEdges1[1] = {1}; + int edges1[1] = {1}; + int nbEdges2[1] = {2}; + int edges2[2] = {2,3}; + sup1->setpartial("description 1", 1, 1, gtEdges, nbEdges1, edges1); + sup2->setpartial("description 1", 1, 2, gtEdges, nbEdges2, edges2); + + vector<SUPPORT *> myVectSup3; + myVectSup3.push_back(sup1); + myVectSup3.push_back(sup2); + //method return a MergeSup on the union of all SUPPORTs in Supports. + SUPPORT *MergeSup; + CPPUNIT_ASSERT_NO_THROW(MergeSup = myMesh3->mergeSupports(myVectSup3)); + cout << *MergeSup << endl; + delete MergeSup; + + //method return a intersection of all SUPPORTs in IntersectSup + SUPPORT *IntersectSup; + CPPUNIT_ASSERT_NO_THROW(IntersectSup = myMesh3->intersectSupports(myVectSup3)); + if (IntersectSup != NULL) cout<< *IntersectSup <<endl; + delete IntersectSup; + + FIELD<double> * length1 = myMeshing3->getLength(sup1); + FIELD<double> * length2 = myMeshing3->getLength(sup2); + + vector< FIELD<double> *> myVect12; + myVect12.push_back(length1); + myVect12.push_back(length2); + + FIELD<double> * length12; + CPPUNIT_ASSERT_NO_THROW(length12 = myMeshing3->mergeFields(myVect12)); + delete length12; + + delete sup1; + delete sup2; + delete length1; + delete length2; + } + } + + ///////////////////////////////////////////////////////// + // TEST 4: test MESH constructed from file pointe.med // + //////////////////////////////////////////////////////// + MESH * myMesh4 = new MESH(); + myMesh4->setName(meshname); + MED_MESH_RDONLY_DRIVER myMeshDriver (filename, myMesh4); + myMeshDriver.setMeshName(meshname); + + //Mesh has no driver->segmentation violation + //CPPUNIT_ASSERT_THROW(myMesh4->read(), MEDEXCEPTION); + + //Add an existing MESH driver. + int myDriver4; + CPPUNIT_ASSERT_NO_THROW(myDriver4 = myMesh4->addDriver(myMeshDriver)); + + //read all objects in the file + CPPUNIT_ASSERT_NO_THROW(myMesh4->read(myDriver4)); + + if (myMesh4->getIsAGrid()) { + GRID* myGrid = dynamic_cast<GRID*>(myMesh4); + CPPUNIT_ASSERT(myGrid); + } + + //myDriver4->DRONLY->can't write + CPPUNIT_ASSERT_THROW(myMesh4->write(myDriver4), MEDEXCEPTION); + + // add new driver + int idMeshV21; + CPPUNIT_ASSERT_NO_THROW(idMeshV21 = myMesh4->addDriver(MED_DRIVER,filenameout21)); + + //Write all the content of the MESH using driver referenced by the integer handler index. + CPPUNIT_ASSERT_NO_THROW(myMesh4->write(idMeshV21)); + + // remove driver from mesh + CPPUNIT_ASSERT_NO_THROW(myMesh4->rmDriver(myDriver4)); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("ERROR: driver with index idMedV21 has not been removed"); +#endif + // ensure exception is raised on second attempt to remove driver + //CPPUNIT_ASSERT_THROW(myMesh4->rmDriver(myDriver4),MEDEXCEPTION); + + // Create a MESH object using a MESH driver of type MED_DRIVER associated with file fileName. + MESH* myMesh5; + CPPUNIT_ASSERT_NO_THROW(myMesh5 = new MESH(MED_DRIVER, filename, meshname)); + if(myMesh5->getIsAGrid()){ + GRID* myGrid = dynamic_cast<GRID*>(myMesh4); + CPPUNIT_ASSERT(myGrid); + } + + //ensure two meshes constracted from one file in two different ways are equal + CPPUNIT_ASSERT(myMesh5->deepCompare(*myMesh4)); + + int myDriver6; + MESH* myMesh6 = new MESH(); + try{ + myDriver6 = myMesh6->addDriver(MED_DRIVER, filename, meshname, MED_LECT); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try{ + myMesh6->read(myDriver6); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //ensure two meshes constracted from one file in two different ways are equal + CPPUNIT_ASSERT(myMesh6->deepCompare(*myMesh4)); + + //test FAMILY + int NumberOfFamilies4; + CPPUNIT_ASSERT_NO_THROW(NumberOfFamilies4 = myMesh6->getNumberOfFamilies(MED_CELL)); + CPPUNIT_ASSERT_MESSAGE("Current mesh hasn't Families", NumberOfFamilies4 != 0); + + vector<FAMILY*> families4; + CPPUNIT_ASSERT_NO_THROW(families4 = myMesh6->getFamilies(MED_CELL)); + CPPUNIT_ASSERT(families4.size() == NumberOfFamilies4); + for(int nb = 1; nb <= NumberOfFamilies4; nb++ ) + { + const FAMILY* family; + CPPUNIT_ASSERT_NO_THROW(family = myMesh6->getFamily(MED_CELL, nb)); + CPPUNIT_ASSERT_EQUAL(family->getName(), families4[nb-1]->getName()); + } + + //get support which reference all elements on the boundary of mesh. + SUPPORT*myBndSup; + CPPUNIT_ASSERT_THROW(myMesh6->getBoundaryElements(MED_CELL), MEDEXCEPTION); + //get only face in 3D. + CPPUNIT_ASSERT_NO_THROW(myBndSup = myMesh6->getBoundaryElements(MED_FACE)); + + //test buildSupportOnElementsFromElementList and buildSupportOnNodeFromElementList + const int * myConnectivityValue6; + CPPUNIT_ASSERT_NO_THROW(myConnectivityValue6 = myMesh6->getReverseConnectivity(MED_DESCENDING)); + const int * myConnectivityIndex6; + CPPUNIT_ASSERT_NO_THROW(myConnectivityIndex6 = myMesh6->getReverseConnectivityIndex(MED_DESCENDING)); + int numberOfElem6; + CPPUNIT_ASSERT_NO_THROW(numberOfElem6 = myMesh6->getNumberOfElementsWithPoly(MED_FACE,MED_ALL_ELEMENTS)); + list<int> myElementsList6; + + for (int i=0; i<numberOfElem6; i++) + if (myConnectivityValue6[myConnectivityIndex6[i]] == 0) { + myElementsList6.push_back(i+1); + } + + SUPPORT * mySupportOnNode; + SUPPORT * mySupportOnElem; + CPPUNIT_ASSERT_NO_THROW(mySupportOnElem = myMesh6->buildSupportOnElementsFromElementList(myElementsList6,MED_FACE)); + CPPUNIT_ASSERT(mySupportOnElem->deepCompare(*myBndSup)); + CPPUNIT_ASSERT_EQUAL(MED_FACE, mySupportOnElem->getEntity()); + + list<int>::const_iterator iteronelem = myElementsList6.begin(); + for (int i = 1; i <= 3; i++, iteronelem++) { + CPPUNIT_ASSERT_EQUAL(i, mySupportOnElem->getValIndFromGlobalNumber(*iteronelem)); + } + + CPPUNIT_ASSERT_NO_THROW(mySupportOnNode = myMesh6->buildSupportOnNodeFromElementList(myElementsList6,MED_FACE)); + CPPUNIT_ASSERT(mySupportOnNode->deepCompare( *(myMesh6->getBoundaryElements(MED_NODE)))); + + //sets mesh fields to initial values + try{ + myMesh6->init(); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //ensure two meshes constracted from one file in two different ways are equal + CPPUNIT_ASSERT(!myMesh6->deepCompare(*myMesh4)); + + //ensure mesh is empty + CPPUNIT_ASSERT(myMesh6->getSpaceDimension() == MED_INVALID); + CPPUNIT_ASSERT(myMesh6->getNumberOfNodes() == MED_INVALID); + CPPUNIT_ASSERT(myMesh6->getCoordinateptr() == NULL); + + delete myMesh4; + delete myMesh5; + delete myMesh6; + + MESH* myMesh7 = MEDMEMTest_createTestMesh(); + vector< vector<double> > myBndBox; + try{ + myBndBox = myMesh7->getBoundingBox(); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + cout<<"Bounding box for createTestMesh()"<<endl; + for(int i = 0; i < myBndBox.size(); i++) + { + for(int j = 0; j < myBndBox[i].size(); j++) + cout<<" "<< myBndBox[i][j]<<" "; + cout<<endl; + } + + double CoorPoint[3] = {0.0, 0.0, 1.0}; //n2 + int idxElem; + try{ + idxElem = myMesh7->getElementContainingPoint(CoorPoint); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(idxElem != -1); + + double CoorNoPoint[3] = {5.0, 0.0, -5.0}; //there is no such point + int idxNoElem; + try{ + idxNoElem = myMesh7->getElementContainingPoint(CoorNoPoint); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT(idxNoElem == -1); +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testMeshAndMeshing(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_ModulusArray.cxx b/src/MEDMEM/Test/MEDMEMTest_ModulusArray.cxx new file mode 100644 index 000000000..a912b9c05 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_ModulusArray.cxx @@ -0,0 +1,288 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include "MEDMEM_ModulusArray.hxx" +#include "MEDMEM_define.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (4), defined in MEDMEM_ModulusArray.hxx: + * class MEDMODULUSARRAY { + * (+) MEDMODULUSARRAY(int length, const int * array); + * (+) MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array); + * (+) ~MEDMODULUSARRAY(); + * (+) const int operator[](const int &i) const; + * (+) int compare(const MEDMODULUSARRAY &modulusArray) const; + * } + */ +void MEDMEMTest::testModulusArray() +{ + + int array[5]={0,1,2,1,4} ; + MEDMODULUSARRAY modulusArray(5,array); + + cout <<"ModulusArray"<<endl; + for(int i=-10;i<15;i++) + cout <<" - A["<<i<<"]="<<modulusArray[i]<<endl; + cout <<endl; + + // test compare + int ret ; + + int array2[5]={1,4,0,1,2} ; + MEDMODULUSARRAY modulusArray2(5,array2); + + try{ + ret=modulusArray2.compare(modulusArray); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + cout<<"!!!!!!ret"<<ret<<endl; + CPPUNIT_ASSERT_MESSAGE("Two identical arrays - KO", ret == 1); + + int array3[5]={1,2,1,0,4} ; + MEDMODULUSARRAY modulusArray3(5,array3) ; + try{ + ret=modulusArray3.compare(modulusArray); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Two arrays are in reverse order - KO",ret == -1); + + int array4[6]={1,2,1,0} ; + MEDMODULUSARRAY modulusArray4(4,array4) ; + try{ + ret=modulusArray4.compare(modulusArray); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Two arrays are have different size - KO",ret == 0); + + int array5[5]={1,2,1,0,1} ; + MEDMODULUSARRAY modulusArray5(5,array5) ; + + try{ + ret=modulusArray5.compare(modulusArray); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Two different arrays, same size - KO",ret == 0); + + // test small array : + + // 1 + int array6[1]={1} ; + MEDMODULUSARRAY modulusArray6(1,array6); + + cout <<"Test small array"<<endl; + for(int i=-10;i<15;i++) + cout <<" - A["<<i<<"]="<<modulusArray6[i]<<endl; + + + int array7[1]={1} ; + MEDMODULUSARRAY modulusArray7(1,array7); + try{ + ret=modulusArray6.compare(modulusArray7); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Two identical arrays - KO", ret == 1); + + int array8[1]={2} ; + MEDMODULUSARRAY modulusArray8(1,array8); + try{ + ret=modulusArray6.compare(modulusArray8); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Two different arrays - KO",ret == 0); + + // 2 + int array60[2]={1,2} ; + MEDMODULUSARRAY modulusArray60(2,array60); + + cout<<"ModulusArray 2 :"<<endl; + for(int i=-10;i<15;i++) + cout <<" - A["<<i<<"]="<<modulusArray60[i]<<endl; + cout <<endl; + + int array70[2]={1,2} ; + MEDMODULUSARRAY modulusArray70(2,array70); + + try{ + ret=modulusArray60.compare(modulusArray70); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO",ret == 1); + + int array80[2]={2,2} ; + MEDMODULUSARRAY modulusArray80(2,array80); + try{ + ret=modulusArray60.compare(modulusArray80); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Different arrays - KO",ret == 0); + + int array90[2]={2,1} ; + MEDMODULUSARRAY modulusArray90(2,array90); + + try{ + ret=modulusArray60.compare(modulusArray90); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Two arrays are in reverse order - KO",ret == -1); + + //test not vertex nodes + int array100[2]={1,2} ; + MEDMODULUSARRAY modulusArray100(2,2,array100); // == MEDMODULUSARRAY(2,array100); + + try{ + ret = modulusArray60.compare(modulusArray100); + } + catch (const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1); + + // check comparison of equal arrays, containing non-vertex nodes + + int array110[4] = {1,2,4,3}; + MEDMODULUSARRAY modulusArray110(2,4,array110); + + int array120[4] = {1,2,4,3}; + MEDMODULUSARRAY modulusArray120(2,4,array120); + + int array130[4] = {1,2,3,4}; + MEDMODULUSARRAY modulusArray130(2,4,array130); + + // same order of non-vertex nodes + CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray110)); + CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1); + + // different order of non-vertex nodes + CPPUNIT_ASSERT_NO_THROW(ret = modulusArray130.compare(modulusArray110)); + CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1); + + // check comparison of different arrays, containing non-vertex nodes + + // difference is in vertex nodes + int array140[4] = {1,5,4,3}; + MEDMODULUSARRAY modulusArray140 (2,4,array140); + + CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray140)); + CPPUNIT_ASSERT_MESSAGE("Different arrays - KO", ret == 0); + + // difference is in non-vertex nodes + int array150[4] = {1,2,4,5}; + MEDMODULUSARRAY modulusArray150 (2,4,array150); + + CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray150)); + CPPUNIT_ASSERT_MESSAGE("Different arrays - KO", ret == 0); + + // check that operator[] returns only vertex nodes + CPPUNIT_ASSERT_EQUAL(1, modulusArray120[0]); + CPPUNIT_ASSERT_EQUAL(2, modulusArray120[1]); + CPPUNIT_ASSERT_EQUAL(1, modulusArray120[2]); + CPPUNIT_ASSERT_EQUAL(2, modulusArray120[3]); + CPPUNIT_ASSERT_EQUAL(1, modulusArray120[4]); + CPPUNIT_ASSERT_EQUAL(2, modulusArray120[5]); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_PointerOf.cxx b/src/MEDMEM/Test/MEDMEMTest_PointerOf.cxx new file mode 100644 index 000000000..6e5f47e0f --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_PointerOf.cxx @@ -0,0 +1,151 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include "MEDMEM_PointerOf.hxx" +#include "MEDMEM_define.hxx" + +#include <cppunit/TestAssert.h> + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +/*! + * Check methods (12), defined in MEDMEM_PointerOf.hxx: + * template <typename T> class PointerOf { + * (+) PointerOf(); + * (+) ~PointerOf(); + * (+) PointerOf(const int &size); + * (+) PointerOf(const T *pointer); + * (+) PointerOf(const int &size, const T *pointer); + * (+) PointerOf(const PointerOf<T> & pointerOf); + * (NOT COMPILABLE!!!) PointerOf(const int &size, const PointerOf<T> & pointerOf); + * (+) operator T*(); + * (+) operator const T*() const; + * (+) void set(const int &size); + * (+) void set(const T *pointer); + * (+) void set(const int &size, const T *pointer); + * (+) void setShallowAndOwnership(const T *pointer); + * (+) PointerOf<T>& operator=(const PointerOf<T> &pointer); + * } + * + */ +void MEDMEMTest::testPointerOf() +{ + const int size=10; + PointerOf<int> P; + + try + { + P.set(0); + CPPUNIT_ASSERT((int *)P == NULL); + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + + try + { + P.set(-1 * size); + CPPUNIT_ASSERT((int *)P == NULL); + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + + try + { + P.set(size); + CPPUNIT_ASSERT((int *)P != NULL); + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + + for (int i=0; i < size; i++) + { + P[i]=i; + } + + PointerOf<int> P2(10); + + P2=P; + for (int i=0; i < size; i++) + { + SCRUTE(P2[i]); + } + + int * p=new int [size]; + for (int i=0; i < size; i++) + { + p[i]=i*10; + } + + P2.set(p); + PointerOf<int> P3(p); + + for (int i=0; i < size; i++) + { + CPPUNIT_ASSERT_EQUAL(P2[i],P3[i]); + } + + const PointerOf<int> P4(p); + for (int i=0; i < size; i++) + { + CPPUNIT_ASSERT_EQUAL(P4[i],p[i]); + } + + const PointerOf<int> P5(P4); + CPPUNIT_ASSERT((const int*)P5 != NULL); + + const PointerOf<int> P7(10, p); + + { +#ifdef ENABLE_COMPILATION_ERRORS + PointerOf<int> PP1 (10, p); + PointerOf<int> PP2 (10, PP1); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("Can not create: PointerOf(const int &size, const PointerOf<T> & pointerOf)"); +#endif + } + + CPPUNIT_ASSERT_THROW(P3.set(0, p),MEDEXCEPTION); + + P.setShallowAndOwnership( p ); + for (int i=0; i < size; i++) + { + CPPUNIT_ASSERT_EQUAL(P[i],p[i]); + } + + //delete [] p; not needed - P already owns p and will delete it when the scope is over +} diff --git a/src/MEDMEM/Test/MEDMEMTest_PolyhedronArray.cxx b/src/MEDMEM/Test/MEDMEMTest_PolyhedronArray.cxx new file mode 100644 index 000000000..5a1261ab5 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_PolyhedronArray.cxx @@ -0,0 +1,103 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include "MEDMEM_PolyhedronArray.hxx" +#include "MEDMEM_define.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (12), defined in MEDMEM_PolyhedronArray.hxx: + * class POLYHEDRONARRAY { + * (+) POLYHEDRONARRAY(); + * (+) POLYHEDRONARRAY(MED_EN::med_int numberofpolyhedron, + * MED_EN::med_int numberoffaces, MED_EN::med_int numberofnodes); + * (+) POLYHEDRONARRAY(const POLYHEDRONARRAY& m); + * + * (+) inline MED_EN::med_int getNumberOfPolyhedron() const; + * (+) inline MED_EN::med_int getNumberOfFaces() const; + * (+) inline MED_EN::med_int getNumberOfNodes() const; + * + * (+) inline const MED_EN::med_int* getPolyhedronIndex() const; + * (+) inline const MED_EN::med_int* getFacesIndex() const; + * (+) inline const MED_EN::med_int* getNodes() const; + * + * (+) inline void setPolyhedronIndex(const MED_EN::med_int* polyhedronindex); + * (+) inline void setFacesIndex(const MED_EN::med_int* facesindex); + * (+) inline void setNodes(const MED_EN::med_int* nodes); + * } + */ +void MEDMEMTest::testPolyhedronArray() +{ + const med_int nbPolyhedrons = 2; + const med_int nbFaces = 11; + const med_int nbNodes = 40; + + med_int polyhedronindex[nbPolyhedrons] = {1,7}; + med_int facesindex[nbFaces] = {1,5,9,13,17,21,25,28,31,34,37}; + med_int nodes[nbNodes] = {1,2,6,5,2,3,7,6,4,3,7,8,1,4,8,5,1,2,3,4,5,6,7,8,5,6,9,6,7,9,7,8,9,8,5,9,5,6,7,8}; + + // construction with parameters + POLYHEDRONARRAY myPArray (nbPolyhedrons, nbFaces, nbNodes); + + CPPUNIT_ASSERT_NO_THROW(myPArray.setPolyhedronIndex(polyhedronindex)); + CPPUNIT_ASSERT_NO_THROW(myPArray.setFacesIndex(facesindex)); + CPPUNIT_ASSERT_NO_THROW(myPArray.setNodes(nodes)); + + // copy constructor + POLYHEDRONARRAY myPArray2 (myPArray); + + const med_int* __polyhedronindex = myPArray2.getPolyhedronIndex(); + const med_int* __facesindex = myPArray2.getFacesIndex(); + const med_int* __nodes = myPArray2.getNodes(); + + CPPUNIT_ASSERT_EQUAL(myPArray2.getNumberOfPolyhedron(), nbPolyhedrons); + CPPUNIT_ASSERT_EQUAL(myPArray2.getNumberOfFaces(), nbFaces); + CPPUNIT_ASSERT_EQUAL(myPArray2.getNumberOfNodes(), nbNodes); + + for (int i = 0; i < nbPolyhedrons; i++) + CPPUNIT_ASSERT_EQUAL(__polyhedronindex[i], polyhedronindex[i]); + + for (int i = 0; i < nbFaces; i++) + CPPUNIT_ASSERT_EQUAL(__facesindex[i], facesindex[i]); + + for (int i = 0; i < nbNodes; i++) + CPPUNIT_ASSERT_EQUAL(__nodes[i], nodes[i]); + + // default constructor (has no sense, must be private) + POLYHEDRONARRAY myPArray3; + + CPPUNIT_ASSERT_EQUAL(0, int(myPArray3.getNumberOfPolyhedron())); + CPPUNIT_ASSERT_EQUAL(0, int(myPArray3.getNumberOfFaces())); + CPPUNIT_ASSERT_EQUAL(0, int(myPArray3.getNumberOfNodes())); + + CPPUNIT_ASSERT(myPArray3.getPolyhedronIndex() == NULL); + CPPUNIT_ASSERT(myPArray3.getFacesIndex() == NULL); + CPPUNIT_ASSERT(myPArray3.getNodes() == NULL); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_PorflowMeshDriver.cxx b/src/MEDMEM/Test/MEDMEMTest_PorflowMeshDriver.cxx new file mode 100644 index 000000000..1174e1ef7 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_PorflowMeshDriver.cxx @@ -0,0 +1,315 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_PorflowMeshDriver.hxx> +#include <MEDMEM_Mesh.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +/*! + * Check methods (18), defined in MEDMEM_PorflowMeshDriver.hxx: + * class PORFLOW_MESH_DRIVER : public GENDRIVER { + * (+) PORFLOW_MESH_DRIVER(); + * (+) PORFLOW_MESH_DRIVER(const string & fileName, MESH * ptrMesh, MED_EN::med_mode_acces accessMode); + * (+) PORFLOW_MESH_DRIVER(const PORFLOW_MESH_DRIVER & driver); + * (+) virtual ~PORFLOW_MESH_DRIVER(); + * (+) void open() throw (MEDEXCEPTION); + * (+) void close() throw (MEDEXCEPTION); + * (-) virtual void write(void) const = 0; + * (+) virtual void read (void) = 0; + * (+) void setMeshName(const string & meshName); + * (+) string getMeshName() const; + * } + * class PORFLOW_MESH_RDONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER { + * (+) PORFLOW_MESH_RDONLY_DRIVER(); + * (+) PORFLOW_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) PORFLOW_MESH_RDONLY_DRIVER(const PORFLOW_MESH_RDONLY_DRIVER & driver); + * (+) virtual ~PORFLOW_MESH_RDONLY_DRIVER(); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * class PORFLOW_MESH_WRONLY_DRIVER : public virtual PORFLOW_MESH_DRIVER { + * (+) PORFLOW_MESH_WRONLY_DRIVER(); + * (+) PORFLOW_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) PORFLOW_MESH_WRONLY_DRIVER(const PORFLOW_MESH_WRONLY_DRIVER & driver); + * (+) virtual ~PORFLOW_MESH_WRONLY_DRIVER(); + * (NOT IMPLEMENTED!!!) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + * class PORFLOW_MESH_RDWR_DRIVER : public PORFLOW_MESH_RDONLY_DRIVER, public PORFLOW_MESH_WRONLY_DRIVER { + * (+) PORFLOW_MESH_RDWR_DRIVER(); + * (+) PORFLOW_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) PORFLOW_MESH_RDWR_DRIVER(const PORFLOW_MESH_RDWR_DRIVER & driver); + * (+) ~PORFLOW_MESH_RDWR_DRIVER(); + * (CALLS PORFLOW_MESH_WRONLY_DRIVER::write()) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testPorflowMeshDriver() +{ + MESH *aMesh = new MESH(); + MESH *aMesh_1 = new MESH(); + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + + string filename_rd = data_dir + "/inp_xyz/Case1.inp"; + string filename_wr = tmp_dir + "/myWr_Case1.inp"; + string meshname = "Case1"; + string newmeshname = "new" + meshname; + string fileNotExistsName_rd = "notExists.inp"; + string fileNotExistsName_wr = "/path_not_exists/file_not_exists.inp"; + string filename_rdwr = tmp_dir + "/myRdWr_Case1.inp"; + string fcopy = "cp " + filename_rd + " " + filename_rdwr; + string fcopy1 = "cp " + data_dir + "/inp_xyz/Case1.xyz" + " " + tmp_dir + "/Case1.xyz"; + string fcopy2 = "cp " + data_dir + "/inp_xyz/Case1.cnc" + " " + tmp_dir + "/Case1.cnc"; + + //Copy files in the TMP dir for testing READ/WRITE case + system(fcopy.data()); + system(fcopy1.data()); + system(fcopy2.data()); + + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_rdwr); + aRemover.Register(tmp_dir + "/Case1.xyz"); + aRemover.Register(tmp_dir + "/Case1.cnc"); + + //-----------------------------Test READ ONLY part---------------------------------------// + { + { + //Creation a incorrect Porflow read only driver + PORFLOW_MESH_RDONLY_DRIVER *aInvalidPorflowRdDriver = + new PORFLOW_MESH_RDONLY_DRIVER(fileNotExistsName_rd, aMesh); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidPorflowRdDriver->open(), MEDEXCEPTION); + + delete aInvalidPorflowRdDriver; + } + + //Creation a correct Porflow read only driver (normal constructor) + PORFLOW_MESH_RDONLY_DRIVER *aPorflowRdDriver = new PORFLOW_MESH_RDONLY_DRIVER(filename_rd, aMesh); + + //Check driver + CPPUNIT_ASSERT(aPorflowRdDriver); + + //Trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aPorflowRdDriver->read(), MEDEXCEPTION); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aPorflowRdDriver->open()); + +#ifdef ENABLE_FORCED_FAILURES + //Trying open file secondary + CPPUNIT_ASSERT_THROW(aPorflowRdDriver->open(), MEDEXCEPTION); + //This case work, but it corrypt driver +#endif + + //Test read() method + CPPUNIT_ASSERT_NO_THROW(aPorflowRdDriver->read()); + + //Check Mesh + CPPUNIT_ASSERT(aMesh); + + //Trying fill not empty mesh + CPPUNIT_ASSERT_THROW(aPorflowRdDriver->read(), MEDEXCEPTION); + + //Test write() method for Porflow RDONLY Driver + CPPUNIT_ASSERT_THROW(aPorflowRdDriver->write(), MEDEXCEPTION); + + //Test setMeshName() and getMeshName() + CPPUNIT_ASSERT_NO_THROW(aPorflowRdDriver->setMeshName(meshname)); + CPPUNIT_ASSERT_EQUAL(meshname, aPorflowRdDriver->getMeshName()); + + //Test close() method + CPPUNIT_ASSERT_NO_THROW(aPorflowRdDriver->close()); + + //Default constructor + PORFLOW_MESH_RDONLY_DRIVER aPorflowRdDriverCpy_1; + // TO DO + + //Test copy constructor + PORFLOW_MESH_RDONLY_DRIVER aPorflowRdDriverCpy_2 (*aPorflowRdDriver); + + //Test (bool operator ==) defined GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aPorflowRdDriverCpy_2.GENDRIVER::operator==(*aPorflowRdDriver)); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream rostr1, rostr2; + rostr1 << *aPorflowRdDriver; + rostr2 << aPorflowRdDriverCpy_2; + CPPUNIT_ASSERT(rostr1.str() != ""); + CPPUNIT_ASSERT_EQUAL(rostr1.str() , rostr2.str()); + + delete aPorflowRdDriver; + } + + //---------------------------Test WRITE ONLY part-------------------------------------// + { + { + //Creation a incorrect Porflow write only driver + PORFLOW_MESH_WRONLY_DRIVER *aInvalidPorflowWrDriver = + new PORFLOW_MESH_WRONLY_DRIVER(fileNotExistsName_wr, aMesh); + + //Test case: trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidPorflowWrDriver->open(), MEDEXCEPTION); + + delete aInvalidPorflowWrDriver; + } + + //Creation a correct write only driver + PORFLOW_MESH_WRONLY_DRIVER *aPorflowWrDriver = new PORFLOW_MESH_WRONLY_DRIVER(filename_wr, aMesh); + + //Check driver + CPPUNIT_ASSERT(aPorflowWrDriver); + + //Test case: trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aPorflowWrDriver->write(), MEDEXCEPTION); + + //Test open() method +#ifndef ENABLE_FORCED_FAILURES + FILE *tmpFile = fopen(filename_wr.data(), "w"); + fclose(tmpFile); +#endif + CPPUNIT_ASSERT_NO_THROW(aPorflowWrDriver->open()); + + //Test case: trying open file secondary. + CPPUNIT_ASSERT_THROW(aPorflowWrDriver->open(), MEDEXCEPTION); + + //Test write() method +#ifdef ENABLE_FORCED_FAILURES + //Write method is not implemented + CPPUNIT_ASSERT_NO_THROW(aPorflowWrDriver->write()); +#endif + + //Test read() method for WRITE ONLY driver + CPPUNIT_ASSERT_THROW(aPorflowWrDriver->read(), MEDEXCEPTION); + + //Test setMeshName() and getMeshName() + CPPUNIT_ASSERT_NO_THROW(aPorflowWrDriver->setMeshName(newmeshname)); + CPPUNIT_ASSERT_EQUAL(newmeshname, aPorflowWrDriver->getMeshName()); + + CPPUNIT_ASSERT_NO_THROW(aPorflowWrDriver->close()); + + //Default constructor + PORFLOW_MESH_WRONLY_DRIVER aPorflowWrDriverCpy_1; + + //Test copy constructor + PORFLOW_MESH_WRONLY_DRIVER aPorflowWrDriverCpy_2 (*aPorflowWrDriver); + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aPorflowWrDriverCpy_2.GENDRIVER::operator==(*aPorflowWrDriver)); + + //Test (friend ostream & operator <<) defined in GENDRIVER class + ostringstream wostr1, wostr2; + wostr1 << *aPorflowWrDriver; + wostr2 << aPorflowWrDriverCpy_2; + CPPUNIT_ASSERT(wostr1.str() != ""); + CPPUNIT_ASSERT(wostr1.str() == wostr2.str()); + + delete aPorflowWrDriver; + } + + //------------------------Test READ / WRITE part------------------------------------// + { + { + //Creation a incorrect read/write driver + PORFLOW_MESH_RDWR_DRIVER *aInvalidPorflowRdWrDriver = + new PORFLOW_MESH_RDWR_DRIVER(fileNotExistsName_wr, aMesh_1); + + //Test case: trying open non existing file + CPPUNIT_ASSERT_THROW(aInvalidPorflowRdWrDriver->open(), MEDEXCEPTION); + + delete aInvalidPorflowRdWrDriver; + } + + //Creation a correct read/write driver + PORFLOW_MESH_RDWR_DRIVER *aPorflowRdWrDriver = new PORFLOW_MESH_RDWR_DRIVER(filename_rdwr, aMesh_1); + + //Check driver + CPPUNIT_ASSERT(aPorflowRdWrDriver); + + //Test case: trying write mesh to file, if file is not open + CPPUNIT_ASSERT_THROW(aPorflowRdWrDriver->write(), MEDEXCEPTION); + + //Test case: trying read mesh from file, if file is not open + CPPUNIT_ASSERT_THROW(aPorflowRdWrDriver->read(), MEDEXCEPTION); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aPorflowRdWrDriver->open()); + + //Test case: trying open file secondary. +#ifdef ENABLE_FORCED_FAILURES + // (BUG) This case work, but corrupt driver + CPPUNIT_ASSERT_THROW(aPorflowRdWrDriver->open(), MEDEXCEPTION); +#endif + + //Test read() method + CPPUNIT_ASSERT_NO_THROW(); + CPPUNIT_ASSERT_NO_THROW(aPorflowRdWrDriver->read()); + + //Test write() method + //aPorflowRdWrDriver->setMeshName(newmeshname); + //aMesh->setName(newmeshname); + //CPPUNIT_ASSERT_NO_THROW(aPorflowRdWrDriver->write()); + //Write method is not implemented +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("PORFLOW_MESH_RDWR_DRIVER::write() method not implemented"); +#endif + + //Check Mesh + CPPUNIT_ASSERT(aMesh); + + CPPUNIT_ASSERT_NO_THROW(aPorflowRdWrDriver->close()); + + //Default constructor + PORFLOW_MESH_RDWR_DRIVER aPorflowRdWrDriverCpy_1; + // TO DO + + //Test copy constructor + PORFLOW_MESH_RDWR_DRIVER aPorflowRdWrDriverCpy_2 (*aPorflowRdWrDriver); + + //Test (bool operator ==) defined in GENDRIVER class + CPPUNIT_ASSERT(aPorflowRdWrDriverCpy_2.GENDRIVER::operator==(*aPorflowRdWrDriver)); + + //Test (friend ostream & operator <<) defined in GENDRIVER class + ostringstream rwostr1, rwostr2; + rwostr1 << *aPorflowRdWrDriver; + rwostr2 << aPorflowRdWrDriverCpy_2; + CPPUNIT_ASSERT(rwostr1.str() != ""); + CPPUNIT_ASSERT(rwostr1.str() == rwostr2.str()); + + delete aPorflowRdWrDriver; + } + + //Delete all objects + delete aMesh; + delete aMesh_1; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_SkyLineArray.cxx b/src/MEDMEM/Test/MEDMEMTest_SkyLineArray.cxx new file mode 100644 index 000000000..d71050d99 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_SkyLineArray.cxx @@ -0,0 +1,200 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_define.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; +using namespace MEDMEM; + +/*! + * Check methods (17), defined in MEDMEM_SkyLineArray.hxx: + * class MEDSKYLINEARRAY { + * (+) MEDSKYLINEARRAY(); + * (+) MEDSKYLINEARRAY(const MEDSKYLINEARRAY &myArray); + * (+) MEDSKYLINEARRAY(const int count, const int length); + * (+) MEDSKYLINEARRAY(const int count, const int length, + * const int* index, const int* value, bool shallowCopy=false); + * (+) ~MEDSKYLINEARRAY(); + * (+) inline int getNumberOf() const; + * (+) inline int getLength() const; + * (+) inline const int* getIndex() const; + * (+) inline const int* getValue() const; + * (+) inline int getNumberOfI(int i) const throw (MEDEXCEPTION); + * (+) inline const int* getI(int i) const throw (MEDEXCEPTION); + * (+) inline int getIJ(int i, int j) const throw (MEDEXCEPTION); + * (+) inline int getIndexValue(int i) const throw (MEDEXCEPTION); + * (+) inline void setIndex(const int* index); + * (+) inline void setI(const int i, const int* values) throw (MEDEXCEPTION); + * (+) inline void setIJ(int i, int j, int value) throw (MEDEXCEPTION); + * (+) inline void setIndexValue(int i, int value) throw (MEDEXCEPTION); + * (+) friend ostream& operator<<(ostream &os, const MEDSKYLINEARRAY &sky); + * } + * + */ +void MEDMEMTest::testSkyLineArray() +{ + int NumberOfCell = 3 ; // 1 triangle,1 quadrangle,1 triangle + int Size = 10 ; // 10 nodes + + int * index = new int[NumberOfCell+1] ; + index[0]=1; + index[1]=4; + index[2]=8; + index[3]=11; + int * value = new int[Size] ; + value[0]=1; // first + value[1]=2; + value[2]=5; + value[3]=2; // second + value[4]=3; + value[5]=5; + value[6]=6; + value[7]=3; // thirst + value[8]=4; + value[9]=6; + // value[]=; // forth + + MEDSKYLINEARRAY * myArray = new MEDSKYLINEARRAY(NumberOfCell,Size,index,value) ; + const int * ArrayIndex ; + try + { + ArrayIndex = myArray->getIndex() ; + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + const int * ArrayValue ; + try + { + ArrayValue = myArray->getValue() ; + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + + try + { + CPPUNIT_ASSERT(myArray->getNumberOf()==NumberOfCell); + + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT(myArray->getLength()==Size); + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + for (int i=1; i< NumberOfCell+1 ; i++) + { + const int * cell; + CPPUNIT_ASSERT_NO_THROW(cell = myArray->getI(i)); + int numberof; + CPPUNIT_ASSERT_NO_THROW(numberof= myArray->getNumberOfI(i)); + CPPUNIT_ASSERT(numberof==index[i]-index[i-1]); + int verif; + for (int j=0;j<numberof;j++) + { + CPPUNIT_ASSERT_NO_THROW(verif=myArray->getIJ(i,j+1)); + CPPUNIT_ASSERT(verif == cell[j]); + } + } + + MEDSKYLINEARRAY * myArray2 = new MEDSKYLINEARRAY(*myArray) ; + delete myArray ; + + const int * index2 = myArray2->getIndex() ; + for (int i=1; i<=NumberOfCell ; i++) { + for (int j=index2[i-1];j<index2[i];j++) + CPPUNIT_ASSERT_NO_THROW(myArray2->getIndexValue(j)); + } + + delete myArray2 ; + + MEDSKYLINEARRAY myArray3(NumberOfCell,Size); + try + { + myArray3.setIndex(index); + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + CPPUNIT_ASSERT_THROW(myArray3.setI(0, 0),MEDEXCEPTION); + + for (int i=1; i<NumberOfCell+1 ; i++) { + CPPUNIT_ASSERT_NO_THROW(myArray3.setI(i, &value[index[i-1]-1])); + } + + for (int i=1; i<NumberOfCell+1 ; i++) { + int numberof; + CPPUNIT_ASSERT_NO_THROW(numberof = myArray3.getNumberOfI(i)); + for (int j=1;j<numberof+1;j++) + CPPUNIT_ASSERT_NO_THROW(myArray3.setIJ(i,j,myArray3.getIJ(i,j))) ; + } + + for (int i=1; i<=NumberOfCell ; i++) { + for (int j=index[i-1];j<index[i];j++) + CPPUNIT_ASSERT_NO_THROW(myArray3.setIndexValue(j,value[j-1])); + } + + delete[] index ; + delete[] value ; + MEDSKYLINEARRAY myEmptyArray; + cout<<myEmptyArray<<endl; +} + diff --git a/src/MEDMEM/Test/MEDMEMTest_Support.cxx b/src/MEDMEM/Test/MEDMEMTest_Support.cxx new file mode 100644 index 000000000..6e83298ae --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Support.cxx @@ -0,0 +1,686 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Support.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #52: MEDMEM_Support.hxx } MEDMEMTest_Support.cxx + +/*! + * Check methods (48), defined in MEDMEM_Support.hxx: + * class SUPPORT : public RCBASE { + * (+) SUPPORT(); + * (+) SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL); + * (+) SUPPORT(const SUPPORT & m); + * (+) virtual ~SUPPORT(); + * + * (+) friend ostream & operator<<(ostream &os,const SUPPORT &my); + * (+) SUPPORT& operator=(const SUPPORT &support); + * (+) bool operator == (const SUPPORT &support) const; + * (+) bool deepCompare(const SUPPORT &support) const; + * + * (+) void update(); + * + * (+) inline void setName(string Name); + * (+) inline void setDescription(string Description); + * (+) void setMesh(MESH *Mesh) const; + * (+) inline void setMeshName(const string & meshName); + * (+) inline void setAll(bool All); + * (+) inline void setEntity(MED_EN::medEntityMesh Entity); + * + * (+) inline void setNumberOfGeometricType(int NumberOfGeometricType); + * (+) inline void setGeometricType(const MED_EN::medGeometryElement *GeometricType); + * (+) inline void setNumberOfElements(const int *NumberOfElements); + * (+) inline void setTotalNumberOfElements(int TotalNumberOfElements); + * (+) inline void setNumber(MEDSKYLINEARRAY * Number); + * (+) inline void setNumber(const int * index, const int* value, bool shallowCopy=false); + * + * (+) inline string getName() const; + * (+) inline string getDescription() const; + * (+) virtual inline MESH * getMesh() const; + * (+) string getMeshName() const; + * (+) inline MED_EN::medEntityMesh getEntity() const; + * (+) inline bool isOnAllElements() const; + * + * (+) inline int getNumberOfTypes() const; + * (+) inline const MED_EN::medGeometryElement* getTypes() const; + * (+) inline int getNumberOfElements + * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + * (+) inline const int * getNumberOfElements() const throw (MEDEXCEPTION); + * (+) virtual inline MEDSKYLINEARRAY * getnumber() const throw (MEDEXCEPTION); + * (NO METHOD IN THIS BRANCH) virtual inline MEDSKYLINEARRAY * getnumberFromFile() const throw (MEDEXCEPTION); + * (+) virtual inline const int * getNumber + * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + * (NO METHOD IN THIS BRANCH) virtual inline const int * getNumberFromFile + * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + * (+) virtual inline const int * getNumberIndex() const throw (MEDEXCEPTION); + * (+) virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION); + * + * (+) void blending(SUPPORT * mySupport) throw (MEDEXCEPTION); + * + * (+) void setpartial(string Description, int NumberOfGeometricType, + * int TotalNumberOfEntity, MED_EN::medGeometryElement *GeometricType, + * int *NumberOfEntity, int *NumberValue); + * (+) void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION); + * (NO METHOD IN THIS BRANCH) void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION); + * + * (+) void setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION); + * (+) vector<string> getProfilNames() const throw (MEDEXCEPTION); + * + * (+) void getBoundaryElements() throw (MEDEXCEPTION); + * + * (+) void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew, + * int limitNbClassicPoly, const int *renumberingFromOldToNewPoly=0); + * (+) void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION); + * (+) bool belongsTo(const SUPPORT& other, bool deepCompare=false) const; + * + * (+) SUPPORT *getComplement() const; + * (+) SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION); + * + * (+) SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * + * (+) void fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION); + * (+) void fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION); + * + * (+) void clearDataOnNumbers(); + * + * (reference counter presently disconnected in C++) virtual void addReference() const; + * (reference counter presently disconnected in C++) virtual void removeReference() const; + * } + */ +void MEDMEMTest::testSupport() +{ + // cells connectivities + //const int NumberOfCellTypes = 3; + //MED_EN::medGeometryElement CellTypes[NumberOfCellTypes] = + // {MED_EN::MED_TETRA4, MED_EN::MED_PYRA5, MED_EN::MED_HEXA8}; + //const int NumberOfCells[NumberOfCellTypes] = {12, 2, 2}; + + // faces connectivities + //const int NumberOfFaceTypes = 2; + //MED_EN::medGeometryElement FaceTypes[NumberOfFaceTypes] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4}; + //const int NumberOfFaces[NumberOfFaceTypes] = {4, 4}; + + MESH * aMesh = MEDMEMTest_createTestMesh(); + MESH * aMeshOneMore = MEDMEMTest_createTestMesh(); + + //////////// + // TEST 1 // + //////////// + + SUPPORT aSupportOnFaces1 (aMesh, "Support On Faces 1", MED_EN::MED_FACE); + SUPPORT aSupportOnCells1 (aMesh, "Support On Cells 1"/*, MED_EN::MED_CELL*/); + + SUPPORT aSupportOnFaces2; + SUPPORT aSupportOnCells2; + + SUPPORT aSupportOnFaces3 (aMeshOneMore, "Support On Faces 3", MED_EN::MED_FACE); + + // entity + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces1.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells1.getEntity()); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnFaces2.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells2.getEntity()); + + aSupportOnFaces2.setEntity(MED_EN::MED_FACE); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces2.getEntity()); + + // isOnAllElements + CPPUNIT_ASSERT(aSupportOnFaces1.isOnAllElements()); + CPPUNIT_ASSERT(aSupportOnCells1.isOnAllElements()); + + CPPUNIT_ASSERT(!aSupportOnFaces2.isOnAllElements()); + CPPUNIT_ASSERT(!aSupportOnCells2.isOnAllElements()); + + // mesh and mesh name + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.setMeshName("Mesh 1"), MEDEXCEPTION); + + aSupportOnFaces2.setMeshName("Mesh 1"); + aSupportOnCells2.setMeshName("Mesh 1"); + CPPUNIT_ASSERT(aSupportOnFaces2.getMeshName() == "Mesh 1"); + CPPUNIT_ASSERT(aSupportOnCells2.getMeshName() == "Mesh 1"); + + aSupportOnFaces2.setMesh(aMesh); + CPPUNIT_ASSERT_THROW(aSupportOnFaces2.setMeshName("Mesh 1"), MEDEXCEPTION); + + aSupportOnCells1.setMesh(NULL); + aSupportOnCells1.setMeshName("Mesh 1"); + + CPPUNIT_ASSERT(aSupportOnFaces1.getMeshName() == "meshing"); + CPPUNIT_ASSERT(aSupportOnFaces2.getMeshName() == "meshing"); + CPPUNIT_ASSERT(aSupportOnCells1.getMeshName() == "Mesh 1"); + CPPUNIT_ASSERT(aSupportOnCells2.getMeshName() == "Mesh 1"); + + CPPUNIT_ASSERT(aSupportOnFaces1.getMesh() == aMesh); + CPPUNIT_ASSERT(aSupportOnFaces2.getMesh() == aMesh); + CPPUNIT_ASSERT(aSupportOnCells1.getMesh() == NULL); + CPPUNIT_ASSERT(aSupportOnCells2.getMesh() == NULL); + + // operator == + aSupportOnFaces2.setName("Support On Faces 2"); + aSupportOnCells2.setName("Support On Cells 2"); + + // because aSupportOnFaces1 is on all elements, but aSupportOnFaces2 not + CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2)); + + aSupportOnCells1.setAll(false); + CPPUNIT_ASSERT(!aSupportOnCells1.isOnAllElements()); + // this is only sets flag _isOnAllElts to false, but not clear elements and types + // information, so aSupportOnCells1 is not equal to aSupportOnCells2 at this moment + +#ifdef ENABLE_FAULTS + // (BUG) SUPPORT::operator= gives "Segmentation Fault" on supports with NULL meshes!!! + CPPUNIT_ASSERT(!(aSupportOnCells1 == aSupportOnCells2)); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("SUPPORT::operator= gives Segmentation Fault on supports with NULL meshes!!!"); +#endif + + aSupportOnFaces2.setAll(true); + CPPUNIT_ASSERT(aSupportOnFaces2.isOnAllElements()); + // flag _isOnAllElts now is set to true, but we need also to call update() + // to set elements and types information from mesh to this support + CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2)); + aSupportOnFaces2.update(); + CPPUNIT_ASSERT(aSupportOnFaces1 == aSupportOnFaces2); + + // deep compare + CPPUNIT_ASSERT(aSupportOnFaces1.deepCompare(aSupportOnFaces2)); + + CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces3)); // different mesh pointers + CPPUNIT_ASSERT(aSupportOnFaces1.deepCompare(aSupportOnFaces3)); // meshes are really equal + + // description + aSupportOnFaces1.setDescription("Support on all faces with mesh pointer"); + aSupportOnFaces2.setDescription("Support on all faces with mesh pointer"); + + aSupportOnCells1.setDescription("Support on a part of cells with mesh name"); + aSupportOnCells2.setDescription("Support on a part of cells with mesh name"); + + CPPUNIT_ASSERT(aSupportOnFaces1.getDescription() == "Support on all faces with mesh pointer"); + CPPUNIT_ASSERT(aSupportOnFaces2.getDescription() == "Support on all faces with mesh pointer"); + CPPUNIT_ASSERT(aSupportOnCells1.getDescription() == "Support on a part of cells with mesh name"); + CPPUNIT_ASSERT(aSupportOnCells2.getDescription() == "Support on a part of cells with mesh name"); + + // operator<< + ostringstream ostr1; + ostr1 << aSupportOnFaces1; + CPPUNIT_ASSERT(ostr1.str() != ""); + + ostringstream ostr2; + ostr2 << aSupportOnCells2; + CPPUNIT_ASSERT(ostr2.str() != ""); + + // set/get elements and types information + + // 1. aSupportOnCells1 is not on all elements, but now it contains information + // about all cells of aMesh, because it was created on mesh and with parameters. + CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells1.getTypes() != NULL); + + //const int * nbEltsSC_old = aSupportOnCells1.getNumberOfElements(); // {12, 2, 2} + + aSupportOnCells1.setNumberOfGeometricType(0); + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells1.getTypes() == NULL); + + MED_EN::medGeometryElement aSCTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_PENTA15}; + aSupportOnCells1.setNumberOfGeometricType(2); + aSupportOnCells1.setGeometricType(aSCTypes); + + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells1.getTypes() != NULL); + CPPUNIT_ASSERT(aSupportOnCells1.getNumberOfElements() == NULL); // reset by setNumberOfGeometricType + + int nbEltsSC[2] = {2, 1}; + aSupportOnCells1.setNumberOfElements(nbEltsSC); + + const int * nbEltsSCBack = aSupportOnCells1.getNumberOfElements(); + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1.getNumberOfElements(MED_EN::MED_PYRA5)); + CPPUNIT_ASSERT_EQUAL(2, nbEltsSCBack[0]); + CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells1.getNumberOfElements(MED_EN::MED_PENTA15)); + CPPUNIT_ASSERT_EQUAL(1, nbEltsSCBack[1]); + CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // old types + CPPUNIT_ASSERT_THROW(aSupportOnCells1.getNumberOfElements(MED_EN::MED_TETRA4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnCells1.getNumberOfElements(MED_EN::MED_HEXA8), MEDEXCEPTION); + + //_number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy); + int indexSC[3] = {1,3,4}; // length = nb.types + 1 + int valueSC[3] = {21,22,47}; // length = total nb. of elements + aSupportOnCells1.setNumber(indexSC, valueSC); + + // check number + MEDSKYLINEARRAY * aNumberSCBack = aSupportOnCells1.getnumber(); + + CPPUNIT_ASSERT_EQUAL(2, aNumberSCBack->getNumberOf()); + CPPUNIT_ASSERT_EQUAL(3, aNumberSCBack->getLength()); + const int * ind = aNumberSCBack->getIndex(); + const int * val = aNumberSCBack->getValue(); + CPPUNIT_ASSERT_EQUAL(1, ind[0]); + CPPUNIT_ASSERT_EQUAL(3, ind[1]); + CPPUNIT_ASSERT_EQUAL(4, ind[2]); + CPPUNIT_ASSERT_EQUAL(21, val[0]); + CPPUNIT_ASSERT_EQUAL(22, val[1]); + CPPUNIT_ASSERT_EQUAL(47, val[2]); + + // 2. aSupportOnCells2 is not on all elements, and now it contains + // no information about elements of a mesh + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells2.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells2.getTypes() == NULL); + + aSupportOnCells2.setNumberOfGeometricType(2); + aSupportOnCells2.setGeometricType(aSCTypes); + + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells2.getTypes() != NULL); + + aSupportOnCells2.setNumberOfElements(nbEltsSC); + + // we create MEDSKYLINEARRAY as pointer, because aSupportOnCells2 will + // become an owner of it, and we must not delete it. + MEDSKYLINEARRAY * aNumberSC = new MEDSKYLINEARRAY(2, 3, indexSC, valueSC); + aSupportOnCells2.setNumber(aNumberSC); + + // check number + const int * aNumberIndexSC = aSupportOnCells2.getNumberIndex(); + CPPUNIT_ASSERT_EQUAL(1, aNumberIndexSC[0]); + CPPUNIT_ASSERT_EQUAL(3, aNumberIndexSC[1]); + CPPUNIT_ASSERT_EQUAL(4, aNumberIndexSC[2]); + + const int * aNbPYRA5 = aSupportOnCells2.getNumber(MED_EN::MED_PYRA5); + const int * aNbPENTA15 = aSupportOnCells2.getNumber(MED_EN::MED_PENTA15); + CPPUNIT_ASSERT_THROW(aSupportOnCells2.getNumber(MED_EN::MED_TETRA4), MEDEXCEPTION); + + const int * aNbC = aSupportOnCells2.getNumber(MED_EN::MED_ALL_ELEMENTS); + + CPPUNIT_ASSERT_EQUAL(21, aNbPYRA5[0]); + CPPUNIT_ASSERT_EQUAL(22, aNbPYRA5[1]); + CPPUNIT_ASSERT_EQUAL(47, aNbPENTA15[0]); + + CPPUNIT_ASSERT_EQUAL(21, aNbC[0]); + CPPUNIT_ASSERT_EQUAL(22, aNbC[1]); + CPPUNIT_ASSERT_EQUAL(47, aNbC[2]); + + // getValIndFromGlobalNumber + CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells2.getValIndFromGlobalNumber(21)); + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2.getValIndFromGlobalNumber(22)); + CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells2.getValIndFromGlobalNumber(47)); + // not existing element + CPPUNIT_ASSERT_THROW(aSupportOnCells2.getValIndFromGlobalNumber(10), MEDEXCEPTION); + + // compare aSupportOnCells1 and aSupportOnCells2 + + // temporary set mesh (because of bug with operator==) + aSupportOnCells1.setMesh(aMesh); + aSupportOnCells2.setMesh(aMesh); + + CPPUNIT_ASSERT_EQUAL(aSupportOnCells1, aSupportOnCells2); + + // restore mesh name + aSupportOnCells1.setMesh(NULL); + aSupportOnCells2.setMesh(NULL); + aSupportOnCells1.setMeshName("Mesh 1"); + aSupportOnCells2.setMeshName("Mesh 1"); + + // 3. aSupportOnFacesN is on all elements, and it contains + // information about all faces of aMesh + CPPUNIT_ASSERT_EQUAL(2, aSupportOnFaces1.getNumberOfTypes()); + const MED_EN::medGeometryElement* aSF1Types = aSupportOnFaces1.getTypes(); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aSF1Types[0]); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aSF1Types[1]); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Comment to method SUPPORT::getTypes() says: + // "If isOnAllElements is false, returns an array of %medGeometryElement types used by the support." + // But in fact it returns types in any case (comment to SUPPORT::setAll() gives more information). + CPPUNIT_FAIL("Comment and implementation does not match for SUPPORT::getTypes()"); + // This concerns also method SUPPORT::update(), being called from constructor, + // which fills internal SUPPORT structures with information about mesh elements + // in case of isOnAllElements == true. + // Also comments and implementation does not match for SUPPORT::getNumberOfElements(). + // It seems that in case "isOnAllElements == true" calls like getNumberOfElements() + // must be redirected to mesh, but what if mesh is not set (mesh name used instead)?. +#endif + const int * nbEltsSF1 = aSupportOnFaces1.getNumberOfElements(); + CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[0]); + CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[1]); + CPPUNIT_ASSERT_EQUAL(8, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberOfElements(MED_EN::MED_TRIA6), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberOfElements(MED_EN::MED_QUAD8), MEDEXCEPTION); + + // check number + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberIndex(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_QUAD4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getnumber(), MEDEXCEPTION); + + // getValIndFromGlobalNumber + CPPUNIT_ASSERT_EQUAL(8, aMesh->getNumberOfElements(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS)); + for (int i = 1; i <= 8; i++) { + CPPUNIT_ASSERT_EQUAL(i, aSupportOnFaces1.getValIndFromGlobalNumber(i)); + } + +#ifdef ENABLE_FORCED_FAILURES + // Why methods setNumber do not throw exception in case "isOnAllElements == true", + // like methods getNumber do? + //CPPUNIT_ASSERT_THROW(aSupportOnFaces1.setNumber(indexSF1, valueSF1)); +#endif + +#ifdef ENABLE_FORCED_FAILURES + // It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements() + //CPPUNIT_FAIL("It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()"); +#endif + // setTotalNumberOfElements + aSupportOnFaces1.setTotalNumberOfElements(1000); + CPPUNIT_ASSERT_EQUAL(1000, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // clearDataOnNumbers + aSupportOnCells1.clearDataOnNumbers(); + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT_THROW(aSupportOnCells1.getnumber(), MEDEXCEPTION); + + //////////// + // TEST 2 // + //////////// + + list<int> nodes137; + nodes137.push_back(1); + nodes137.push_back(3); + nodes137.push_back(7); + + list<int> nodes248; + nodes248.push_back(2); + nodes248.push_back(4); + nodes248.push_back(8); + + list<int> nodes27; + nodes27.push_back(2); + nodes27.push_back(7); + + SUPPORT aNodes137 (aMesh, "Support On Nodes 1,3,7", MED_EN::MED_CELL); + SUPPORT aNodes248 (aMesh, "Support On Nodes 2,4,8", MED_EN::MED_CELL); + SUPPORT aNodes27 (aMesh, "Support On Nodes 2,7" , MED_EN::MED_CELL); + + aNodes137.fillFromNodeList(nodes137); + aNodes248.fillFromNodeList(nodes248); + aNodes27.fillFromNodeList(nodes27); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes137.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes248.getEntity()); + + list<int>::const_iterator iter137 = nodes137.begin(); + list<int>::const_iterator iter248 = nodes248.begin(); + for (int i = 1; i <= 3; i++, iter137++, iter248++) { + CPPUNIT_ASSERT_EQUAL(i, aNodes137.getValIndFromGlobalNumber(*iter137)); + CPPUNIT_ASSERT_EQUAL(i, aNodes248.getValIndFromGlobalNumber(*iter248)); + } + + //////////// + + list<int> faces123; + faces123.push_back(1); + faces123.push_back(2); + faces123.push_back(3); + + list<int> faces135; + faces135.push_back(1); + faces135.push_back(3); + faces135.push_back(5); + + SUPPORT aFaces123 (aMesh, "Support On Faces 1,2,3", MED_EN::MED_FACE); + SUPPORT aFaces135 (aMesh, "Support On Faces 1,3,5", MED_EN::MED_FACE); + + aFaces123.fillFromElementList(faces123); + aFaces135.fillFromElementList(faces135); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces123.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces135.getEntity()); + + list<int>::const_iterator iter123 = faces123.begin(); + list<int>::const_iterator iter135 = faces135.begin(); + for (int i = 1; i <= 3; i++, iter123++, iter135++) { + CPPUNIT_ASSERT_EQUAL(i, aFaces123.getValIndFromGlobalNumber(*iter123)); + CPPUNIT_ASSERT_EQUAL(i, aFaces135.getValIndFromGlobalNumber(*iter135)); + } + + // substract + SUPPORT * aFaces2 = aFaces123.substract(aFaces135); // => 2 + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces2->getEntity()); + CPPUNIT_ASSERT_EQUAL(1, aFaces2->getValIndFromGlobalNumber(2)); + CPPUNIT_ASSERT_EQUAL(1, aFaces2->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_THROW(aFaces123.substract(aNodes137), MEDEXCEPTION); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) SUPPORT::substract() does not work with supports on nodes, + // because it uses method MESH::buildSupportOnNodeFromElementList(), + // which does not work if entity = MED_NODE + //SUPPORT * aNodes137mesh = aMesh->buildSupportOnNodeFromElementList(nodes137, MED_EN::MED_NODE); + //delete aNodes137mesh; + SUPPORT * aNodes137sub = aNodes137.substract(aNodes248); // => 1,3,7 + CPPUNIT_ASSERT_EQUAL(*aNodes137sub, aNodes137); + delete aNodes137sub; +#endif + + // belongsTo + CPPUNIT_ASSERT(aFaces2->belongsTo(aFaces123)); + CPPUNIT_ASSERT(!aFaces2->belongsTo(aFaces135)); + + CPPUNIT_ASSERT(!aFaces2->belongsTo(aSupportOnFaces3)); + CPPUNIT_ASSERT(aFaces2->belongsTo(aSupportOnFaces3, /*deepCompare*/true)); + + delete aFaces2; + + // getComplement + SUPPORT * aFaces_135 = aFaces135.getComplement(); // => 2,4,6,7,8 + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces_135->getEntity()); + CPPUNIT_ASSERT_EQUAL(5, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Memory problem in SUPPORT::sub() + // Invalid read of size 4 + // at 0x34902492: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:852) + // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916) + // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514) + // Address 0x352DB91C is 0 bytes after a block of size 12 alloc'd + // at 0x3414C8E2: operator new[](unsigned) (vg_replace_malloc.c:138) + // by 0x3490243A: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:847) + // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916) + // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514) + CPPUNIT_FAIL("Memory problem in SUPPORT::sub(): Invalid read of size 4 from array <temp>"); +#endif + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) SUPPORT::getComplement() does not work with support on nodes, + // because it uses method MESH::buildSupportOnNodeFromElementList(), + // which does not work if entity = MED_NODE + SUPPORT * aNodes_137 = aNodes137.getComplement(); // => 2,4,5,6,8,9,10-19 + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes_137->getEntity()); + CPPUNIT_ASSERT_EQUAL(16, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); +#endif + + // intersecting + aFaces_135->intersecting(&aFaces123); // => 2 + CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getValIndFromGlobalNumber(2)); + + //aNodes_137->intersecting(&aNodes248); // => 2,4,8 + //CPPUNIT_ASSERT_EQUAL(3, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + //CPPUNIT_ASSERT_EQUAL(*aNodes_137, aNodes248); + aNodes137.intersecting(&aNodes248); // => {} + CPPUNIT_ASSERT_EQUAL(0, aNodes137.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // blending + aFaces_135->blending(&aFaces135); // => 1,2,3,5 + CPPUNIT_ASSERT_EQUAL(4, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + aNodes248.blending(&aNodes27); // => 2,4,7,8 + CPPUNIT_ASSERT_EQUAL(4, aNodes248.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // operator= + SUPPORT aCopy1; + aCopy1 = aNodes248; + CPPUNIT_ASSERT_EQUAL(aNodes248, aCopy1); + + // copy constructor + SUPPORT aCopy2 (aFaces135); + CPPUNIT_ASSERT_EQUAL(aFaces135, aCopy2); + + delete aFaces_135; +#ifdef ENABLE_FORCED_FAILURES + delete aNodes_137; +#endif + + // profil names + vector<string> aPrN2 (2); // nb. types + aPrN2[0] = "Profil 1"; + aPrN2[1] = "Profil 2"; + aFaces135.setProfilNames(aPrN2); + + // because on all elements + CPPUNIT_ASSERT_THROW(aSupportOnFaces3.setProfilNames(aPrN2), MEDEXCEPTION); + + // because length of vector is not equal to nb.types + vector<string> aPrN3 (3); + CPPUNIT_ASSERT_THROW(aFaces135.setProfilNames(aPrN3), MEDEXCEPTION); + + vector<string> aPrN2Back = aFaces135.getProfilNames(); + CPPUNIT_ASSERT_EQUAL(aPrN2[0], aPrN2Back[0]); + CPPUNIT_ASSERT_EQUAL(aPrN2[1], aPrN2Back[1]); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) profil names are not copied by copy constructor and operator=, + // not compared by operator==, not dumped in stream by operator<< + //CPPUNIT_FAIL("Not complete implementation for Profil Names"); +#endif + + //////////// + // TEST 3 // + //////////// + + SUPPORT aPartialCells (aMesh, "Support On Cells 2,3,4", MED_EN::MED_CELL); + SUPPORT aPartialNodes (aMesh, "Support On Nodes 2,3,4", MED_EN::MED_NODE); + + // setpartial + MED_EN::medGeometryElement gtCells[1] = {MED_EN::MED_TETRA4}; + int nbCells[1] = {3}; + int cells[3] = {2,3,4}; + aPartialCells.setpartial("with description", 1, 3, gtCells, nbCells, cells); + CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(2)); + CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(3)); + CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(4)); + + MED_EN::medGeometryElement gtNodes[1] = {MED_EN::MED_NONE}; + aPartialNodes.setNumberOfGeometricType(1); + aPartialNodes.setGeometricType(gtNodes); + int indexSN[2] = {1,4}; + int valueSN[3] = {2,3,4}; + MEDSKYLINEARRAY * aNumberSN = new MEDSKYLINEARRAY(1, 3, indexSN, valueSN); + aPartialNodes.setpartial(aNumberSN, /*shallowCopy*/false); + delete aNumberSN; + CPPUNIT_ASSERT_EQUAL(1, aPartialNodes.getValIndFromGlobalNumber(2)); + CPPUNIT_ASSERT_EQUAL(2, aPartialNodes.getValIndFromGlobalNumber(3)); + CPPUNIT_ASSERT_EQUAL(3, aPartialNodes.getValIndFromGlobalNumber(4)); + + // changeElementsNbs + + // {1,2,3,4,5,6,7,8,9,10} -> {10,9,8,7,6,5,4,3,2,1} + int renumberingFromOldToNew[10] = {10,9,8,7,6,5,4,3,2,1}; + + CPPUNIT_ASSERT_THROW(aPartialCells.changeElementsNbs + (MED_EN::MED_NODE, renumberingFromOldToNew, 10), MEDEXCEPTION); + + aPartialCells.changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNew, 10); + CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(9)); + CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(8)); + CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(7)); + + // {1,2,3,4,5,6,7} -> {1,3,5,7,2,4,6}, {8,9,10,11} -> {8,10,9,11} + int renumberingFromOldToNewP[7] = {1,3,5,7,2,4,6}; + int renumberingFromOldToNewPolyP[4] = {8,10,9,11}; + aPartialCells.changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNewP, + 7, renumberingFromOldToNewPolyP); + CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(10)); + CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(8)); + CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(6)); + + // this method does not suit for nodes renumbering! + // {1,2,3} -> {3,2,1}, {4,5,6,7} -> {5,6,7,4} + //int renumberingFromOldToNewN[3] = {3,2,1}; + //int renumberingFromOldToNewPolyN[4] = {5,6,7,4}; + //aPartialNodes.changeElementsNbs(MED_EN::MED_NODE, renumberingFromOldToNewN, + // 3, renumberingFromOldToNewPolyN); + + // getBoundaryElements +#ifdef ENABLE_FAULTS + // (BUG) Segmentation Fault during SUPPORT::getBoundaryElements() + // ??? May be mesh is not complete ??? + SUPPORT aBoundaryFaces (aMesh, "meshing boundary faces", MED_EN::MED_FACE); + aBoundaryFaces.getBoundaryElements(); + //cout << "aBoundaryFaces:" << endl; + //cout << aBoundaryFaces << endl; + + SUPPORT * aBoundaryNodes = aSupportOnFaces3.getBoundaryElements(MED_EN::MED_NODE); + //cout << "aSupportOnFaces3:" << endl; + //cout << aSupportOnFaces3 << endl; + //cout << "aBoundaryNodes:" << endl; + //cout << aBoundaryNodes << endl; + delete aBoundaryNodes; +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("Segmentation Fault during SUPPORT::getBoundaryElements()"); + // Invalid write of size 4 + // at 0x3439DFCE: void std::_Construct<int, int>(int*, int const&) (stl_construct.h:81) + // by 0x3476E4D1: std::vector<int, std::allocator<int> >::push_back(int const&) (stl_vector.h:560) + // by 0x34763DDB: MEDMEM::CONNECTIVITY::calculateReverseNodalConnectivity() (MEDMEM_Connectivity.cxx:1155) + // by 0x347655FF: MEDMEM::CONNECTIVITY::calculateDescendingConnectivity() (MEDMEM_Connectivity.cxx:1333) + // by 0x3476363E: MEDMEM::CONNECTIVITY::getReverseDescendingConnectivity() (MEDMEM_Connectivity.cxx:1090) + // by 0x34772AB6: MEDMEM::CONNECTIVITY::getReverseConnectivity(long, long) (MEDMEM_Connectivity.hxx:503) + // by 0x348F4F4B: MEDMEM::MESH::getReverseConnectivity(long, long) const (MEDMEM_Mesh.hxx:848) + // by 0x348FF559: MEDMEM::SUPPORT::getBoundaryElements() (MEDMEM_Support.cxx:483) + // by 0x3439C8E5: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:641) + // Address 0x61666A2F is not stack'd, malloc'd or (recently) free'd +#endif + + delete aMesh; + delete aMeshOneMore; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Support_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_Support_fault.cxx new file mode 100644 index 000000000..7b6dfbe59 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Support_fault.cxx @@ -0,0 +1,691 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_STRING.hxx" +#include "MEDMEM_Support.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +// #52: MEDMEM_Support.hxx } MEDMEMTest_Support.cxx + +/*! + * Check methods (48), defined in MEDMEM_Support.hxx: + * class SUPPORT : public RCBASE { + * (+) SUPPORT(); + * (+) SUPPORT(MESH* Mesh, string Name="", MED_EN::medEntityMesh Entity=MED_EN::MED_CELL); + * (+) SUPPORT(const SUPPORT & m); + * (+) virtual ~SUPPORT(); + * + * (+) friend ostream & operator<<(ostream &os,const SUPPORT &my); + * (+) SUPPORT& operator=(const SUPPORT &support); + * (+) bool operator == (const SUPPORT &support) const; + * (+) bool deepCompare(const SUPPORT &support) const; + * + * (+) void update(); + * + * (+) inline void setName(string Name); + * (+) inline void setDescription(string Description); + * (+) void setMesh(MESH *Mesh) const; + * (+) inline void setMeshName(const string & meshName); + * (+) inline void setAll(bool All); + * (+) inline void setEntity(MED_EN::medEntityMesh Entity); + * + * (+) inline void setNumberOfGeometricType(int NumberOfGeometricType); + * (+) inline void setGeometricType(const MED_EN::medGeometryElement *GeometricType); + * (+) inline void setNumberOfElements(const int *NumberOfElements); + * (+) inline void setTotalNumberOfElements(int TotalNumberOfElements); + * (+) inline void setNumber(MEDSKYLINEARRAY * Number); + * (+) inline void setNumber(const int * index, const int* value, bool shallowCopy=false); + * + * (+) inline string getName() const; + * (+) inline string getDescription() const; + * (+) virtual inline MESH * getMesh() const; + * (+) string getMeshName() const; + * (+) inline MED_EN::medEntityMesh getEntity() const; + * (+) inline bool isOnAllElements() const; + * + * (+) inline int getNumberOfTypes() const; + * (+) inline const MED_EN::medGeometryElement* getTypes() const; + * (+) inline int getNumberOfElements + * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + * (+) inline const int * getNumberOfElements() const throw (MEDEXCEPTION); + * (+) virtual inline MEDSKYLINEARRAY * getnumber() const throw (MEDEXCEPTION); + * (NO METHOD IN THIS BRANCH) virtual inline MEDSKYLINEARRAY * getnumberFromFile() const throw (MEDEXCEPTION); + * (+) virtual inline const int * getNumber + * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + * (NO METHOD IN THIS BRANCH) virtual inline const int * getNumberFromFile + * (MED_EN::medGeometryElement GeometricType) const throw (MEDEXCEPTION); + * (+) virtual inline const int * getNumberIndex() const throw (MEDEXCEPTION); + * (+) virtual int getValIndFromGlobalNumber(const int number) const throw (MEDEXCEPTION); + * + * (+) void blending(SUPPORT * mySupport) throw (MEDEXCEPTION); + * + * (+) void setpartial(string Description, int NumberOfGeometricType, + * int TotalNumberOfEntity, MED_EN::medGeometryElement *GeometricType, + * int *NumberOfEntity, int *NumberValue); + * (+) void setpartial(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION); + * (NO METHOD IN THIS BRANCH) void setpartial_fromfile(MEDSKYLINEARRAY * number, bool shallowCopy=false) throw (MEDEXCEPTION); + * + * (+) void setProfilNames(vector<string> profilNames) throw (MEDEXCEPTION); + * (+) vector<string> getProfilNames() const throw (MEDEXCEPTION); + * + * (+) void getBoundaryElements() throw (MEDEXCEPTION); + * + * (+) void changeElementsNbs(MED_EN::medEntityMesh entity, const int *renumberingFromOldToNew, + * int limitNbClassicPoly, const int *renumberingFromOldToNewPoly=0); + * (+) void intersecting(SUPPORT * mySupport) throw (MEDEXCEPTION); + * (+) bool belongsTo(const SUPPORT& other, bool deepCompare=false) const; + * + * (+) SUPPORT *getComplement() const; + * (+) SUPPORT *substract(const SUPPORT& other) const throw (MEDEXCEPTION); + * + * (+) SUPPORT *getBoundaryElements(MED_EN::medEntityMesh Entity) const throw (MEDEXCEPTION); + * + * (+) void fillFromNodeList(const list<int>& listOfNode) throw (MEDEXCEPTION); + * (+) void fillFromElementList(const list<int>& listOfElt) throw (MEDEXCEPTION); + * + * (+) void clearDataOnNumbers(); + * + * (reference counter presently disconnected in C++) virtual void addReference() const; + * (reference counter presently disconnected in C++) virtual void removeReference() const; + * } + */ +void MEDMEMTest_testSupport() +{ + // cells connectivities + //const int NumberOfCellTypes = 3; + //MED_EN::medGeometryElement CellTypes[NumberOfCellTypes] = + // {MED_EN::MED_TETRA4, MED_EN::MED_PYRA5, MED_EN::MED_HEXA8}; + //const int NumberOfCells[NumberOfCellTypes] = {12, 2, 2}; + + // faces connectivities + //const int NumberOfFaceTypes = 2; + //MED_EN::medGeometryElement FaceTypes[NumberOfFaceTypes] = {MED_EN::MED_TRIA3, MED_EN::MED_QUAD4}; + //const int NumberOfFaces[NumberOfFaceTypes] = {4, 4}; + + MESH * aMesh = MEDMEMTest_createTestMesh(); + MESH * aMeshOneMore = MEDMEMTest_createTestMesh(); + + //////////// + // TEST 1 // + //////////// + + SUPPORT aSupportOnFaces1 (aMesh, "Support On Faces 1", MED_EN::MED_FACE); + SUPPORT aSupportOnCells1 (aMesh, "Support On Cells 1"/*, MED_EN::MED_CELL*/); + + SUPPORT aSupportOnFaces2; + SUPPORT aSupportOnCells2; + + SUPPORT aSupportOnFaces3 (aMeshOneMore, "Support On Faces 3", MED_EN::MED_FACE); + + // entity + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces1.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells1.getEntity()); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnFaces2.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_CELL, aSupportOnCells2.getEntity()); + + aSupportOnFaces2.setEntity(MED_EN::MED_FACE); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aSupportOnFaces2.getEntity()); + + // isOnAllElements + CPPUNIT_ASSERT(aSupportOnFaces1.isOnAllElements()); + CPPUNIT_ASSERT(aSupportOnCells1.isOnAllElements()); + + CPPUNIT_ASSERT(!aSupportOnFaces2.isOnAllElements()); + CPPUNIT_ASSERT(!aSupportOnCells2.isOnAllElements()); + + // mesh and mesh name + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.setMeshName("Mesh 1"), MEDEXCEPTION); + + aSupportOnFaces2.setMeshName("Mesh 1"); + aSupportOnCells2.setMeshName("Mesh 1"); + CPPUNIT_ASSERT(aSupportOnFaces2.getMeshName() == "Mesh 1"); + CPPUNIT_ASSERT(aSupportOnCells2.getMeshName() == "Mesh 1"); + + aSupportOnFaces2.setMesh(aMesh); + CPPUNIT_ASSERT_THROW(aSupportOnFaces2.setMeshName("Mesh 1"), MEDEXCEPTION); + + aSupportOnCells1.setMesh(NULL); + aSupportOnCells1.setMeshName("Mesh 1"); + + CPPUNIT_ASSERT(aSupportOnFaces1.getMeshName() == "meshing"); + CPPUNIT_ASSERT(aSupportOnFaces2.getMeshName() == "meshing"); + CPPUNIT_ASSERT(aSupportOnCells1.getMeshName() == "Mesh 1"); + CPPUNIT_ASSERT(aSupportOnCells2.getMeshName() == "Mesh 1"); + + CPPUNIT_ASSERT(aSupportOnFaces1.getMesh() == aMesh); + CPPUNIT_ASSERT(aSupportOnFaces2.getMesh() == aMesh); + CPPUNIT_ASSERT(aSupportOnCells1.getMesh() == NULL); + CPPUNIT_ASSERT(aSupportOnCells2.getMesh() == NULL); + + // operator == + aSupportOnFaces2.setName("Support On Faces 2"); + aSupportOnCells2.setName("Support On Cells 2"); + + // because aSupportOnFaces1 is on all elements, but aSupportOnFaces2 not + CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2)); + + aSupportOnCells1.setAll(false); + CPPUNIT_ASSERT(!aSupportOnCells1.isOnAllElements()); + // this is only sets flag _isOnAllElts to false, but not clear elements and types + // information, so aSupportOnCells1 is not equal to aSupportOnCells2 at this moment + +#ifdef ENABLE_FAULTS + // (BUG) SUPPORT::operator= gives "Segmentation Fault" on supports with NULL meshes!!! + CPPUNIT_ASSERT(!(aSupportOnCells1 == aSupportOnCells2)); +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("SUPPORT::operator= gives Segmentation Fault on supports with NULL meshes!!!"); +#endif + + aSupportOnFaces2.setAll(true); + CPPUNIT_ASSERT(aSupportOnFaces2.isOnAllElements()); + // flag _isOnAllElts now is set to true, but we need also to call update() + // to set elements and types information from mesh to this support + CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces2)); + aSupportOnFaces2.update(); + CPPUNIT_ASSERT(aSupportOnFaces1 == aSupportOnFaces2); + + // deep compare + CPPUNIT_ASSERT(aSupportOnFaces1.deepCompare(aSupportOnFaces2)); + + CPPUNIT_ASSERT(!(aSupportOnFaces1 == aSupportOnFaces3)); // different mesh pointers + CPPUNIT_ASSERT(aSupportOnFaces1.deepCompare(aSupportOnFaces3)); // meshes are really equal + + // description + aSupportOnFaces1.setDescription("Support on all faces with mesh pointer"); + aSupportOnFaces2.setDescription("Support on all faces with mesh pointer"); + + aSupportOnCells1.setDescription("Support on a part of cells with mesh name"); + aSupportOnCells2.setDescription("Support on a part of cells with mesh name"); + + CPPUNIT_ASSERT(aSupportOnFaces1.getDescription() == "Support on all faces with mesh pointer"); + CPPUNIT_ASSERT(aSupportOnFaces2.getDescription() == "Support on all faces with mesh pointer"); + CPPUNIT_ASSERT(aSupportOnCells1.getDescription() == "Support on a part of cells with mesh name"); + CPPUNIT_ASSERT(aSupportOnCells2.getDescription() == "Support on a part of cells with mesh name"); + + // operator<< + ostringstream ostr1; + ostr1 << aSupportOnFaces1; + CPPUNIT_ASSERT(ostr1.str() != ""); + + ostringstream ostr2; + ostr2 << aSupportOnCells2; + CPPUNIT_ASSERT(ostr2.str() != ""); + + // set/get elements and types information + + // 1. aSupportOnCells1 is not on all elements, but now it contains information + // about all cells of aMesh, because it was created on mesh and with parameters. + CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells1.getTypes() != NULL); + + //const int * nbEltsSC_old = aSupportOnCells1.getNumberOfElements(); // {12, 2, 2} + + aSupportOnCells1.setNumberOfGeometricType(0); + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells1.getTypes() == NULL); + + MED_EN::medGeometryElement aSCTypes[2] = {MED_EN::MED_PYRA5, MED_EN::MED_PENTA15}; + aSupportOnCells1.setNumberOfGeometricType(2); + aSupportOnCells1.setGeometricType(aSCTypes); + + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells1.getTypes() != NULL); + CPPUNIT_ASSERT(aSupportOnCells1.getNumberOfElements() == NULL); // reset by setNumberOfGeometricType + + int nbEltsSC[2] = {2, 1}; + aSupportOnCells1.setNumberOfElements(nbEltsSC); + + const int * nbEltsSCBack = aSupportOnCells1.getNumberOfElements(); + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells1.getNumberOfElements(MED_EN::MED_PYRA5)); + CPPUNIT_ASSERT_EQUAL(2, nbEltsSCBack[0]); + CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells1.getNumberOfElements(MED_EN::MED_PENTA15)); + CPPUNIT_ASSERT_EQUAL(1, nbEltsSCBack[1]); + CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // old types + CPPUNIT_ASSERT_THROW(aSupportOnCells1.getNumberOfElements(MED_EN::MED_TETRA4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnCells1.getNumberOfElements(MED_EN::MED_HEXA8), MEDEXCEPTION); + + //_number= new MEDSKYLINEARRAY(_numberOfGeometricType,_totalNumberOfElements,index,value,shallowCopy); + int indexSC[3] = {1,3,4}; // length = nb.types + 1 + int valueSC[3] = {21,22,47}; // length = total nb. of elements + aSupportOnCells1.setNumber(indexSC, valueSC); + + // check number + MEDSKYLINEARRAY * aNumberSCBack = aSupportOnCells1.getnumber(); + + CPPUNIT_ASSERT_EQUAL(2, aNumberSCBack->getNumberOf()); + CPPUNIT_ASSERT_EQUAL(3, aNumberSCBack->getLength()); + const int * ind = aNumberSCBack->getIndex(); + const int * val = aNumberSCBack->getValue(); + CPPUNIT_ASSERT_EQUAL(1, ind[0]); + CPPUNIT_ASSERT_EQUAL(3, ind[1]); + CPPUNIT_ASSERT_EQUAL(4, ind[2]); + CPPUNIT_ASSERT_EQUAL(21, val[0]); + CPPUNIT_ASSERT_EQUAL(22, val[1]); + CPPUNIT_ASSERT_EQUAL(47, val[2]); + + // 2. aSupportOnCells2 is not on all elements, and now it contains + // no information about elements of a mesh + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells2.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells2.getTypes() == NULL); + + aSupportOnCells2.setNumberOfGeometricType(2); + aSupportOnCells2.setGeometricType(aSCTypes); + + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2.getNumberOfTypes()); + CPPUNIT_ASSERT(aSupportOnCells2.getTypes() != NULL); + + aSupportOnCells2.setNumberOfElements(nbEltsSC); + + // we create MEDSKYLINEARRAY as pointer, because aSupportOnCells2 will + // become an owner of it, and we must not delete it. + MEDSKYLINEARRAY * aNumberSC = new MEDSKYLINEARRAY(2, 3, indexSC, valueSC); + aSupportOnCells2.setNumber(aNumberSC); + + // check number + const int * aNumberIndexSC = aSupportOnCells2.getNumberIndex(); + CPPUNIT_ASSERT_EQUAL(1, aNumberIndexSC[0]); + CPPUNIT_ASSERT_EQUAL(3, aNumberIndexSC[1]); + CPPUNIT_ASSERT_EQUAL(4, aNumberIndexSC[2]); + + const int * aNbPYRA5 = aSupportOnCells2.getNumber(MED_EN::MED_PYRA5); + const int * aNbPENTA15 = aSupportOnCells2.getNumber(MED_EN::MED_PENTA15); + CPPUNIT_ASSERT_THROW(aSupportOnCells2.getNumber(MED_EN::MED_TETRA4), MEDEXCEPTION); + + const int * aNbC = aSupportOnCells2.getNumber(MED_EN::MED_ALL_ELEMENTS); + + CPPUNIT_ASSERT_EQUAL(21, aNbPYRA5[0]); + CPPUNIT_ASSERT_EQUAL(22, aNbPYRA5[1]); + CPPUNIT_ASSERT_EQUAL(47, aNbPENTA15[0]); + + CPPUNIT_ASSERT_EQUAL(21, aNbC[0]); + CPPUNIT_ASSERT_EQUAL(22, aNbC[1]); + CPPUNIT_ASSERT_EQUAL(47, aNbC[2]); + + // getValIndFromGlobalNumber + CPPUNIT_ASSERT_EQUAL(1, aSupportOnCells2.getValIndFromGlobalNumber(21)); + CPPUNIT_ASSERT_EQUAL(2, aSupportOnCells2.getValIndFromGlobalNumber(22)); + CPPUNIT_ASSERT_EQUAL(3, aSupportOnCells2.getValIndFromGlobalNumber(47)); + // not existing element + CPPUNIT_ASSERT_THROW(aSupportOnCells2.getValIndFromGlobalNumber(10), MEDEXCEPTION); + + // compare aSupportOnCells1 and aSupportOnCells2 + + // temporary set mesh (because of bug with operator==) + aSupportOnCells1.setMesh(aMesh); + aSupportOnCells2.setMesh(aMesh); + + CPPUNIT_ASSERT_EQUAL(aSupportOnCells1, aSupportOnCells2); + + // restore mesh name + aSupportOnCells1.setMesh(NULL); + aSupportOnCells2.setMesh(NULL); + aSupportOnCells1.setMeshName("Mesh 1"); + aSupportOnCells2.setMeshName("Mesh 1"); + + // 3. aSupportOnFacesN is on all elements, and it contains + // information about all faces of aMesh + CPPUNIT_ASSERT_EQUAL(2, aSupportOnFaces1.getNumberOfTypes()); + const MED_EN::medGeometryElement* aSF1Types = aSupportOnFaces1.getTypes(); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_TRIA3, aSF1Types[0]); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_QUAD4, aSF1Types[1]); +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Comment to method SUPPORT::getTypes() says: + // "If isOnAllElements is false, returns an array of %medGeometryElement types used by the support." + // But in fact it returns types in any case (comment to SUPPORT::setAll() gives more information). + CPPUNIT_FAIL("Comment and implementation does not match for SUPPORT::getTypes()"); + // This concerns also method SUPPORT::update(), being called from constructor, + // which fills internal SUPPORT structures with information about mesh elements + // in case of isOnAllElements == true. + // Also comments and implementation does not match for SUPPORT::getNumberOfElements(). + // It seems that in case "isOnAllElements == true" calls like getNumberOfElements() + // must be redirected to mesh, but what if mesh is not set (mesh name used instead)?. +#endif + const int * nbEltsSF1 = aSupportOnFaces1.getNumberOfElements(); + CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_TRIA3)); + CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[0]); + CPPUNIT_ASSERT_EQUAL(4, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_QUAD4)); + CPPUNIT_ASSERT_EQUAL(4, nbEltsSF1[1]); + CPPUNIT_ASSERT_EQUAL(8, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberOfElements(MED_EN::MED_TRIA6), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberOfElements(MED_EN::MED_QUAD8), MEDEXCEPTION); + + // check number + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumberIndex(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_TRIA3), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_QUAD4), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getNumber(MED_EN::MED_ALL_ELEMENTS), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aSupportOnFaces1.getnumber(), MEDEXCEPTION); + + // getValIndFromGlobalNumber + CPPUNIT_ASSERT_EQUAL(8, aMesh->getNumberOfElements(MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS)); + for (int i = 1; i <= 8; i++) { + CPPUNIT_ASSERT_EQUAL(i, aSupportOnFaces1.getValIndFromGlobalNumber(i)); + } + +#ifdef ENABLE_FORCED_FAILURES + // Why methods setNumber do not throw exception in case "isOnAllElements == true", + // like methods getNumber do? + //CPPUNIT_ASSERT_THROW(aSupportOnFaces1.setNumber(indexSF1, valueSF1)); +#endif + +#ifdef ENABLE_FORCED_FAILURES + // It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements() + //CPPUNIT_FAIL("It seems to be dangerous and useless to have method SUPPORT::setTotalNumberOfElements()"); +#endif + // setTotalNumberOfElements + aSupportOnFaces1.setTotalNumberOfElements(1000); + CPPUNIT_ASSERT_EQUAL(1000, aSupportOnFaces1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // clearDataOnNumbers + aSupportOnCells1.clearDataOnNumbers(); + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(0, aSupportOnCells1.getNumberOfTypes()); + CPPUNIT_ASSERT_THROW(aSupportOnCells1.getnumber(), MEDEXCEPTION); + + //////////// + // TEST 2 // + //////////// + + list<int> nodes137; + nodes137.push_back(1); + nodes137.push_back(3); + nodes137.push_back(7); + + list<int> nodes248; + nodes248.push_back(2); + nodes248.push_back(4); + nodes248.push_back(8); + + list<int> nodes27; + nodes27.push_back(2); + nodes27.push_back(7); + + SUPPORT aNodes137 (aMesh, "Support On Nodes 1,3,7", MED_EN::MED_CELL); + SUPPORT aNodes248 (aMesh, "Support On Nodes 2,4,8", MED_EN::MED_CELL); + SUPPORT aNodes27 (aMesh, "Support On Nodes 2,7" , MED_EN::MED_CELL); + + aNodes137.fillFromNodeList(nodes137); + aNodes248.fillFromNodeList(nodes248); + aNodes27.fillFromNodeList(nodes27); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes137.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes248.getEntity()); + + list<int>::const_iterator iter137 = nodes137.begin(); + list<int>::const_iterator iter248 = nodes248.begin(); + for (int i = 1; i <= 3; i++, iter137++, iter248++) { + CPPUNIT_ASSERT_EQUAL(i, aNodes137.getValIndFromGlobalNumber(*iter137)); + CPPUNIT_ASSERT_EQUAL(i, aNodes248.getValIndFromGlobalNumber(*iter248)); + } + + //////////// + + list<int> faces123; + faces123.push_back(1); + faces123.push_back(2); + faces123.push_back(3); + + list<int> faces135; + faces135.push_back(1); + faces135.push_back(3); + faces135.push_back(5); + + SUPPORT aFaces123 (aMesh, "Support On Faces 1,2,3", MED_EN::MED_FACE); + SUPPORT aFaces135 (aMesh, "Support On Faces 1,3,5", MED_EN::MED_FACE); + + aFaces123.fillFromElementList(faces123); + aFaces135.fillFromElementList(faces135); + + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces123.getEntity()); + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces135.getEntity()); + + list<int>::const_iterator iter123 = faces123.begin(); + list<int>::const_iterator iter135 = faces135.begin(); + for (int i = 1; i <= 3; i++, iter123++, iter135++) { + CPPUNIT_ASSERT_EQUAL(i, aFaces123.getValIndFromGlobalNumber(*iter123)); + CPPUNIT_ASSERT_EQUAL(i, aFaces135.getValIndFromGlobalNumber(*iter135)); + } + + // substract + SUPPORT * aFaces2 = aFaces123.substract(aFaces135); // => 2 + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces2->getEntity()); + CPPUNIT_ASSERT_EQUAL(1, aFaces2->getValIndFromGlobalNumber(2)); + CPPUNIT_ASSERT_EQUAL(1, aFaces2->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + CPPUNIT_ASSERT_THROW(aFaces123.substract(aNodes137), MEDEXCEPTION); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) SUPPORT::substract() does not work with supports on nodes, + // because it uses method MESH::buildSupportOnNodeFromElementList(), + // which does not work if entity = MED_NODE + //SUPPORT * aNodes137mesh = aMesh->buildSupportOnNodeFromElementList(nodes137, MED_EN::MED_NODE); + //delete aNodes137mesh; + SUPPORT * aNodes137sub = aNodes137.substract(aNodes248); // => 1,3,7 + CPPUNIT_ASSERT_EQUAL(*aNodes137sub, aNodes137); + delete aNodes137sub; +#endif + + // belongsTo + CPPUNIT_ASSERT(aFaces2->belongsTo(aFaces123)); + CPPUNIT_ASSERT(!aFaces2->belongsTo(aFaces135)); + + CPPUNIT_ASSERT(!aFaces2->belongsTo(aSupportOnFaces3)); + CPPUNIT_ASSERT(aFaces2->belongsTo(aSupportOnFaces3, /*deepCompare*/true)); + + delete aFaces2; + + // getComplement + SUPPORT * aFaces_135 = aFaces135.getComplement(); // => 2,4,6,7,8 + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_FACE, aFaces_135->getEntity()); + CPPUNIT_ASSERT_EQUAL(5, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Memory problem in SUPPORT::sub() + // Invalid read of size 4 + // at 0x34902492: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:852) + // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916) + // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514) + // Address 0x352DB91C is 0 bytes after a block of size 12 alloc'd + // at 0x3414C8E2: operator new[](unsigned) (vg_replace_malloc.c:138) + // by 0x3490243A: MEDMEM::SUPPORT::sub(int, int, int const*, int) (MEDMEM_Support.cxx:847) + // by 0x3490296B: MEDMEM::SUPPORT::getComplement() const (MEDMEM_Support.cxx:916) + // by 0x34398F1E: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:514) + CPPUNIT_FAIL("Memory problem in SUPPORT::sub(): Invalid read of size 4 from array <temp>"); +#endif + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) SUPPORT::getComplement() does not work with support on nodes, + // because it uses method MESH::buildSupportOnNodeFromElementList(), + // which does not work if entity = MED_NODE + SUPPORT * aNodes_137 = aNodes137.getComplement(); // => 2,4,5,6,8,9,10-19 + CPPUNIT_ASSERT_EQUAL(MED_EN::MED_NODE, aNodes_137->getEntity()); + CPPUNIT_ASSERT_EQUAL(16, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); +#endif + + // intersecting + aFaces_135->intersecting(&aFaces123); // => 2 + CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(1, aFaces_135->getValIndFromGlobalNumber(2)); + + //aNodes_137->intersecting(&aNodes248); // => 2,4,8 + //CPPUNIT_ASSERT_EQUAL(3, aNodes_137->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + //CPPUNIT_ASSERT_EQUAL(*aNodes_137, aNodes248); + aNodes137.intersecting(&aNodes248); // => {} + CPPUNIT_ASSERT_EQUAL(0, aNodes137.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // blending + aFaces_135->blending(&aFaces135); // => 1,2,3,5 + CPPUNIT_ASSERT_EQUAL(4, aFaces_135->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + aNodes248.blending(&aNodes27); // => 2,4,7,8 + CPPUNIT_ASSERT_EQUAL(4, aNodes248.getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)); + + // operator= + SUPPORT aCopy1; + aCopy1 = aNodes248; + CPPUNIT_ASSERT_EQUAL(aNodes248, aCopy1); + + // copy constructor + SUPPORT aCopy2 (aFaces135); + CPPUNIT_ASSERT_EQUAL(aFaces135, aCopy2); + + delete aFaces_135; +#ifdef ENABLE_FORCED_FAILURES + delete aNodes_137; +#endif + + // profil names + vector<string> aPrN2 (2); // nb. types + aPrN2[0] = "Profil 1"; + aPrN2[1] = "Profil 2"; + aFaces135.setProfilNames(aPrN2); + + // because on all elements + CPPUNIT_ASSERT_THROW(aSupportOnFaces3.setProfilNames(aPrN2), MEDEXCEPTION); + + // because length of vector is not equal to nb.types + vector<string> aPrN3 (3); + CPPUNIT_ASSERT_THROW(aFaces135.setProfilNames(aPrN3), MEDEXCEPTION); + + vector<string> aPrN2Back = aFaces135.getProfilNames(); + CPPUNIT_ASSERT_EQUAL(aPrN2[0], aPrN2Back[0]); + CPPUNIT_ASSERT_EQUAL(aPrN2[1], aPrN2Back[1]); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) profil names are not copied by copy constructor and operator=, + // not compared by operator==, not dumped in stream by operator<< + //CPPUNIT_FAIL("Not complete implementation for Profil Names"); +#endif + + //////////// + // TEST 3 // + //////////// + + SUPPORT aPartialCells (aMesh, "Support On Cells 2,3,4", MED_EN::MED_CELL); + SUPPORT aPartialNodes (aMesh, "Support On Nodes 2,3,4", MED_EN::MED_NODE); + + // setpartial + MED_EN::medGeometryElement gtCells[1] = {MED_EN::MED_TETRA4}; + int nbCells[1] = {3}; + int cells[3] = {2,3,4}; + aPartialCells.setpartial("with description", 1, 3, gtCells, nbCells, cells); + CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(2)); + CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(3)); + CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(4)); + + MED_EN::medGeometryElement gtNodes[1] = {MED_EN::MED_NONE}; + aPartialNodes.setNumberOfGeometricType(1); + aPartialNodes.setGeometricType(gtNodes); + int indexSN[2] = {1,4}; + int valueSN[3] = {2,3,4}; + MEDSKYLINEARRAY * aNumberSN = new MEDSKYLINEARRAY(1, 3, indexSN, valueSN); + aPartialNodes.setpartial(aNumberSN, /*shallowCopy*/false); + delete aNumberSN; + CPPUNIT_ASSERT_EQUAL(1, aPartialNodes.getValIndFromGlobalNumber(2)); + CPPUNIT_ASSERT_EQUAL(2, aPartialNodes.getValIndFromGlobalNumber(3)); + CPPUNIT_ASSERT_EQUAL(3, aPartialNodes.getValIndFromGlobalNumber(4)); + + // changeElementsNbs + + // {1,2,3,4,5,6,7,8,9,10} -> {10,9,8,7,6,5,4,3,2,1} + int renumberingFromOldToNew[10] = {10,9,8,7,6,5,4,3,2,1}; + + CPPUNIT_ASSERT_THROW(aPartialCells.changeElementsNbs + (MED_EN::MED_NODE, renumberingFromOldToNew, 10), MEDEXCEPTION); + + aPartialCells.changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNew, 10); + CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(9)); + CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(8)); + CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(7)); + + // {1,2,3,4,5,6,7} -> {1,3,5,7,2,4,6}, {8,9,10,11} -> {8,10,9,11} + int renumberingFromOldToNewP[7] = {1,3,5,7,2,4,6}; + int renumberingFromOldToNewPolyP[4] = {8,10,9,11}; + aPartialCells.changeElementsNbs(MED_EN::MED_CELL, renumberingFromOldToNewP, + 7, renumberingFromOldToNewPolyP); + CPPUNIT_ASSERT_EQUAL(3, aPartialCells.getValIndFromGlobalNumber(10)); + CPPUNIT_ASSERT_EQUAL(2, aPartialCells.getValIndFromGlobalNumber(8)); + CPPUNIT_ASSERT_EQUAL(1, aPartialCells.getValIndFromGlobalNumber(6)); + + // this method does not suit for nodes renumbering! + // {1,2,3} -> {3,2,1}, {4,5,6,7} -> {5,6,7,4} + //int renumberingFromOldToNewN[3] = {3,2,1}; + //int renumberingFromOldToNewPolyN[4] = {5,6,7,4}; + //aPartialNodes.changeElementsNbs(MED_EN::MED_NODE, renumberingFromOldToNewN, + // 3, renumberingFromOldToNewPolyN); + + // getBoundaryElements +#ifdef ENABLE_FAULTS + // (BUG) Segmentation Fault during SUPPORT::getBoundaryElements() + // ??? May be mesh is not complete ??? + SUPPORT aBoundaryFaces (aMesh, "meshing boundary faces", MED_EN::MED_FACE); + aBoundaryFaces.getBoundaryElements(); + //cout << "aBoundaryFaces:" << endl; + //cout << aBoundaryFaces << endl; + + SUPPORT * aBoundaryNodes = aSupportOnFaces3.getBoundaryElements(MED_EN::MED_NODE); + //cout << "aSupportOnFaces3:" << endl; + //cout << aSupportOnFaces3 << endl; + //cout << "aBoundaryNodes:" << endl; + //cout << aBoundaryNodes << endl; + delete aBoundaryNodes; +#endif +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_FAIL("Segmentation Fault during SUPPORT::getBoundaryElements()"); + // Invalid write of size 4 + // at 0x3439DFCE: void std::_Construct<int, int>(int*, int const&) (stl_construct.h:81) + // by 0x3476E4D1: std::vector<int, std::allocator<int> >::push_back(int const&) (stl_vector.h:560) + // by 0x34763DDB: MEDMEM::CONNECTIVITY::calculateReverseNodalConnectivity() (MEDMEM_Connectivity.cxx:1155) + // by 0x347655FF: MEDMEM::CONNECTIVITY::calculateDescendingConnectivity() (MEDMEM_Connectivity.cxx:1333) + // by 0x3476363E: MEDMEM::CONNECTIVITY::getReverseDescendingConnectivity() (MEDMEM_Connectivity.cxx:1090) + // by 0x34772AB6: MEDMEM::CONNECTIVITY::getReverseConnectivity(long, long) (MEDMEM_Connectivity.hxx:503) + // by 0x348F4F4B: MEDMEM::MESH::getReverseConnectivity(long, long) const (MEDMEM_Mesh.hxx:848) + // by 0x348FF559: MEDMEM::SUPPORT::getBoundaryElements() (MEDMEM_Support.cxx:483) + // by 0x3439C8E5: MEDMEMTest::testSupport() (MEDMEMTest_Support.cxx:641) + // Address 0x61666A2F is not stack'd, malloc'd or (recently) free'd +#endif + + delete aMesh; + delete aMeshOneMore; +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testSupport(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_TopLevel.cxx b/src/MEDMEM/Test/MEDMEMTest_TopLevel.cxx new file mode 100644 index 000000000..8f81511a4 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_TopLevel.cxx @@ -0,0 +1,165 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_TopLevel.hxx> +#include <MEDMEM_MedFieldDriver22.hxx> +#include <MEDMEM_Field.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (6), defined in MEDMEM_TopLevel.hxx: + * (+) MED *readMedInFile(const std::string& fileName) throw(MEDEXCEPTION); + * (+) MESH *readMeshInFile(const std::string& fileName, const std::string& meshName); + * (+) template<class T> FIELD<T> *readFieldInFile + * (const std::string& fileName, const std::string& fieldName); + * (+) void writeMedToFile(const MED *medObj, const std::string& fileName); + * (+) void writeMeshToFile(const MESH *meshObj, const std::string& fileName); + * (-) template<class T> void writeFieldToFile(const FIELD<T> *fieldObj, const std::string& fileName); + */ +void MEDMEMTest::testTopLevel() +{ + MED * aMed = NULL; + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string filename22_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filenameMesh_wr = tmp_dir + "/myMesh.med"; + string filenameMed_wr = tmp_dir + "/myMed.med"; + string filenameField_wr = tmp_dir + "/myField.med"; + string fileNotExist_rd = "/notExist.med"; + string fileNotExist_wr = "/path_not_exist/file_not_exist.med"; + string meshname = "maa1"; + string meshname_not_exist = "anymesh"; + string fieldname_not_exist = "anyfield"; + string fieldname = "fieldnodedouble"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filenameMesh_wr); + aRemover.Register(filenameMed_wr); + aRemover.Register(filenameField_wr); + + /////////////////// + //Test Read Part // + /////////////////// + { + //Trying read from not existing file +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_THROW(readMedInFile(fileNotExist_rd), MEDEXCEPTION); + // (BUG) No exception in this case +#endif + CPPUNIT_ASSERT_THROW(readMeshInFile(fileNotExist_rd, meshname), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(readFieldInFile<double>(fileNotExist_rd, fieldname), MEDEXCEPTION); + + //Trying read not existing mesh from file + CPPUNIT_ASSERT_THROW(readMeshInFile(filename_rd, meshname_not_exist), MEDEXCEPTION); + + //Trying read not existing field from file + CPPUNIT_ASSERT_THROW(readFieldInFile<double>(filename22_rd, fieldname_not_exist), MEDEXCEPTION); + + //Test readMeshInFile() method +#ifdef ENABLE_FORCED_FAILURES + { + MESH * aMesh = NULL; + //MEDEXCEPTION: can not open file, but file exist + CPPUNIT_ASSERT_NO_THROW(aMesh = readMeshInFile(filename_rd, meshname)); + CPPUNIT_ASSERT(aMesh); + delete aMesh; + } +#endif + + //Test readMedInFile() method + { + CPPUNIT_ASSERT_NO_THROW(aMed = readMedInFile(filename_rd)); + CPPUNIT_ASSERT(aMed); + } + + //Test readFieldInFile() method +#ifdef ENABLE_FORCED_FAILURES + { + FIELD<double> * aField = NULL; + //MEDEXCEPTION: can not open file, but file exist + CPPUNIT_ASSERT_NO_THROW(aField = readFieldInFile<double>(filename22_rd, fieldname)); + CPPUNIT_ASSERT(aField); + delete aField; + } +#endif + } + + //////////////////// + //Test Write Part // + //////////////////// + { + //Create a FIELD + FIELD<double> *aField_1 = new FIELD<double> (); + + MED_FIELD_RDONLY_DRIVER22<double> *aMedRdFieldDriver22 = + new MED_FIELD_RDONLY_DRIVER22<double>(filename22_rd, aField_1); + aMedRdFieldDriver22->setFieldName(fieldname); + aMedRdFieldDriver22->open(); + aMedRdFieldDriver22->read(); + aMedRdFieldDriver22->close(); + + //Trying write objects in the not existing file +#ifdef ENABLE_FORCED_FAILURES + // (BUG) No exception in this case + CPPUNIT_ASSERT_THROW(writeMedToFile(aMed, fileNotExist_wr), MEDEXCEPTION); +#endif + + //Create a MESH + MESH * aMesh = MEDMEMTest_createTestMesh(); + CPPUNIT_ASSERT_THROW(writeMeshToFile(aMesh, fileNotExist_wr), MEDEXCEPTION); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Error during compilation + //MED_SRC/src/MEDMEM/MEDMEM_TopLevel.hxx:66: error: passing `const MEDMEM::FIELD<double, MEDMEM::FullInterlace>' as `this' argument of `int MEDMEM::FIELD<T, INTERLACING_TAG>::addDriver(MEDMEM::driverTypes, const std::string&, const std::string&, MED_EN::med_mode_acces) [with T = double, INTERLACING_TAG = MEDMEM::FullInterlace]' discards qualifiers CPPUNIT_ASSERT_THROW(writeFieldToFile<double>(aField_1, fileNotExist_wr),MEDEXCEPTION); + CPPUNIT_FAIL("writeFieldToFile(): compilation error"); +#endif + + //Trying write mesh in the file with empty name + aMesh->setName(""); + CPPUNIT_ASSERT_THROW(writeMeshToFile(aMesh, filenameField_wr), MEDEXCEPTION); + + //Test writeMedToFile() and writeMeshToFile() methods + aMesh->setName(meshname); + CPPUNIT_ASSERT_NO_THROW(writeMeshToFile(aMesh, filenameMesh_wr)); + CPPUNIT_ASSERT_NO_THROW(writeMedToFile(aMed, filenameMed_wr)); + + delete aField_1; + delete aMesh; + delete aMed; + } +} diff --git a/src/MEDMEM/Test/MEDMEMTest_Unit.cxx b/src/MEDMEM/Test/MEDMEMTest_Unit.cxx new file mode 100644 index 000000000..1d83ea282 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_Unit.cxx @@ -0,0 +1,353 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include <cstdlib> +#include <exception> + +#include <MEDMEM_Unit.hxx> + +using namespace std; +using namespace MEDMEM; + + +/*! + * Check methods (18), defined in MEDMEM_Unit.hxx: + * class UNIT { + * (+) UNIT(); + * (+) UNIT(string Name, string Description); + * (+) ~UNIT(); + * (+) UNIT & operator=(const UNIT &unit); + * (+) inline void setName(string Name); + * (+) inline void setDescription(string Description); + * (+) inline void setMasse(int Masse); + * (+) inline void setLength(int Length); + * (+) inline void setTime(int Time); + * (+) inline void setTemperature(int Temperature); + * (+) inline void setMatterQuantity(int MatterQuantity); + * (+) void setCurrentStrength(int CurrentStrength); + * (+) inline void setLightIntensity(int LightIntensity); + * + * (+) inline string getName() const; + * (+) inline string getDescription() const; + * (+) inline int getMasse() const; + * (+) inline int getLength() const; + * (+) inline int getTime() const; + * (+) inline int getTemperature() const; + * (+) inline int getMatterQuantity() const; + * (+) inline int getCurrentStrength() const; + * (+) inline int getLightIntensity() const; + * } + * + * Used code of MEDMEM/tests/testUUnit.cxx + */ + +void MEDMEMTest::testUnit() +{ + string myName = "NameForTesting"; + string myDescription = "all values are setted 10"; + int myMasse = 10; + int myLength = 10; + int myTime = 10; + int myTemperature = 10; + int myMatterQuantity = 10; + int myCurrentStrength = 10; + int myLightIntensity = 10; + + //Default constructor + UNIT myUNIT; + + //Normal constructor + UNIT *myUNIT1 = new UNIT(myName,myDescription); + CPPUNIT_ASSERT(myUNIT1); + + //--------------------------------------------------------------------// + // Tests des methodes // + // // + // - setName // + // - setDescription // + // - setMasse // + // - setLength // + // - setTime // + // - setTemperature // + // - setMatterQuantity // + // - setCurrentStrength // + // - setLightIntensity // + //--------------------------------------------------------------------// + + try + { + myUNIT.setName(myName); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setDescription(myDescription); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("MEDMEM_UNIT::setDescription(): Unknown exception"); + } + + try + { + myUNIT.setMasse(myMasse); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setLength(myLength); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setTime(myTime); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setTemperature(myTemperature); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setMatterQuantity(myMatterQuantity); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setCurrentStrength(myCurrentStrength); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + myUNIT.setLightIntensity(myLightIntensity); + } + catch(const std::exception &e) + { + CPPUNIT_FAIL(e.what()); + } + catch(...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //--------------------------------------------------------------------// + // Tests des methodes // + // // + // - getName // + // - getDescription // + // - getMasse // + // - getLength // + // - getTime // + // - getTemperature // + // - getMatterQuantity // + // - getCurrentStrength // + // - getLightIntensity // + //--------------------------------------------------------------------// + + try + { + CPPUNIT_ASSERT( myUNIT.getName() == myName ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getDescription() == myDescription ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getMasse() == myMasse ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getLength() == myLength ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getTime() == myTime ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getTemperature() == myTemperature ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getMatterQuantity() == myMatterQuantity ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getCurrentStrength() == myCurrentStrength ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + try + { + CPPUNIT_ASSERT( myUNIT.getLightIntensity() == myLightIntensity ); + } + catch( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch ( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //--------------------------------------------------------------------// + // Tests des method // + // - operator= // + //--------------------------------------------------------------------// + + UNIT myUNITCpy; + myUNITCpy = myUNIT; + CPPUNIT_ASSERT_EQUAL( myUNITCpy.getTemperature(), myUNITCpy.getTemperature()); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_VtkFieldDriver.cxx b/src/MEDMEM/Test/MEDMEMTest_VtkFieldDriver.cxx new file mode 100644 index 000000000..1610348f5 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_VtkFieldDriver.cxx @@ -0,0 +1,299 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_VtkFieldDriver.hxx> +#include <MEDMEM_Med.hxx> +#include <MEDMEM_Field.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (14), defined in MEDMEM_VtkFieldDriver.hxx: + * template <class T> class VTK_FIELD_DRIVER : public GENDRIVER { + * //MUST BE PRIVATE, because it is impossible to set _ptrField after this constructor. + * //AND cannot compile, so maybe it is specially implemented to prevent usage of it. + * (!) template <class INTERLACING_TAG> VTK_FIELD_DRIVER(); + * (+) template <class INTERLACING_TAG> VTK_FIELD_DRIVER + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField) + * (+) VTK_FIELD_DRIVER(const VTK_FIELD_DRIVER & fieldDriver) + * (+) ~VTK_FIELD_DRIVER() + * (+) void openConst() const throw (MEDEXCEPTION) + * (+) void openConstAppend() const throw (MEDEXCEPTION) + * (+) void open() throw (MEDEXCEPTION) + * (+) void openAppend() throw (MEDEXCEPTION) + * (+) void closeConst() const throw (MEDEXCEPTION) + * (+) void close() + * (+) void setFieldName(const string & fieldName); + * (+) string getFieldName() const; + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void writeAppend(void) const throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest::testVtkFieldDriver() +{ + FIELD<int> *aField = new FIELD<int> (); + FIELD<double> *aField_1 = new FIELD<double> (); + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string emptyfilename = ""; + string fileNotExistsName = "/path_not_exists/file_not_exists.vtk"; + string filename_wr = tmp_dir + "/myField_pointe.vtk"; + + string fieldname_rd_int = "fieldnodeint"; + string fieldname_wr_int = "myintfield"; + string fieldname_rd_double = "fieldnodedouble"; + string fieldname_wr_double = "mydoublefield"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + //Creation Invalid VtkFieldDriver (file not exist) + VTK_FIELD_DRIVER<int> *aInvalidVtkFieldDriver_1 = new VTK_FIELD_DRIVER<int>(fileNotExistsName, aField); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_1->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_1->openConst(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_1->openConstAppend(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid VtkFieldDriver (empty file name) + VTK_FIELD_DRIVER<int> *aInvalidVtkFieldDriver_2 = new VTK_FIELD_DRIVER<int>(emptyfilename, aField); + + //Trying file with empty name + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_2->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_2->openConst(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_2->openConstAppend(), MEDEXCEPTION); + + //////////////////////// + // TEST2: Main test // + //////////////////////// + //Read Fields from file + MED_FIELD_RDONLY_DRIVER21<int> *aMedRdFieldDriver21_int = new MED_FIELD_RDONLY_DRIVER21<int>(filename_rd, aField); + aMedRdFieldDriver21_int->open(); + aMedRdFieldDriver21_int->setFieldName(fieldname_rd_int); + aMedRdFieldDriver21_int->read(); + aMedRdFieldDriver21_int->close(); + + MED_FIELD_RDONLY_DRIVER21<double> *aMedRdFieldDriver21_double = new MED_FIELD_RDONLY_DRIVER21<double>(filename_rd, aField_1); + aMedRdFieldDriver21_double->open(); + aMedRdFieldDriver21_double->setFieldName(fieldname_rd_double); + aMedRdFieldDriver21_double->read(); + aMedRdFieldDriver21_double->close(); + //Check fields + CPPUNIT_ASSERT(aField); + + //Creation correct VtkFieldDriver + VTK_FIELD_DRIVER<int> *aVtkFieldDriver_int = new VTK_FIELD_DRIVER<int>(filename_wr, aField); + + //Check driver + CPPUNIT_ASSERT(aVtkFieldDriver_int); + + //Test setFieldName() and getFieldName() methods + try + { + aVtkFieldDriver_int->setFieldName(fieldname_wr_int); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fieldname_wr_int, aVtkFieldDriver_int->getFieldName()); + + //Test open() method + try + { + aVtkFieldDriver_int->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aVtkFieldDriver_int->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // => Segmentation fault +#endif + + //Test read() method for Vtk Field Driver + CPPUNIT_ASSERT_THROW(aVtkFieldDriver_int->read(),MEDEXCEPTION); + + //Test close() method + try + { + aVtkFieldDriver_int->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test openAppend() method + try + { + aVtkFieldDriver_int->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + + ///////////////////////////////////////////////////////// + // TEST? Test openAppend() and writeAppend() methods // + ///////////////////////////////////////////////////////// + + //Creation correct VtkFieldDriver + VTK_FIELD_DRIVER<double> *aVtkFieldDriver_double = new VTK_FIELD_DRIVER<double>(filename_wr, aField_1); + + //Check driver + CPPUNIT_ASSERT(aVtkFieldDriver_double); + + //Test openAppend() method + try + { + aVtkFieldDriver_double->openAppend(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + aVtkFieldDriver_double->setFieldName(fieldname_wr_double); + +#ifdef ENABLE_FAULTS + //Test writeAppend() method + try + { + aVtkFieldDriver_double->writeAppend(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // => Segmentation fault +#endif + + try + { + aVtkFieldDriver_double->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //#ifdef ENABLE_FORCED_FAILURES + //VTK_FIELD_DRIVER<int> aVtkFieldDriver_intCpy_1; + //VTK_FIELD_DRIVER<int>.template VTK_FIELD_DRIVER<FullInterlace> aVtkFieldDriver_intCpy_1; + //CPPUNIT_FAIL("Compilation error: no matching function for call to 'MEDMEM::VTK_FIELD_DRIVER<int>::VTK_FIELD_DRIVER()"); + //#endif + +#ifdef ENABLE_FAULTS + //Test copy constructor + VTK_FIELD_DRIVER<int> aVtkFieldDriver_intCpy_2 (*aVtkFieldDriver_int); + // => Segmentation fault after call Copy Constructor + + CPPUNIT_ASSERT_EQUAL(aVtkFieldDriver_intCpy_2, *aVtkFieldDriver_int); + //Test (bool operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aVtkFieldDriver_intCpy_2.GENDRIVER::operator== (*aVtkFieldDriver_int)); + + //Test (friend ostream & operator <<) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream ostr1, ostr2; + ostr1<<*aVtkFieldDriver_int; + ostr2<<aVtkFieldDriver_intCpy_2; + + CPPUNIT_ASSERT(ostr1.str() != ""); + CPPUNIT_ASSERT(ostr1.str() == ostr2.str()); +#endif + + //Delete all objects + delete aField; + delete aField_1; +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Exception in the destructor after trying close not existing file. + delete aInvalidVtkFieldDriver_1; +#endif + delete aInvalidVtkFieldDriver_2; + delete aMedRdFieldDriver21_int; + delete aMedRdFieldDriver21_double; + delete aVtkFieldDriver_int; + delete aVtkFieldDriver_double; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_VtkFieldDriver_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_VtkFieldDriver_fault.cxx new file mode 100644 index 000000000..0fecaafc7 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_VtkFieldDriver_fault.cxx @@ -0,0 +1,304 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_VtkFieldDriver.hxx> +#include <MEDMEM_Med.hxx> +#include <MEDMEM_Field.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +//#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (14), defined in MEDMEM_VtkFieldDriver.hxx: + * template <class T> class VTK_FIELD_DRIVER : public GENDRIVER { + * //MUST BE PRIVATE, because it is impossible to set _ptrField after this constructor. + * //AND cannot compile, so maybe it is specially implemented to prevent usage of it. + * (!) template <class INTERLACING_TAG> VTK_FIELD_DRIVER(); + * (+) template <class INTERLACING_TAG> VTK_FIELD_DRIVER + * (const string & fileName, FIELD<T, INTERLACING_TAG> * ptrField) + * (+) VTK_FIELD_DRIVER(const VTK_FIELD_DRIVER & fieldDriver) + * (+) ~VTK_FIELD_DRIVER() + * (+) void openConst() const throw (MEDEXCEPTION) + * (+) void openConstAppend() const throw (MEDEXCEPTION) + * (+) void open() throw (MEDEXCEPTION) + * (+) void openAppend() throw (MEDEXCEPTION) + * (+) void closeConst() const throw (MEDEXCEPTION) + * (+) void close() + * (+) void setFieldName(const string & fieldName); + * (+) string getFieldName() const; + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void writeAppend(void) const throw (MEDEXCEPTION); + * } + */ +void MEDMEMTest_testVtkFieldDriver() +{ + FIELD<int> *aField = new FIELD<int> (); + FIELD<double> *aField_1 = new FIELD<double> (); + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string emptyfilename = ""; + string fileNotExistsName = "/path_not_exists/file_not_exists.vtk"; + string filename_wr = tmp_dir + "/myField_pointe.vtk"; + + string fieldname_rd_int = "fieldnodeint"; + string fieldname_wr_int = "myintfield"; + string fieldname_rd_double = "fieldnodedouble"; + string fieldname_wr_double = "mydoublefield"; + + // To remove tmp files from disk + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + + ///////////////////////////////////// + // TEST1: Open not existing file // + ///////////////////////////////////// + //Creation Invalid VtkFieldDriver (file not exist) + VTK_FIELD_DRIVER<int> *aInvalidVtkFieldDriver_1 = new VTK_FIELD_DRIVER<int>(fileNotExistsName, aField); + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_1->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_1->openConst(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_1->openConstAppend(), MEDEXCEPTION); + + ///////////////////////////////////////////// + // TEST2: Open file with empty file name // + ///////////////////////////////////////////// + //Creation Invalid VtkFieldDriver (empty file name) + VTK_FIELD_DRIVER<int> *aInvalidVtkFieldDriver_2 = new VTK_FIELD_DRIVER<int>(emptyfilename, aField); + + //Trying file with empty name + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_2->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_2->openConst(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkFieldDriver_2->openConstAppend(), MEDEXCEPTION); + + //////////////////////// + // TEST2: Main test // + //////////////////////// + //Read Fields from file + MED_FIELD_RDONLY_DRIVER21<int> *aMedRdFieldDriver21_int = new MED_FIELD_RDONLY_DRIVER21<int>(filename_rd, aField); + aMedRdFieldDriver21_int->open(); + aMedRdFieldDriver21_int->setFieldName(fieldname_rd_int); + aMedRdFieldDriver21_int->read(); + aMedRdFieldDriver21_int->close(); + + MED_FIELD_RDONLY_DRIVER21<double> *aMedRdFieldDriver21_double = new MED_FIELD_RDONLY_DRIVER21<double>(filename_rd, aField_1); + aMedRdFieldDriver21_double->open(); + aMedRdFieldDriver21_double->setFieldName(fieldname_rd_double); + aMedRdFieldDriver21_double->read(); + aMedRdFieldDriver21_double->close(); + //Check fields + CPPUNIT_ASSERT(aField); + + //Creation correct VtkFieldDriver + VTK_FIELD_DRIVER<int> *aVtkFieldDriver_int = new VTK_FIELD_DRIVER<int>(filename_wr, aField); + + //Check driver + CPPUNIT_ASSERT(aVtkFieldDriver_int); + + //Test setFieldName() and getFieldName() methods + try + { + aVtkFieldDriver_int->setFieldName(fieldname_wr_int); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + CPPUNIT_ASSERT_EQUAL(fieldname_wr_int, aVtkFieldDriver_int->getFieldName()); + + //Test open() method + try + { + aVtkFieldDriver_int->open(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + +#ifdef ENABLE_FAULTS + //Test write() method + try + { + aVtkFieldDriver_int->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // => Segmentation fault +#endif + + //Test read() method for Vtk Field Driver + CPPUNIT_ASSERT_THROW(aVtkFieldDriver_int->read(),MEDEXCEPTION); + + //Test close() method + try + { + aVtkFieldDriver_int->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test openAppend() method + try + { + aVtkFieldDriver_int->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + + ///////////////////////////////////////////////////////// + // TEST? Test openAppend() and writeAppend() methods // + ///////////////////////////////////////////////////////// + + //Creation correct VtkFieldDriver + VTK_FIELD_DRIVER<double> *aVtkFieldDriver_double = new VTK_FIELD_DRIVER<double>(filename_wr, aField_1); + + //Check driver + CPPUNIT_ASSERT(aVtkFieldDriver_double); + + //Test openAppend() method + try + { + aVtkFieldDriver_double->openAppend(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + aVtkFieldDriver_double->setFieldName(fieldname_wr_double); + +#ifdef ENABLE_FAULTS + //Test writeAppend() method + try + { + aVtkFieldDriver_double->writeAppend(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + // => Segmentation fault +#endif + + try + { + aVtkFieldDriver_double->close(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //#ifdef ENABLE_FORCED_FAILURES + //VTK_FIELD_DRIVER<int> aVtkFieldDriver_intCpy_1; + //VTK_FIELD_DRIVER<int>.template VTK_FIELD_DRIVER<FullInterlace> aVtkFieldDriver_intCpy_1; + //CPPUNIT_FAIL("Compilation error: no matching function for call to 'MEDMEM::VTK_FIELD_DRIVER<int>::VTK_FIELD_DRIVER()"); + //#endif + +#ifdef ENABLE_FAULTS + //Test copy constructor + VTK_FIELD_DRIVER<int> aVtkFieldDriver_intCpy_2 (*aVtkFieldDriver_int); + // => Segmentation fault after call Copy Constructor + + CPPUNIT_ASSERT_EQUAL(aVtkFieldDriver_intCpy_2, *aVtkFieldDriver_int); + //Test (bool operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + CPPUNIT_ASSERT(aVtkFieldDriver_intCpy_2.GENDRIVER::operator== (*aVtkFieldDriver_int)); + + //Test (friend ostream & operator <<) defined in GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream ostr1, ostr2; + ostr1<<*aVtkFieldDriver_int; + ostr2<<aVtkFieldDriver_intCpy_2; + + CPPUNIT_ASSERT(ostr1.str() != ""); + CPPUNIT_ASSERT(ostr1.str() == ostr2.str()); +#endif + + //Delete all objects + delete aField; + delete aField_1; +#ifdef ENABLE_FORCED_FAILURES + // (BUG) Exception in the destructor after trying close not existing file. + delete aInvalidVtkFieldDriver_1; +#endif + delete aInvalidVtkFieldDriver_2; + delete aMedRdFieldDriver21_int; + delete aMedRdFieldDriver21_double; + delete aVtkFieldDriver_int; + delete aVtkFieldDriver_double; +} + +int main (int argc, char** argv) +{ + MEDMEMTest_testVtkFieldDriver(); +} diff --git a/src/MEDMEM/Test/MEDMEMTest_VtkMedDriver.cxx b/src/MEDMEM/Test/MEDMEMTest_VtkMedDriver.cxx new file mode 100644 index 000000000..ad8b0a222 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_VtkMedDriver.cxx @@ -0,0 +1,133 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_Compatibility21_22.hxx> +#include <MEDMEM_VtkMedDriver.hxx> +#include <MEDMEM_MedMedDriver21.hxx> +#include <MEDMEM_Med.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (5), defined in MEDMEM_VtkMedDriver.hxx: + * class VTK_MED_DRIVER : public GENDRIVER { + * (+) VTK_MED_DRIVER(const string & fileName, MED * const ptrMed); + * (+) VTK_MED_DRIVER(const VTK_MED_DRIVER & driver); + * (+) ~VTK_MED_DRIVER(); + * (+) void write (void) const; + * (-) virtual void read (void) {}; + * (+) GENDRIVER * copy (void) const; + * } + */ +void MEDMEMTest::testVtkMedDriver() +{ + MED *aMed = new MED(); + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string emptyfilename = ""; + string fileNotExistsName = "/path_not_exists/file_not_exists.vtk"; + string filename_wr = tmp_dir + "/myMED_pointe.vtk"; + + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + + //Read MED structure from file + MED_MED_RDONLY_DRIVER21 *aMedMedRdDriver21 = new MED_MED_RDONLY_DRIVER21(filename_rd, aMed); + aMedMedRdDriver21->open(); + aMedMedRdDriver21->read(); + aMedMedRdDriver21->close(); + //Check Med + CPPUNIT_ASSERT(aMed); + + //Creation incorrect Vtk Med Driver (file is not exists) + VTK_MED_DRIVER *aInvalidVtkMedDriver = new VTK_MED_DRIVER(fileNotExistsName,aMed); + + //Trying write data in the not existing file + CPPUNIT_ASSERT_THROW(aInvalidVtkMedDriver->write(),MEDEXCEPTION); + + //Creation correct Vtk Med Driver + VTK_MED_DRIVER *aVtkMedDriver = new VTK_MED_DRIVER(filename_wr ,aMed); + + //Check driver + CPPUNIT_ASSERT(aVtkMedDriver); + + //Test write() method + + try + { + aVtkMedDriver->write(); + } + catch(MEDEXCEPTION &e) + { + CPPUNIT_FAIL(e.what()); + } + catch( ... ) + { + CPPUNIT_FAIL("Unknown exception"); + } + + //Test copy constructor + VTK_MED_DRIVER *aVtkMedDriverCpy = new VTK_MED_DRIVER(*aVtkMedDriver); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_EQUAL(*aVtkMedDriverCpy, *aVtkMedDriver); +#endif + + //Test (operator ==) defined in GENDRIVER class in MEDMEM_GenDriver.hxx +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT(*aVtkMedDriverCpy == *aVtkMedDriver); +#endif + + //Test copy() function + VTK_MED_DRIVER *aVtkMedDriverCpy_1 = (VTK_MED_DRIVER*)aVtkMedDriver->copy(); +#ifdef ENABLE_FORCED_FAILURES + CPPUNIT_ASSERT_EQUAL(*aVtkMedDriverCpy_1, *aVtkMedDriver); +#endif + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + ostringstream ostr1, ostr2; + ostr1<<*aVtkMedDriverCpy; + ostr2<<*aVtkMedDriverCpy_1; + CPPUNIT_ASSERT(ostr1.str() != ""); + CPPUNIT_ASSERT(ostr1.str() == ostr2.str()); + + + //Delete objects + delete aMedMedRdDriver21; +#ifdef ENABLE_FORCED_FAILURES + delete aInvalidVtkMedDriver; + delete aVtkMedDriver; + delete aVtkMedDriverCpy; + delete aVtkMedDriverCpy_1; + //MEDEXCEPTION in the destructor (after trying close file) +#endif +} diff --git a/src/MEDMEM/Test/MEDMEMTest_VtkMeshDriver.cxx b/src/MEDMEM/Test/MEDMEMTest_VtkMeshDriver.cxx new file mode 100644 index 000000000..95e56e181 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_VtkMeshDriver.cxx @@ -0,0 +1,164 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" +#include <cppunit/TestAssert.h> + +#include <MEDMEM_VtkMeshDriver.hxx> +#include <MEDMEM_MedMeshDriver21.hxx> +#include <MEDMEM_Mesh.hxx> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; + +/*! + * Check methods (11), defined in MEDMEM_VtkMeshDriver.hxx: + * class VTK_MESH_DRIVER : public GENDRIVER { + * (+) VTK_MESH_DRIVER(); + * (+) VTK_MESH_DRIVER(const string & fileName, MESH * ptrMesh); + * (+) VTK_MESH_DRIVER(const VTK_MESH_DRIVER & driver); + * (+) ~VTK_MESH_DRIVER(); + * (+) void open(); + * (+) void close(); + * (+) void openConst() const throw (MEDEXCEPTION); + * (+) void closeConst() const throw (MEDEXCEPTION); + * (+) void write(void) const throw (MEDEXCEPTION); + * (+) void read (void) throw (MEDEXCEPTION); + * (+) void setMeshName(const string & meshName); + * (+) string getMeshName() const; + * } + */ +void MEDMEMTest::testVtkMeshDriver() +{ + MESH * aMesh = new MESH(); + + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + string filename_rd = data_dir + "/MedFiles/pointe.med"; + string emptyfilename = ""; + string meshname_rd = "maa1"; + string meshname = "MyMesh"; + string fileNotExistsName = "/path_not_exists/file_not_exists.vtk"; + string filename = tmp_dir + "/my_pointe.vtk"; + + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename); + + { + //Creation a invalid Vtk driver + VTK_MESH_DRIVER *aInvalidVtkDriver = new VTK_MESH_DRIVER(fileNotExistsName, aMesh); + + //Trying open not existing file + CPPUNIT_ASSERT_THROW(aInvalidVtkDriver->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aInvalidVtkDriver->openConst(), MEDEXCEPTION); + +#ifdef ENABLE_FORCED_FAILURES + // (BUG) In destructor of VTK_MESH_DRIVER: Exception after trying close not existing file + CPPUNIT_ASSERT_NO_THROW(delete aInvalidVtkDriver); +#endif + } + + { + //Create Vtk driver with empty file name + VTK_MESH_DRIVER *aEmptyVtkDriver = new VTK_MESH_DRIVER(emptyfilename, aMesh); + + //Test open() and openConst() methods with empty file name + CPPUNIT_ASSERT_THROW(aEmptyVtkDriver->open(), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(aEmptyVtkDriver->openConst(), MEDEXCEPTION); + + delete aEmptyVtkDriver; + } + + //Creation corect driver + VTK_MESH_DRIVER *aVtkDriver = new VTK_MESH_DRIVER(filename, aMesh); + CPPUNIT_ASSERT(aVtkDriver); + + //Create a Mesh + MED_MESH_RDONLY_DRIVER21 *aMedMeshRdDriver21 = new MED_MESH_RDONLY_DRIVER21(filename_rd, aMesh); + aMedMeshRdDriver21->open(); + aMedMeshRdDriver21->setMeshName(meshname_rd); + + //Test openConst() and closeConst() methods + CPPUNIT_ASSERT_NO_THROW(aVtkDriver->openConst()); + CPPUNIT_ASSERT_NO_THROW(aVtkDriver->closeConst()); + + //Test open() method + CPPUNIT_ASSERT_NO_THROW(aVtkDriver->open()); + + //Trying open file secondary +#ifdef ENABLE_FORCED_FAILURES + // (BUG) No exception on attempt to open a file for the second time + CPPUNIT_ASSERT_THROW(aVtkDriver->open(), MEDEXCEPTION); +#endif + + //Test read method + CPPUNIT_ASSERT_THROW(aVtkDriver->read(), MEDEXCEPTION); + + //Trying write empty mesh +#ifdef ENABLE_FAULTS + // ? (BUG) ? In VTK_MESH_DRIVER::write() => Segmentation fault on attempt to write an empty mesh + CPPUNIT_ASSERT_THROW(aVtkDriver->write(), MEDEXCEPTION); +#endif + + //Read mesh from Med file + aMedMeshRdDriver21->read(); + + //Check mesh + CPPUNIT_ASSERT(aMesh); + + //Test SetMeshName and getMeshName methods + CPPUNIT_ASSERT_NO_THROW(aVtkDriver->setMeshName(meshname)); + CPPUNIT_ASSERT_EQUAL(meshname, aVtkDriver->getMeshName()); + + //Test write method + CPPUNIT_ASSERT_NO_THROW(aVtkDriver->write()); + + //Test close method + CPPUNIT_ASSERT_NO_THROW(aVtkDriver->close()); + + //Test Default constructor + VTK_MESH_DRIVER aVtkDriverCpy_1; + + //Test copy constructor +#ifdef ENABLE_FAULTS + // (BUG) In copy constructor of VTK_MESH_DRIVER: Segmentation fault + VTK_MESH_DRIVER aVtkDriverCpy_2 (*aVtkDriver); +#endif + + //Test (bool operator ==) defined in GENDRIVER class + //CPPUNIT_ASSERT(aVtkDriverCpy_2.GENDRIVER::operator==(aVtkDriver)); + + //Test (friend ostream & operator <<) defined GENDRIVER class in MEDMEM_GenDriver.hxx + //ostringstream ostr1, ostr2; + //ostr1 << aVtkDriverCpy_2; + //ostr2 << aVtkDriver; + //CPPUNIT_ASSERT(ostr1.str() != ""); + //CPPUNIT_ASSERT_EQUAL(ostr1.str(), ostr2.str()); + + //Delete objects + delete aVtkDriver; + delete aMedMeshRdDriver21; + delete aMesh; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_VtkMeshDriver_fault.cxx b/src/MEDMEM/Test/MEDMEMTest_VtkMeshDriver_fault.cxx new file mode 100644 index 000000000..ac5122689 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_VtkMeshDriver_fault.cxx @@ -0,0 +1,67 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDMEMTest.hxx" + +#include <MEDMEM_VtkMeshDriver.hxx> +#include <MEDMEM_MedMeshDriver21.hxx> +#include <MEDMEM_Mesh.hxx> + +using namespace std; +using namespace MEDMEM; + +int main (int argc, char** argv) +{ + string tmp_dir = getenv("TMP"); + string meshname = "MyMesh"; + string filename = tmp_dir + "/my_pointe.vtk"; + + MEDMEMTest_TmpFilesRemover aRemover; + aRemover.Register(filename); + + //Create an empty Mesh + MESH * aMesh = new MESH(); + + //Creation corect driver + VTK_MESH_DRIVER *aVtkDriver = new VTK_MESH_DRIVER(filename, aMesh); + aVtkDriver->setMeshName(meshname); + aVtkDriver->open(); + + // ? (BUG) ? In VTK_MESH_DRIVER::write() => Segmentation fault on attempt to write an empty mesh + try + { + //Trying write an empty mesh + aVtkDriver->write(); + } + catch (MEDEXCEPTION & ex) + { + // good behaviour + } + catch (...) + { + } + + aVtkDriver->close(); + + // (BUG) In copy constructor of VTK_MESH_DRIVER: Segmentation fault or Infinite loop + VTK_MESH_DRIVER aVtkDriverCpy_2 (*aVtkDriver); + + delete aVtkDriver; + delete aMesh; +} diff --git a/src/MEDMEM/Test/MEDMEMTest_nArray.cxx b/src/MEDMEM/Test/MEDMEMTest_nArray.cxx new file mode 100644 index 000000000..0e2fe4ce4 --- /dev/null +++ b/src/MEDMEM/Test/MEDMEMTest_nArray.cxx @@ -0,0 +1,529 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDMEMTest.hxx" +#include <cppunit/Message.h> +#include <cppunit/TestAssert.h> + +#include "MEDMEM_nArray.hxx" +#include "MEDMEM_define.hxx" +#include "MEDMEM_ArrayConvert.hxx" + +#include <sstream> +#include <cmath> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +/*! + * Check methods (21), defined in MEDMEM_nArray.hxx: + * class MEDMEM_Array_ { + * (-) virtual bool getGaussPresence() const { return false; } + * (-) virtual MED_EN::medModeSwitch getInterlacingType() const {return MED_EN::MED_UNDEFINED_INTERLACE;} + * (+) ~MEDMEM_Array_() {}; + * } + * template<class ARRAY_ELEMENT_TYPE, + * class INTERLACING_POLICY=FullInterlaceNoGaussPolicy, + * class CHECKING_POLICY=IndexCheckPolicy> + * class MEDMEM_Array : public INTERLACING_POLICY, public CHECKING_POLICY, public MEDMEM_Array_ { + * (+) MEDMEM_Array(); + * (+) ~MEDMEM_Array(); + * (+) inline MEDMEM_Array(int dim, int nbelem); + * (+) inline MEDMEM_Array(ElementType * values, int dim, int nbelem, + * bool shallowCopy=false, bool ownershipOfValues=false); + * (+) inline MEDMEM_Array(int dim, int nbelem, int nbtypegeo, + * const int * const nbelgeoc, const int * const nbgaussgeo); + * (+) inline MEDMEM_Array(ElementType * values, int dim, int nbelem, int nbtypegeo, + * const int * const nbelgeoc, const int * const nbgaussgeo, + * bool shallowCopy=false, bool ownershipOfValues=false); + * (+) inline MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false); + * (+) inline MEDMEM_Array<ElementType,InterlacingPolicy,CheckingPolicy> & + * operator=(const MEDMEM_Array & array); + * (+) MED_EN::medModeSwitch getInterlacingType() const; + * (+) bool getGaussPresence() const; + * (+) ElementType * getPtr(); + * (+) void setPtr(ElementType * values, bool shallowCopy=false, bool ownershipOfValues=false); + * (+) inline const ElementType * getRow(int i) const; + * (+) void setRow(int i,const ElementType * const value); + * (+) inline const ElementType * getColumn(int j) const; + * (+) void setColumn(int j, const ElementType * const value); + * (+) inline const ElementType & getIJ(int i, int j) const; + * (+) inline const ElementType & getIJK(int i, int j, int k) const; + * (+) inline void setIJ(int i, int j, const ElementType & value); + * (+) inline void setIJK(int i, int j, int k, const ElementType & value); + * (+) bool operator == (const MEDMEM_Array & array) const; + * (+) friend ostream & operator<<(ostream & os, const MEDMEM_Array & array); + * } + */ +void MEDMEMTest::testnArray() +{ + const int mdim = 2; + const int nbelem1 = 20; + const double EPS = 0.00001; + + ///////////////////////////////////////// + // TEST 1 FullInterlace et NoGauss // + //////////////////////////////////////// + const double * myArray1Ptr = 0; + const double array1Ref[] = { 11 , 12 , 21 , 22 , 31 , 32 , 41 , 42 , 51 , 52 , + 61 , 62 , 71 , 72 , 81 , 82 , 91 , 92 , 101 , 102 , + 111 , 112 , 121 , 122 , 131 , 132 , 141 , 142 , + 151 , 152 , 161 , 162 , 171 , 172 , 181 , 182 , + 191 , 192 , 201 , 202 }; + + const double array2Ref[] = { 11 , 21 , 31 , 41 , 51 , 61 , 71 , 81 , 91 , 101 + , 111 , 121 , 131 , 141 , 151 , 161 , 171 , 181 + , 191 , 201 , + 12 , 22 , 32 , 42 , 52 , 62 , 72 , 82 , 92 , 102 + , 112 , 122 , 132 , 142 , 152 , 162 , 172 , 182 + , 192 , 202 }; + + //test MEDMEM_Array(int dim, int nbelem) + MEDMEM_Array<double> myArray1(mdim,nbelem1); + //test getGaussPresence + CPPUNIT_ASSERT( !myArray1.getGaussPresence()); + + //test setIJ. Fill array + for (int i =1; i <= nbelem1; i++) + for (int j =1; j <= mdim; j++) + { + CPPUNIT_ASSERT_NO_THROW(myArray1.setIJ(i,j,i*10+j)); + } + + //test getPtr + myArray1Ptr = myArray1.getPtr(); + for (int i = 0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray1Ptr[i] == array1Ref[i] ); + + { + //test MEDMEM_Array(ElementType * values, int dim, int nbelem, bool shallowCopy=false, bool ownershipOfValues=false) + MEDMEM_Array<double> myArray1val ((double*)array1Ref, mdim, nbelem1); + myArray1Ptr = myArray1val.getPtr(); + for (int i = 0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray1Ptr[i] == array1Ref[i] ); + + //test MEDMEM_Array(ElementType * values, int dim, int nbelem, bool shallowCopy=true, bool ownershipOfValues=false); + MEDMEM_Array<double> myArray1valsh ((double*)array1Ref, mdim, nbelem1, true); + myArray1Ptr = myArray1valsh.getPtr(); + for (int i = 0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray1Ptr[i] == array1Ref[i] ); + + //test setPtr + double myPtr[] = {-1, -2, -3, -4, -5, -6, -7, -8, -9, 0}; + CPPUNIT_ASSERT_NO_THROW(myArray1valsh.setPtr(myPtr)); + //size the array stays the same, only first 10 element are being overwritten + myArray1Ptr = myArray1valsh.getPtr(); + for (int i = 0; i < 11; i++) + CPPUNIT_ASSERT_EQUAL(myArray1Ptr[i], myPtr[i]); + } + + //test MEDMEM_Array(ElementType * values, int dim, int nbelem, bool shallowCopy=true, bool ownershipOfValues=true); + { + double * array1Ref_do_not_delete = new double[40]; + for (int i = 0; i < 40; i = i + 2) { + array1Ref_do_not_delete[i ] = 10.0 * (i+1) + 1; + array1Ref_do_not_delete[i+1] = 10.0 * (i+1) + 2; + } + MEDMEM_Array<double> myArray1valow (array1Ref_do_not_delete, mdim, nbelem1, true, true); + } + + //test MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false) + MEDMEM_Array<double> myArray1bis (myArray1, false); + CPPUNIT_ASSERT(myArray1 == myArray1bis); + + myArray1Ptr = myArray1bis.getPtr(); + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray1Ptr[i] == array1Ref[i] ); + + //test MEDMEM_Array() + MEDMEM_Array<double> myArray1ter; + try + { + myArray1ter = myArray1; + myArray1Ptr = myArray1ter.getPtr(); + } + catch ( const std::exception &e ) + { + CPPUNIT_FAIL(e.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray1Ptr[i] == array1Ref[i] ); + + MEDMEM_Array<double> myArray1qua(mdim,nbelem1); + myArray1Ptr = myArray1qua.getPtr(); + + for (int i =1; i <= nbelem1; i++) + { + try { + //test setRow(int i,const ElementType * const value) + myArray1qua.setRow(i,&array1Ref[(i-1)*mdim]); + } + catch (MEDMEM::MEDEXCEPTION &m) { + CPPUNIT_FAIL(m.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray1Ptr[i] == array1Ref[i] ); + + //test getColumn(int j) + CPPUNIT_ASSERT_THROW(myArray1qua.getColumn(1), MEDEXCEPTION); + + MEDMEM_Array<double,NoInterlaceNoGaussPolicy> * myArray1cin = ArrayConvert(myArray1); + myArray1Ptr = myArray1cin->getPtr(); + int elemno = 0; + for (int j=1; j <= mdim; j++) + for (int i=1; i <= nbelem1 ; i++ ) { + CPPUNIT_ASSERT( myArray1cin->getIJ(i,j) == array2Ref[elemno] ); + CPPUNIT_ASSERT( myArray1Ptr[elemno] == array2Ref[elemno] ); + elemno++; + } + + ///////////////////////////////////// + // TEST 2 NoInterlace et NoGauss // + ///////////////////////////////////// + { + const double * myArray2Ptr = 0; + //MEDMEM_Array(int dim, int nbelem) + MEDMEM_Array<double,NoInterlaceNoGaussPolicy> myArray2(mdim,nbelem1); + + for (int i =1; i <= nbelem1; i++) { + for (int j =1; j <= mdim; j++) { + //test setIJ(int i, int j, const ElementType & value) + CPPUNIT_ASSERT_NO_THROW(myArray2.setIJ(i,j,i*10+j)); + } + } + + //test getPtr() + myArray2Ptr = myArray2.getPtr(); + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray2Ptr[i] == array2Ref[i] ); + + //test MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false) + MEDMEM_Array<double,NoInterlaceNoGaussPolicy> myArray2bis(myArray2, false); + myArray2Ptr = myArray2bis.getPtr(); + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray2Ptr[i] == array2Ref[i] ); + + //test MEDMEM_Array() + MEDMEM_Array<double,NoInterlaceNoGaussPolicy> myArray2ter; + //test operator=(const MEDMEM_Array & array) + myArray2ter = myArray2; + //test getPtr + myArray2Ptr = myArray2ter.getPtr(); + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray2Ptr[i] == array2Ref[i] ); + + MEDMEM_Array<double,NoInterlaceNoGaussPolicy> myArray2qua(mdim,nbelem1); + myArray2Ptr = myArray2qua.getPtr(); + + for (int j = 1; j <= mdim; j++) { + //test setColumn(int j, const ElementType * const value) + CPPUNIT_ASSERT_NO_THROW(myArray2qua.setColumn(j,&array2Ref[nbelem1*(j-1)])); + } + + for (int i =0; i < mdim*nbelem1; i++) + CPPUNIT_ASSERT( myArray2Ptr[i] == array2Ref[i] ); + + //test getRow(int i) + CPPUNIT_ASSERT_THROW(myArray2qua.getRow(1), MEDEXCEPTION); + + MEDMEM_Array<double,FullInterlaceNoGaussPolicy> * myArray2cin = ArrayConvert(myArray2); + myArray2Ptr = myArray2cin->getPtr(); + elemno = 0; + for (int i=1; i <= nbelem1 ; i++) { + for (int j=1; j <= mdim; j++) { + CPPUNIT_ASSERT( myArray2cin->getIJ(i,j) == array1Ref[elemno] ); + CPPUNIT_ASSERT( myArray2Ptr[elemno] == array1Ref[elemno] ); + elemno++; + } + } + } + + /////////////////////////////////////// + // TEST 3 FullInterlace et Gauss // + ////////////////////////////////////// + const int nbelem2 = 5; + const int nbtypegeo = 2; + const int nbelgeoc[nbtypegeo+1] = {1,3,6}; + const int nbgaussgeo[nbtypegeo+1] = {-1,2,3}; + + const double * myArray3Ptr = 0; + const double array3Ref[] = {1.11 , 1.12 , 1.21 , 1.22 , + 2.11 , 2.12 , 2.21 , 2.22 , + 13.11 , 13.12 , 13.21 , 13.22 , 13.31 , 13.32 , + 14.11 , 14.12 , 14.21 , 14.22 , 14.31 , 14.32 , + 15.11 , 15.12 , 15.21 , 15.22 , 15.31 , 15.32 }; + + const double array4Ref[] = { 1.11 , 1.21 , 2.11 , 2.21, + 13.11 , 13.21 , 13.31 , 14.11 , 14.21 , 14.31 , + 15.11 , 15.21 , 15.31 , + 1.12 , 1.22 , 2.12 , 2.22 , + 13.12 , 13.22 , 13.32 , 14.12 , 14.22 , 14.32 , + 15.12 , 15.22 , 15.32 }; + + const int array5Ref[] = { 1 , 1 , 2 , 2, + 13 , 13 , 13 , 14 , 14 , 14 , + 15 , 15 , 15 , + 1 , 1 , 2 , 2 , + 13 , 13 , 13 , 14 , 14 , 14 , + 15 , 15 , 15 }; + + //test MEDMEM_Array(int dim, int nbelem, int nbtypegeo, const int * const nbelgeoc, const int * const nbgaussgeo) + MEDMEM_Array<double,FullInterlaceGaussPolicy> myArray3(mdim,nbelem2,nbtypegeo,nbelgeoc,nbgaussgeo); + + elemno = 1; + for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) { + for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) { + for (int k=1; k <= nbgaussgeo[ntyp]; k++) + for (int j=1; j <= mdim; j++) { + try{ + //test setIJK(int i, int j, int k, const ElementType & value) + myArray3.setIJK(elemno,j,k,elemno+(ntyp-1)*10+0.1*k+0.01*j); + } + catch (MEDMEM::MEDEXCEPTION &m) { + CPPUNIT_FAIL(m.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + elemno++; + } + } + + myArray3Ptr = myArray3.getPtr(); + for (int i =0; i < myArray3.getArraySize(); i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(myArray3Ptr[i], array3Ref[i], EPS); + + MEDMEM_Array<double,FullInterlaceGaussPolicy> myArray3bis(myArray3, false); + myArray3Ptr = myArray3bis.getPtr(); + + elemno = 0; + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray3bis.getNbGauss(i); k++) + for (int j=1; j <= mdim; j++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray3bis.getIJK(i,j,k), array3Ref[elemno], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray3Ptr[elemno], array3Ref[elemno], EPS ); + elemno++; + } + + //test MEDMEM_Array() + MEDMEM_Array<double,FullInterlaceGaussPolicy> myArray3ter; + //test operator=(const MEDMEM_Array & array) + myArray3ter = myArray3; + myArray3Ptr = myArray3ter.getPtr(); + + elemno = 0; + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray3ter.getNbGauss(i); k++) + for (int j=1; j <= mdim; j++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray3ter.getIJK(i,j,k), array3Ref[elemno], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray3Ptr[elemno], array3Ref[elemno], EPS ); + elemno++; + } + + MEDMEM_Array<double,FullInterlaceGaussPolicy> myArray3qua(mdim,nbelem2, + nbtypegeo,nbelgeoc,nbgaussgeo); + myArray3Ptr = myArray3qua.getPtr(); + + int cumul = 0; + for (int i =1; i <= nbelem2; i++){ + try{ + myArray3qua.setRow(i,&array3Ref[cumul]); + cumul+=myArray3qua.getNbGauss(i)*mdim; + } + catch (MEDMEM::MEDEXCEPTION &m) { + CPPUNIT_FAIL(m.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + }; + + for (int i =0; i < myArray3qua.getArraySize(); i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray3Ptr[i], array3Ref[i], EPS ); + + MEDMEM_Array<double,NoInterlaceGaussPolicy> * myArray3cin = ArrayConvert(myArray3); + myArray3Ptr = myArray3cin->getPtr(); + elemno = 0; + for (int j=1; j <= mdim; j++) + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray3cin->getNbGauss(i); k++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray3cin->getIJK(i,j,k), array4Ref[elemno], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL(myArray3Ptr[elemno], array4Ref[elemno], EPS ); + elemno++; + } + + //////////////////////////////////// + // TEST 4 NoInterlace et Gauss // + //////////////////////////////////// + const double * myArray4Ptr = 0; + //test MEDMEM_Array(int dim, int nbelem, int nbtypegeo, const int * const nbelgeoc, const int * const nbgaussgeo) + MEDMEM_Array<double,NoInterlaceGaussPolicy> myArray4(mdim,nbelem2,nbtypegeo,nbelgeoc,nbgaussgeo); + + elemno = 1; + for (int ntyp=1; ntyp <= nbtypegeo; ntyp++ ) { + for (int i=0; i < (nbelgeoc[ntyp]-nbelgeoc[ntyp-1]) ; i++ ) { + for (int k=1; k <= nbgaussgeo[ntyp]; k++) + for (int j=1; j <= mdim; j++) { + try{ + //test setIJK(int i, int j, int k, const ElementType & value) + myArray4.setIJK(elemno,j,k,elemno+(ntyp-1)*10+0.1*k+0.01*j); + } + catch (MEDMEM::MEDEXCEPTION &m) { + CPPUNIT_FAIL(m.what()); + } + catch (...) + { + CPPUNIT_FAIL("Unknown exception"); + } + } + elemno++; + } + } + + //test getPtr() + myArray4Ptr = myArray4.getPtr(); + for (int i =0; i < myArray4.getArraySize(); i++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4Ptr[i], array4Ref[i], EPS ); + } + + //test MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false) + MEDMEM_Array<double,NoInterlaceGaussPolicy> myArray4bis(myArray4, false); + myArray4Ptr = myArray4bis.getPtr(); + + elemno = 0; + for (int j=1; j <= mdim; j++) + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray4bis.getNbGauss(i); k++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4bis.getIJK(i,j,k), array4Ref[elemno], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4Ptr[elemno], array4Ref[elemno], EPS ); + elemno++; + } + + //test MEDMEM_Array() + MEDMEM_Array<double,NoInterlaceGaussPolicy> myArray4ter; + //test operator=(const MEDMEM_Array & array) + myArray4ter = myArray4; + myArray4Ptr = myArray4ter.getPtr(); + + elemno = 0; + for (int j=1; j <= mdim; j++) + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray4ter.getNbGauss(i); k++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4ter.getIJK(i,j,k), array4Ref[elemno], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4Ptr[elemno], array4Ref[elemno], EPS ); + elemno++; + } + + { + MEDMEM_Array<double,NoInterlaceGaussPolicy> myArray4qua (mdim,nbelem2,nbtypegeo,nbelgeoc,nbgaussgeo); + myArray4Ptr = myArray4qua.getPtr(); + + for (int j = 1; j <= mdim; j++) { + int k = (myArray4qua.getArraySize() / mdim) * (j - 1); + CPPUNIT_ASSERT_NO_THROW(myArray4qua.setColumn(j, &array4Ref[k])); + } + + for (int i =0; i < myArray4qua.getArraySize(); i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4Ptr[i], array4Ref[i], EPS ); + } + + { + MEDMEM_Array<double,FullInterlaceGaussPolicy> * myArray4cin = ArrayConvert(myArray4); + myArray4Ptr = myArray4cin->getPtr(); + elemno = 0; + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray4cin->getNbGauss(i); k++) + for (int j=1; j <= mdim; j++) { + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4cin->getIJK(i,j,k), array3Ref[elemno], EPS ); + CPPUNIT_ASSERT( myArray4cin->getIJK(i,j,k) == myArray3.getIJK(i,j,k) ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( myArray4Ptr[elemno], array3Ref[elemno], EPS ); + elemno++; + } + delete myArray4cin; + } + + CPPUNIT_ASSERT(myArray4bis.getInterlacingType() != MED_UNDEFINED_INTERLACE); + + CPPUNIT_ASSERT_THROW(myArray4.getIJ(0,2), MEDEXCEPTION); + + ostringstream os; + //test operator<<(ostream & os, const MEDMEM_Array & array) + os << myArray4; + CPPUNIT_ASSERT(os.str() != ""); + + const int * myArray5Ptr = 0; + //test MEDMEM_Array(ElementType * values, int dim, int nbelem, int nbtypegeo, + // const int * const nbelgeoc, const int * const nbgaussgeo, + // bool shallowCopy=false, bool ownershipOfValues=false) + MEDMEM_Array<int, NoInterlaceGaussPolicy> myArray5 ((int*)array5Ref, mdim, nbelem2, + nbtypegeo, nbelgeoc, nbgaussgeo); + //test getGaussPresence + CPPUNIT_ASSERT( myArray5.getGaussPresence()); + + myArray5Ptr = myArray5.getPtr(); + for (int i =0; i < myArray5.getArraySize(); i++) { + CPPUNIT_ASSERT_EQUAL( myArray5Ptr[i], array5Ref[i]); + } + + //test MEDMEM_Array(const MEDMEM_Array & array, bool shallowCopy=false) + MEDMEM_Array<int,NoInterlaceGaussPolicy> myArray5bis(myArray5, false); + myArray5Ptr = myArray5bis.getPtr(); + + elemno = 0; + for (int j=1; j <= mdim; j++) + for (int i=1; i < nbelgeoc[nbtypegeo] ; i++ ) + for (int k=1; k <= myArray5bis.getNbGauss(i); k++) { + CPPUNIT_ASSERT_EQUAL( myArray5bis.getIJK(i,j,k), array5Ref[elemno] ); + CPPUNIT_ASSERT_EQUAL( myArray5Ptr[elemno], array5Ref[elemno] ); + elemno++; + } + + //MEDMEM_Array() + MEDMEM_Array<int,NoInterlaceGaussPolicy> myArray5ter; + //test setPtr(ElementType * values, bool shallowCopy=false, bool ownershipOfValues=false) + CPPUNIT_ASSERT_NO_THROW(myArray5.setPtr((int*)array5Ref)); + + //test getPtr() + myArray5Ptr = myArray5ter.getPtr(); + for (int i =0; i < myArray5ter.getArraySize(); i++) { + CPPUNIT_ASSERT_EQUAL( myArray5Ptr[i], array5Ref[i]); + } +} diff --git a/src/MEDMEM/Test/Makefile.am b/src/MEDMEM/Test/Makefile.am new file mode 100644 index 000000000..f8da5981f --- /dev/null +++ b/src/MEDMEM/Test/Makefile.am @@ -0,0 +1,116 @@ +# SALOMELocalTrace : log on local machine +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libMEDMEMTest.la + +salomeinclude_HEADERS = MEDMEMTest.hxx + +EXTRA_DIST += BasicMainTest.hxx + +dist_libMEDMEMTest_la_SOURCES= \ + MEDMEMTest.cxx \ + MEDMEMTest_Array.cxx \ + MEDMEMTest_AsciiFieldDriver.cxx \ + MEDMEMTest_Connectivity.cxx \ + MEDMEMTest_Coordinate.cxx \ + MEDMEMTest_DriverFactory.cxx \ + MEDMEMTest_Exception.cxx \ + MEDMEMTest_Family.cxx \ + MEDMEMTest_Field.cxx \ + MEDMEMTest_Formulae.cxx \ + MEDMEMTest_GaussLocalization.cxx \ + MEDMEMTest_GibiMeshDriver.cxx \ + MEDMEMTest_Grid.cxx \ + MEDMEMTest_Group.cxx \ + MEDMEMTest_Med.cxx \ + MEDMEMTest_MedFieldDriver21.cxx \ + MEDMEMTest_MedFieldDriver22.cxx \ + MEDMEMTest_MedMedDriver21.cxx \ + MEDMEMTest_MedMedDriver22.cxx \ + MEDMEMTest_MedMeshDriver21.cxx \ + MEDMEMTest_MedMeshDriver22.cxx \ + MEDMEMTest_MedVersion.cxx \ + MEDMEMTest_MeshAndMeshing.cxx \ + MEDMEMTest_ModulusArray.cxx \ + MEDMEMTest_nArray.cxx \ + MEDMEMTest_PointerOf.cxx \ + MEDMEMTest_PolyhedronArray.cxx \ + MEDMEMTest_PorflowMeshDriver.cxx \ + MEDMEMTest_SkyLineArray.cxx \ + MEDMEMTest_Support.cxx \ + MEDMEMTest_TopLevel.cxx \ + MEDMEMTest_Unit.cxx \ + MEDMEMTest_VtkFieldDriver.cxx \ + MEDMEMTest_VtkMedDriver.cxx \ + MEDMEMTest_VtkMeshDriver.cxx + +libMEDMEMTest_la_CPPFLAGS= @CPPUNIT_INCLUDES@ $(MED2_INCLUDES) $(HDF5_INCLUDES) \ + -I$(srcdir)/../../MEDMEM -I$(srcdir)/../../MEDWrapper/V2_1/Core +libMEDMEMTest_la_LDFLAGS= $(MED2_LIBS) @CPPUNIT_LIBS@ + +if MED_ENABLE_KERNEL + libMEDMEMTest_la_CPPFLAGS+= ${KERNEL_CXXFLAGS} + libMEDMEMTest_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace +endif + +# Executables targets +bin_PROGRAMS = TestMEDMEM \ + MEDMEMTest_Array_fault \ + MEDMEMTest_Connectivity_fault \ + MEDMEMTest_Coordinate_fault \ + MEDMEMTest_Family_fault \ + MEDMEMTest_Field_fault \ + MEDMEMTest_Grid_fault \ + MEDMEMTest_MedFieldDriver21_fault \ + MEDMEMTest_MedMedDriver21_fault \ + MEDMEMTest_MedMedDriver22_fault \ + MEDMEMTest_MeshAndMeshing_fault \ + MEDMEMTest_Support_fault \ + MEDMEMTest_VtkFieldDriver_fault \ + MEDMEMTest_VtkMeshDriver_fault + +dist_TestMEDMEM_SOURCES= TestMEDMEM.cxx +dist_MEDMEMTest_Array_fault_SOURCES= MEDMEMTest_Array_fault.cxx +dist_MEDMEMTest_Connectivity_fault_SOURCES= MEDMEMTest_Connectivity_fault.cxx +dist_MEDMEMTest_Coordinate_fault_SOURCES= MEDMEMTest_Coordinate_fault.cxx +dist_MEDMEMTest_Family_fault_SOURCES= MEDMEMTest_Family_fault.cxx +dist_MEDMEMTest_Field_fault_SOURCES= MEDMEMTest_Field_fault.cxx +dist_MEDMEMTest_Grid_fault_SOURCES= MEDMEMTest_Grid_fault.cxx +dist_MEDMEMTest_MedFieldDriver21_fault_SOURCES= MEDMEMTest_MedFieldDriver21_fault.cxx +dist_MEDMEMTest_MedMedDriver21_fault_SOURCES= MEDMEMTest_MedMedDriver21_fault.cxx +dist_MEDMEMTest_MedMedDriver22_fault_SOURCES= MEDMEMTest_MedMedDriver22_fault.cxx +dist_MEDMEMTest_MeshAndMeshing_fault_SOURCES= MEDMEMTest_MeshAndMeshing_fault.cxx +dist_MEDMEMTest_Support_fault_SOURCES= MEDMEMTest_Support_fault.cxx +dist_MEDMEMTest_VtkFieldDriver_fault_SOURCES= MEDMEMTest_VtkFieldDriver_fault.cxx +dist_MEDMEMTest_VtkMeshDriver_fault_SOURCES= MEDMEMTest_VtkMeshDriver_fault.cxx + +LDADD= $(MED2_LIBS) $(libMEDMEMTest_la_LDFLAGS) -lm \ + ../../MEDWrapper/V2_1/Core/libmed_V2_1.la ../libmedmem.la libMEDMEMTest.la +if MED_ENABLE_KERNEL + LDADD+= -lSALOMEBasics +endif +AM_CPPFLAGS= $(libMEDMEMTest_la_CPPFLAGS) + +salomescript_DATA = testMEDMEM.py +UNIT_TEST_PROG = TestMEDMEM diff --git a/src/MEDMEM/Test/TestMEDMEM.cxx b/src/MEDMEM/Test/TestMEDMEM.cxx new file mode 100644 index 000000000..43c056ece --- /dev/null +++ b/src/MEDMEM/Test/TestMEDMEM.cxx @@ -0,0 +1,31 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// --- include all MEDMEM Test + +#include "MEDMEMTest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( MEDMEMTest ); + +// --- generic Main program from KERNEL_SRC/src/Basics/Test + +#include "BasicMainTest.hxx" diff --git a/src/MEDMEM/Test/testMEDMEM.py b/src/MEDMEM/Test/testMEDMEM.py new file mode 100644 index 000000000..c576cf3d3 --- /dev/null +++ b/src/MEDMEM/Test/testMEDMEM.py @@ -0,0 +1,89 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import sys, os,signal,string,commands +###import runSalome +###import orbmodule +###import TestKiller + +# get SALOME environment : + +###args, modules_list, modules_root_dir = runSalome.get_config() +###runSalome.set_env(args, modules_list, modules_root_dir) + +# launch CORBA naming server + +###clt=orbmodule.client() + +# launch CORBA logger server + +###myServer=runSalome.LoggerServer(args) +###myServer.run() +###clt.waitLogger("Logger") + +# execute Unit Test + +command = ['TestMEDMEM'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +print "MEDMEM General testing done." +print "Run cases, which leads to Segmentation Fault ..." + +command = ['MEDMEMTest_Array_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_Connectivity_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_Coordinate_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_Family_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_Field_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_Grid_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_MedFieldDriver21_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_MedMedDriver21_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_MedMedDriver22_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_MeshAndMeshing_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_Support_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_VtkFieldDriver_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +command = ['MEDMEMTest_VtkMeshDriver_fault'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill Test process + +###TestKiller.killProcess(runSalome.process_id) diff --git a/src/MEDMEM/ensight2med.cxx b/src/MEDMEM/ensight2med.cxx new file mode 100644 index 000000000..7d5aaf03c --- /dev/null +++ b/src/MEDMEM/ensight2med.cxx @@ -0,0 +1,64 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include<string> +#include<deque> + +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_define.hxx" + +#include "MEDMEM_Med.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_EnsightMedDriver.hxx" + +using namespace std; +using namespace MEDMEM; +void usage(char * name) +{ + cout << " ERROR ABOUT SYNTAX " << endl ; + cout << " " << name << " <input ensight file> <output med file> " << endl ; + exit(-1); +} + +// ensight2med toto.case toto.med => input : toto.case => output : toto.med.... + +int main (int argc, char ** argv) { + + string filenameIN ; + string filenameOUT; + + if ( argc == 3 ) { + filenameIN = argv[1] ; + filenameOUT = argv[2] ; + cout << " reading all into the Ensight file " << filenameIN << " and writing all into the Med file " << filenameOUT << endl ; + + MED myMed(ENSIGHT_DRIVER,filenameIN) ; + myMed.read() ; + + int id = myMed.addDriver(MED_DRIVER,filenameOUT); + myMed.write(id); + } + else usage(argv[0]); + +} + + diff --git a/src/MEDMEM/med2_1_To_med2_2.cxx b/src/MEDMEM/med2_1_To_med2_2.cxx index af5fd58f1..ee3dda992 100644 --- a/src/MEDMEM/med2_1_To_med2_2.cxx +++ b/src/MEDMEM/med2_1_To_med2_2.cxx @@ -30,16 +30,16 @@ int main (int argc, char ** argv) cerr << "Usage : " << argv[0] << " fileNameIn" << endl ; cerr << "Where - fileNameIn is .med V2.1 file supplied by the user including all the directory path" << endl; - cerr << "fileNameOut is .med V2.2 file produced by this command in the directory $HOME/TMP_Med2_2Files/" << endl; + cerr << "fileNameOut is .med V2.3.2 file produced by this command in the directory $HOME/TMP_Med2_3Files/" << endl; cerr << "This command is supposed to be the same as the med File V2.2 medimport utility" << endl << endl; - cerr << "It will produce a med V2.2 file fileNameOut which will be in the directory $HOME/TMP_Med2_2Files/" << endl; + cerr << "It will produce a med V2.3.2 file fileNameOut which will be in the directory $HOME/TMP_Med2_3Files/" << endl; cerr << "with the same root name as fileNameIn: " << endl; - cerr << "If fileNameIn is /aPath/file.med so fileNameOut will be $HOME/TMP_Med2_2Files/file.med" << endl; + cerr << "If fileNameIn is /aPath/file.med so fileNameOut will be $HOME/TMP_Med2_3Files/file.med" << endl; exit(-1); } string fileNameIn = argv[1] ; - char * fileNameOut = med2_1_To_med2_2((const_cast <char *> + char * fileNameOut = med2_1_To_med2_3((const_cast <char *> (fileNameIn.c_str()))); if (fileNameOut == ((char *) NULL)) @@ -52,7 +52,7 @@ int main (int argc, char ** argv) } else { - cerr << "No nedd to converte because the file is al ready a med 2.2 file" << endl; + cerr << "No nedd to converte because the file is al ready a med 2.3.2 file" << endl; } return 0; diff --git a/src/MEDMEM/med2ensight.cxx b/src/MEDMEM/med2ensight.cxx new file mode 100644 index 000000000..28a5a9a40 --- /dev/null +++ b/src/MEDMEM/med2ensight.cxx @@ -0,0 +1,86 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include<string> +#include<deque> + +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_define.hxx" + +#include "MEDMEM_Med.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Support.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_EnsightMedDriver.hxx" + +using namespace std; +using namespace MEDMEM; + +void usage(char * name) +{ + cout << " ERROR ABOUT SYNTAX " << endl ; + cout << " " << name << " <input med file> <output ensight file> " << endl ; + exit(-1); +} + +int main (int argc, char ** argv) { + + string filenameIN ; + string filenameOUT; + + if ( argc == 3 ) { + filenameIN = argv[1] ; + filenameOUT = argv[2] ; + cout << "-> reading all into the Med file " << filenameIN << " and writing all into the Ensight file " << filenameOUT << endl ; + + MED myMed(MED_DRIVER,filenameIN) ; + + cout << "-> Read all meshes " ; + int NumberOfMeshes = myMed.getNumberOfMeshes() ; + cout << "( "<<NumberOfMeshes << " ) :" << endl ; + deque<string> MeshName = myMed.getMeshNames() ; + for (int i=0; i<NumberOfMeshes; i++) { + myMed.getMesh(MeshName[i])->read() ; + cout << "-> Mesh "<<i+1<<", named "<<MeshName[i]<<" is read !" << endl; + } + + myMed.updateSupport() ; + + cout << "-> Read all fields " ; + int NumberOfFields = myMed.getNumberOfFields() ; + cout << "( "<<NumberOfFields << " ) :" << endl; + deque<string> FieldName = myMed.getFieldNames() ; + for (int i=0; i<NumberOfFields; i++) { + deque<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ; + cout << "-> Field "<<i+1<<", named "<<FieldName[i] << " :" << endl ; + int NumberOfIteration = FieldIteration.size() ; + cout << " Number of iteration pair : "<< NumberOfIteration << endl; + for (int j=0; j<NumberOfIteration; j++) { + FIELD_ * myField = myMed.getField(FieldName[i],FieldIteration[j].dt,FieldIteration[j].it) ; + + myField->read() ; + cout << " * Iteration "<<FieldIteration[j].dt<<" and order number "<<FieldIteration[j].it<<" ) is read !" << endl; + } + } + int id = myMed.addDriver(ENSIGHT_DRIVER,filenameOUT,MED_EN::MED_ECRI) ; + myMed.write(id) ; + } + else usage(argv[0]); +} diff --git a/src/MEDMEM/test_MEDMEM_Meshing.cxx b/src/MEDMEM/test_MEDMEM_Meshing.cxx index 11818a084..41dfc0457 100644 --- a/src/MEDMEM/test_MEDMEM_Meshing.cxx +++ b/src/MEDMEM/test_MEDMEM_Meshing.cxx @@ -17,6 +17,10 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + +//#define protected public +//#define private public + #include "MEDMEM_Meshing.hxx" #include "MEDMEM_Group.hxx" #include "MEDMEM_Field.hxx" @@ -28,7 +32,7 @@ using namespace DRIVERFACTORY; int main (int argc, char ** argv) { - if (argc <2) { + if (argc >2) { cerr << "Usage : " << argv[0] << " filenameRoot" << endl; cerr << " where filenameRoot is a root filename, the program will produce" << endl; @@ -36,9 +40,13 @@ int main (int argc, char ** argv) { exit(-1); } - // filename to save the generated MESH - string filenameRoot = argv[1] ; - + string filenameRoot; + if (argc==1) + // filename to save the generated MESH + filenameRoot = "/tmp/test_MEDMEM_Meshing" ; + else + filenameRoot=argv[1]; + string filenameMed21 = filenameRoot+"_V21.med"; string filenameMed22 = filenameRoot+"_V22.med"; string filenameVtk = filenameRoot+".vtk"; @@ -168,139 +176,141 @@ int main (int argc, char ** argv) { // Some groups : // Node : + + GROUP partialGroupOnNodes ; { - GROUP myGroup ; - myGroup.setName("SomeNodes"); - myGroup.setMesh(&myMeshing); - myGroup.setEntity(MED_NODE); - myGroup.setNumberOfGeometricType(1); - medGeometryElement myTypes[1] = {MED_NONE}; - myGroup.setGeometricType(myTypes); - const int myNumberOfElements[1] = {4} ; - myGroup.setNumberOfElements(myNumberOfElements); - const int index[1+1] = {1,5} ; - const int value[4]= { 1,4,5,7} ; - myGroup.setNumber(index,value); - - myMeshing.addGroup(myGroup); - } + partialGroupOnNodes.setName("SomeNodes"); + partialGroupOnNodes.setMesh(&myMeshing); + partialGroupOnNodes.setEntity(MED_NODE); + partialGroupOnNodes.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_NONE}; + partialGroupOnNodes.setGeometricType(myTypes); + const int myNumberOfElements[1] = {4} ; + partialGroupOnNodes.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,5} ; + const int value[4]= { 1,4,5,7} ; + partialGroupOnNodes.setNumber(index,value); + } + myMeshing.addGroup(partialGroupOnNodes); + + + GROUP partialGroupOnNodes2 ; { - GROUP myGroup ; - myGroup.setName("OtherNodes"); - myGroup.setMesh(&myMeshing); - myGroup.setEntity(MED_NODE); - myGroup.setNumberOfGeometricType(1); - medGeometryElement myTypes[1] = {MED_NONE}; - myGroup.setGeometricType(myTypes); - const int myNumberOfElements[1] = {3} ; - myGroup.setNumberOfElements(myNumberOfElements); - const int index[1+1] = {1,4} ; - const int value[3]= { 2,3,6} ; - myGroup.setNumber(index,value); - - myMeshing.addGroup(myGroup); + partialGroupOnNodes2.setName("OtherNodes"); + partialGroupOnNodes2.setMesh(&myMeshing); + partialGroupOnNodes2.setEntity(MED_NODE); + partialGroupOnNodes2.setNumberOfGeometricType(1); + medGeometryElement myTypes[1] = {MED_NONE}; + partialGroupOnNodes2.setGeometricType(myTypes); + const int myNumberOfElements[1] = {3} ; + partialGroupOnNodes2.setNumberOfElements(myNumberOfElements); + const int index[1+1] = {1,4} ; + const int value[3]= { 2,3,6} ; + partialGroupOnNodes2.setNumber(index,value); } + myMeshing.addGroup(partialGroupOnNodes2); + // Cell : + + GROUP partialGroupOnCells ; { - GROUP myGroup ; - myGroup.setName("SomeCells"); - myGroup.setMesh(&myMeshing); - myGroup.setEntity(MED_CELL); - myGroup.setNumberOfGeometricType(3); - medGeometryElement myTypes[3] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; - myGroup.setGeometricType(myTypes); - const int myNumberOfElements[3] = {4,1,2} ; - myGroup.setNumberOfElements(myNumberOfElements); - const int index[3+1] = {1,5,6,8} ; - const int value[4+1+2]= + partialGroupOnCells.setName("SomeCells"); + partialGroupOnCells.setMesh(&myMeshing); + partialGroupOnCells.setEntity(MED_CELL); + partialGroupOnCells.setNumberOfGeometricType(3); + medGeometryElement myTypes[3] = {MED_TETRA4,MED_PYRA5,MED_HEXA8}; + partialGroupOnCells.setGeometricType(myTypes); + const int myNumberOfElements[3] = {4,1,2} ; + partialGroupOnCells.setNumberOfElements(myNumberOfElements); + const int index[3+1] = {1,5,6,8} ; + const int value[4+1+2]= { 2,7,8,12, 13, 15,16 }; - myGroup.setNumber(index,value); - - myMeshing.addGroup(myGroup); + partialGroupOnCells.setNumber(index,value); } - { - GROUP myGroup ; - myGroup.setName("OtherCells"); - myGroup.setMesh(&myMeshing); - myGroup.setEntity(MED_CELL); - myGroup.setNumberOfGeometricType(2); + myMeshing.addGroup(partialGroupOnCells); + + + GROUP partialGroupOnCells2 ; + { + partialGroupOnCells2.setName("OtherCells"); + partialGroupOnCells2.setMesh(&myMeshing); + partialGroupOnCells2.setEntity(MED_CELL); + partialGroupOnCells2.setNumberOfGeometricType(2); medGeometryElement myTypes[] = {MED_TETRA4,MED_PYRA5}; - myGroup.setGeometricType(myTypes); + partialGroupOnCells2.setGeometricType(myTypes); const int myNumberOfElements[] = {4,1} ; - myGroup.setNumberOfElements(myNumberOfElements); + partialGroupOnCells2.setNumberOfElements(myNumberOfElements); const int index[2+1] = {1,5,6} ; const int value[4+1]= { 3,4,5,9, 14 }; - myGroup.setNumber(index,value); - - myMeshing.addGroup(myGroup); - } + partialGroupOnCells2.setNumber(index,value); + } + myMeshing.addGroup(partialGroupOnCells2); + // Face : - { - GROUP myGroup ; - myGroup.setName("SomeFaces"); - myGroup.setMesh(&myMeshing); - myGroup.setEntity(MED_FACE); - myGroup.setNumberOfGeometricType(2); + + GROUP partialGroupOnFaces ; + { + partialGroupOnFaces.setName("SomeFaces"); + partialGroupOnFaces.setMesh(&myMeshing); + partialGroupOnFaces.setEntity(MED_FACE); + partialGroupOnFaces.setNumberOfGeometricType(2); medGeometryElement myTypes[2] = {MED_TRIA3,MED_QUAD4}; - myGroup.setGeometricType(myTypes); + partialGroupOnFaces.setGeometricType(myTypes); const int myNumberOfElements[2] = {2,3} ; - myGroup.setNumberOfElements(myNumberOfElements); + partialGroupOnFaces.setNumberOfElements(myNumberOfElements); const int index[2+1] = {1,3,6} ; const int value[2+3]= { 2,4, 5,6,8 } ; - myGroup.setNumber(index,value); - - myMeshing.addGroup(myGroup); - } - { - GROUP myGroup ; - myGroup.setName("OtherFaces"); - myGroup.setMesh(&myMeshing); - myGroup.setEntity(MED_FACE); - myGroup.setNumberOfGeometricType(1); - medGeometryElement myTypes[1] = {MED_TRIA3}; - myGroup.setGeometricType(myTypes); - const int myNumberOfElements[1] = {2} ; - myGroup.setNumberOfElements(myNumberOfElements); - const int index[1+1] = {1,3} ; - const int value[2]= - { - 1,3 - } ; - myGroup.setNumber(index,value); - - myMeshing.addGroup(myGroup); - } + partialGroupOnFaces.setNumber(index,value); + } + myMeshing.addGroup(partialGroupOnFaces); + + + GROUP partialGroupOnFaces2 ; + { + partialGroupOnFaces2.setName("OtherFaces"); + partialGroupOnFaces2.setMesh(&myMeshing); + partialGroupOnFaces2.setEntity(MED_FACE); + medGeometryElement myTypes[1] = {MED_TRIA3}; + int myNumberOfElements[1] = {2} ; + int value[2]= + { + 1,3 + } ; + // partialGroupOnFaces2.setNumber(index,value); + partialGroupOnFaces2.setpartial("description",1,2,myTypes,myNumberOfElements,value); + } + myMeshing.addGroup(partialGroupOnFaces2); - // all rigtht, we save it in Med 2.1 2.2 and vtk ! + // all right, we save it in Med 2.1 2.2 and vtk ! medFileVersion version = getMedFileVersionForWriting(); - if (version == V22) - setMedFileVersionForWriting(V21); - - int idMed21 = myMeshing.addDriver(MED_DRIVER,filenameMed21,myMeshing.getName()); - myMeshing.write(idMed21) ; - - version = getMedFileVersionForWriting(); if (version == V21) setMedFileVersionForWriting(V22); int idMed22 = myMeshing.addDriver(MED_DRIVER,filenameMed22,myMeshing.getName()); myMeshing.write(idMed22) ; + version = getMedFileVersionForWriting(); + if (version == V22) + setMedFileVersionForWriting(V21); + + int idMed21 = myMeshing.addDriver(MED_DRIVER,filenameMed21,myMeshing.getName()); + myMeshing.write(idMed21) ; + int idVtk = myMeshing.addDriver(VTK_DRIVER,filenameVtk,myMeshing.getName()); myMeshing.write(idVtk) ; @@ -324,6 +334,16 @@ int main (int argc, char ** argv) { fieldDoubleScalarOnNodes->setComponentDescription(1,"comp1"); fieldDoubleScalarOnNodes->setMEDComponentUnit(1,"unit1"); + FIELD<double>* fieldDoubleScalarOnPartialNodes = new FIELD<double>(&partialGroupOnNodes,1); + fieldDoubleScalarOnPartialNodes->setName("fieldScalarDoublePartialNodes"); + fieldDoubleScalarOnPartialNodes->setIterationNumber(-1); + fieldDoubleScalarOnPartialNodes->setOrderNumber(-1); + fieldDoubleScalarOnPartialNodes->setTime(0.0); + fieldDoubleScalarOnPartialNodes->setComponentName(1,"Vx"); + fieldDoubleScalarOnPartialNodes->setComponentDescription(1,"comp1"); + fieldDoubleScalarOnPartialNodes->setMEDComponentUnit(1,"unit1"); + + FIELD<double> * fieldDoubleVectorOnNodes = new FIELD<double>(supportOnNodes,SpaceDimension); fieldDoubleVectorOnNodes->setName("fieldVectorDoubleNode"); fieldDoubleVectorOnNodes->setIterationNumber(-1); @@ -350,6 +370,41 @@ int main (int argc, char ** argv) { fieldDoubleScalarOnCells->setComponentDescription(1,"comp1"); fieldDoubleScalarOnCells->setMEDComponentUnit(1,"unit1"); + + FIELD<double> * fieldDoubleScalarOnPartialCells = new FIELD<double>(&partialGroupOnCells,1); + fieldDoubleScalarOnPartialCells->setName("fieldScalarDoublePartialCell"); + fieldDoubleScalarOnPartialCells->setIterationNumber(-1); + fieldDoubleScalarOnPartialCells->setOrderNumber(-1); + fieldDoubleScalarOnPartialCells->setTime(0.0); + + fieldDoubleScalarOnPartialCells->setComponentName(1,"Vx"); + fieldDoubleScalarOnPartialCells->setComponentDescription(1,"comp1"); + fieldDoubleScalarOnPartialCells->setMEDComponentUnit(1,"unit1"); + + FIELD<double> * fieldDoubleScalarOnPartialFaces = new FIELD<double>(&partialGroupOnFaces,1); + fieldDoubleScalarOnPartialFaces->setName("fieldScalarDoublePartialFace"); + fieldDoubleScalarOnPartialFaces->setIterationNumber(-1); + fieldDoubleScalarOnPartialFaces->setOrderNumber(-1); + fieldDoubleScalarOnPartialFaces->setTime(0.0); + fieldDoubleScalarOnPartialFaces->setComponentName(1,"Vx"); + fieldDoubleScalarOnPartialFaces->setComponentDescription(1,"comp1"); + fieldDoubleScalarOnPartialFaces->setMEDComponentUnit(1,"unit1"); + + FIELD<double> * fieldDoubleVectorOnPartialFaces = new FIELD<double>(&partialGroupOnFaces2,2); + fieldDoubleVectorOnPartialFaces->setName("fieldVectorDoublePartialFace"); + fieldDoubleVectorOnPartialFaces->setIterationNumber(-1); + fieldDoubleVectorOnPartialFaces->setOrderNumber(-1); + fieldDoubleVectorOnPartialFaces->setTime(0.0); + fieldDoubleVectorOnPartialFaces->setComponentName(1,"Vx"); + fieldDoubleVectorOnPartialFaces->setComponentName(2,"Vy"); + + fieldDoubleVectorOnPartialFaces->setComponentDescription(1,"comp1"); + fieldDoubleVectorOnPartialFaces->setComponentDescription(2,"comp2"); + + fieldDoubleVectorOnPartialFaces->setMEDComponentUnit(1,"unit1"); + fieldDoubleVectorOnPartialFaces->setMEDComponentUnit(2,"unit2"); + + FIELD<double> * fieldDoubleVectorOnCells = new FIELD<double>(supportOnCells,SpaceDimension); fieldDoubleVectorOnCells->setName("fieldVectorrDoubleCell"); fieldDoubleVectorOnCells->setIterationNumber(-1); @@ -464,6 +519,31 @@ int main (int argc, char ** argv) { fieldIntVectorOnCells->setValueIJ(i+1,3,valueInt3); } + for (int i=0; i<partialGroupOnNodes.getNumberOfElements(MED_ALL_ELEMENTS); i++) + { + const int* number=partialGroupOnNodes.getNumber(MED_ALL_ELEMENTS); + fieldDoubleScalarOnPartialNodes->setValueIJ(number[i],1,i+1); + } + + for (int i=0; i<partialGroupOnCells.getNumberOfElements(MED_ALL_ELEMENTS); i++) + { + const int* number=partialGroupOnCells.getNumber(MED_ALL_ELEMENTS); + fieldDoubleScalarOnPartialCells->setValueIJ(number[i],1,i+1); + } + + for (int i=0; i<partialGroupOnFaces.getNumberOfElements(MED_ALL_ELEMENTS); i++) + { + const int* number=partialGroupOnFaces.getNumber(MED_ALL_ELEMENTS); + fieldDoubleScalarOnPartialFaces->setValueIJ(number[i],1,i+1); + } + + for (int i=0; i<partialGroupOnFaces2.getNumberOfElements(MED_ALL_ELEMENTS); i++) + { + const int* number=partialGroupOnFaces2.getNumber(MED_ALL_ELEMENTS); + fieldDoubleVectorOnPartialFaces->setValueIJ(number[i],1,i+1); + fieldDoubleVectorOnPartialFaces->setValueIJ(number[i],2,-i-1); + } + version = getMedFileVersionForWriting(); if (version == V22) setMedFileVersionForWriting(V21); @@ -492,6 +572,7 @@ int main (int argc, char ** argv) { idMed21 = fieldIntVectorOnCells->addDriver(MED_DRIVER,filenameMed21,fieldIntVectorOnCells->getName()); fieldIntVectorOnCells->write(idMed21) ; + version = getMedFileVersionForWriting(); if (version == V21) setMedFileVersionForWriting(V22); @@ -520,6 +601,19 @@ int main (int argc, char ** argv) { idMed22 = fieldIntVectorOnCells->addDriver(MED_DRIVER,filenameMed22,fieldIntVectorOnCells->getName()); fieldIntVectorOnCells->write(idMed22) ; + idMed22 = fieldDoubleScalarOnPartialNodes->addDriver(MED_DRIVER,filenameMed22,fieldDoubleScalarOnPartialNodes->getName()); + fieldDoubleScalarOnPartialNodes->write(idMed22) ; + + idMed22 = fieldDoubleScalarOnPartialCells->addDriver(MED_DRIVER,filenameMed22,fieldDoubleScalarOnPartialCells->getName()); + fieldDoubleScalarOnPartialCells->write(idMed22) ; + + idMed22 = fieldDoubleScalarOnPartialFaces->addDriver(MED_DRIVER,filenameMed22,fieldDoubleScalarOnPartialFaces->getName()); + fieldDoubleScalarOnPartialFaces->write(idMed22) ; + + idMed22 = fieldDoubleVectorOnPartialFaces->addDriver(MED_DRIVER,filenameMed22,fieldDoubleVectorOnPartialFaces->getName()); + fieldDoubleVectorOnPartialFaces->write(idMed22) ; + + idVtk = fieldDoubleScalarOnNodes->addDriver(VTK_DRIVER,filenameVtk,fieldDoubleScalarOnNodes->getName()); fieldDoubleScalarOnNodes->writeAppend(idVtk) ; @@ -544,6 +638,7 @@ int main (int argc, char ** argv) { idVtk = fieldIntVectorOnCells->addDriver(VTK_DRIVER,filenameVtk,fieldIntVectorOnCells->getName()); fieldIntVectorOnCells->writeAppend(idVtk) ; + delete fieldDoubleScalarOnNodes; delete fieldIntScalarOnNodes; delete fieldDoubleVectorOnNodes; @@ -552,6 +647,10 @@ int main (int argc, char ** argv) { delete fieldIntScalarOnCells; delete fieldDoubleVectorOnCells; delete fieldIntVectorOnCells; + delete fieldDoubleScalarOnPartialCells; + delete fieldDoubleScalarOnPartialNodes; + delete fieldDoubleScalarOnPartialFaces; + delete fieldDoubleVectorOnPartialFaces; delete supportOnNodes; delete supportOnCells; diff --git a/src/MEDMEM/test_MEDMEM_MeshingFlica.cxx b/src/MEDMEM/test_MEDMEM_MeshingFlica.cxx index 143a1eb99..353890df3 100644 --- a/src/MEDMEM/test_MEDMEM_MeshingFlica.cxx +++ b/src/MEDMEM/test_MEDMEM_MeshingFlica.cxx @@ -193,9 +193,8 @@ int main() addMedFacesGroup( *meshing, 4, top, "TopFaces",topTypes,topIndex,topNbOfElts,2) ; addMedFacesGroup( *meshing, 24, side, "SideFaces",sideTypes,sideIndex,sideNbOfElts,2) ; //writing... - int id=meshing->addDriver(MED_DRIVER,"totoFlica_V22.med"); + int id=meshing->addDriver(MED_DRIVER,"/tmp/totoFlica_V22.med"); meshing->write(id); delete meshing; return 0; } - diff --git a/src/MEDMEM/test_MEDMEM_MeshingPoly.cxx b/src/MEDMEM/test_MEDMEM_MeshingPoly.cxx index 36b39284b..fab4bf668 100644 --- a/src/MEDMEM/test_MEDMEM_MeshingPoly.cxx +++ b/src/MEDMEM/test_MEDMEM_MeshingPoly.cxx @@ -167,8 +167,8 @@ int main (int argc, char ** argv) { for(i=0;i<4;i++) if(fabs(REFAreaOfPolyg[i]-vals2[i])<1e-12) nbPts++; - delete sup2; delete areas; + delete sup2; SUPPORT *sup = new SUPPORT(&myMeshing); FIELD<double> *vols = myMeshing.getVolume(sup); diff --git a/src/MEDMEM/test_MEDMEM_Meshing_poly.cxx b/src/MEDMEM/test_MEDMEM_Meshing_poly.cxx index 7bf70645b..155a5cb9d 100644 --- a/src/MEDMEM/test_MEDMEM_Meshing_poly.cxx +++ b/src/MEDMEM/test_MEDMEM_Meshing_poly.cxx @@ -28,7 +28,7 @@ using namespace DRIVERFACTORY; int main (int argc, char ** argv) { // Traitement arguments - if (argc != 2) + if (argc > 2) { cerr << "Usage : " << argv[0] << " filenameRoot" << endl << endl @@ -36,7 +36,11 @@ int main (int argc, char ** argv) exit(-1); } - string filenameRoot = argv[1] ; + string filenameRoot; + if (argc==2) + filenameRoot= argv[1] ; + else + filenameRoot="/tmp/testMeshingPoly"; string medfilename = filenameRoot + "22.med"; diff --git a/src/MEDMEM/test_MEDMEM_poly3D.cxx b/src/MEDMEM/test_MEDMEM_poly3D.cxx index 9472e2c4b..4d79c118e 100755 --- a/src/MEDMEM/test_MEDMEM_poly3D.cxx +++ b/src/MEDMEM/test_MEDMEM_poly3D.cxx @@ -103,7 +103,7 @@ int main (int argc, char ** argv) { if (argc<2) // after 2, ignored ! { - cerr << "Usage : " << argv[0] << " poly3D.med typically in ../../share/salome/resources" << endl << endl; + cerr << "Usage : " << argv[0] << " poly3D.med typically in ../../share/salome/resources/med" << endl << endl; exit(-1); } int nbOfPtsForTest=0; diff --git a/src/MEDMEM/test_profil_MedFieldDriver.cxx b/src/MEDMEM/test_profil_MedFieldDriver.cxx index efe008f1b..618cf1bf7 100644 --- a/src/MEDMEM/test_profil_MedFieldDriver.cxx +++ b/src/MEDMEM/test_profil_MedFieldDriver.cxx @@ -210,18 +210,18 @@ int main (int argc, char ** argv) { // les types gĂ©omĂ©triques du MESH ce qui n'est pas forcĂ©ment le cas d'un champ MEDFICHIER // (mĂªme sans profil) lu Ă  posteriori. { - med_2_2::med_err err=-1; - med_2_2::med_idt id = med_2_2::MEDouvrir(const_cast<char *> ( ("Copy_nomesh_"+fileName).c_str()), - med_2_2::MED_LECTURE_ECRITURE); + med_2_3::med_err err=-1; + med_2_3::med_idt id = med_2_3::MEDouvrir(const_cast<char *> ( ("Copy_nomesh_"+fileName).c_str()), + med_2_3::MED_LECTURE_ECRITURE); if (id <=0) cout << "Erreur dans MEDouvrir pour le fichier " << "Copy_nomesh_"+fileName <<endl; - err=med_2_2::MEDlienEcr(id, const_cast<char *> ( ("Copy_withmesh_"+fileName).c_str()), + err=med_2_3::MEDlienEcr(id, const_cast<char *> ( ("Copy_withmesh_"+fileName).c_str()), const_cast<char *> (meshName.c_str()) ); if (err !=0) cout << "Erreur dans MEDlienEcr pour le maillage distant " << meshName <<" contenu dans le fichier " << "Copy_withmesh_"+fileName <<endl; - err=med_2_2::MEDfermer(id); + err=med_2_3::MEDfermer(id); MESH * myMesh3 = new MESH(MED_DRIVER,fileName,meshName); const SUPPORT * mySupport3= new SUPPORT(myMesh3,"Temporary Support",MED_CELL); diff --git a/src/MEDMEM/test_profil_gauss_MedFieldDriver.cxx b/src/MEDMEM/test_profil_gauss_MedFieldDriver.cxx index e3a181e0b..fc030688a 100644 --- a/src/MEDMEM/test_profil_gauss_MedFieldDriver.cxx +++ b/src/MEDMEM/test_profil_gauss_MedFieldDriver.cxx @@ -417,18 +417,18 @@ int main (int argc, char ** argv) { // les types gĂ©omĂ©triques du MESH ce qui n'est pas forcĂ©ment le cas d'un champ MEDFICHIER // (mĂªme sans profil) lu Ă  posteriori. { - med_2_2::med_err err=-1; - med_2_2::med_idt id = med_2_2::MEDouvrir(const_cast<char *> ( ("Copy_nomesh_"+fileName).c_str()), - med_2_2::MED_LECTURE_ECRITURE); + med_2_3::med_err err=-1; + med_2_3::med_idt id = med_2_3::MEDouvrir(const_cast<char *> ( ("Copy_nomesh_"+fileName).c_str()), + med_2_3::MED_LECTURE_ECRITURE); if (id <=0) cout << "Erreur dans MEDouvrir pour le fichier " << "Copy_nomesh_"+fileName <<endl; - err=med_2_2::MEDlienEcr(id, const_cast<char *> ( ("Copy_withmesh_"+fileName).c_str()), + err=med_2_3::MEDlienEcr(id, const_cast<char *> ( ("Copy_withmesh_"+fileName).c_str()), const_cast<char *> (meshName.c_str()) ); if (err !=0) cout << "Erreur dans MEDlienEcr pour le maillage distant " << meshName <<" contenu dans le fichier " << "Copy_withmesh_"+fileName <<endl; - err=med_2_2::MEDfermer(id); + err=med_2_3::MEDfermer(id); MESH * myMesh3 = new MESH(MED_DRIVER,fileName,meshName); const SUPPORT * mySupport3= new SUPPORT(myMesh3,"Temporary Support",MED_CELL); diff --git a/src/MEDMEM/test_write_groups_poly.cxx b/src/MEDMEM/test_write_groups_poly.cxx new file mode 100644 index 000000000..5e97c0ab6 --- /dev/null +++ b/src/MEDMEM/test_write_groups_poly.cxx @@ -0,0 +1,146 @@ +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_Group.hxx" + +using namespace std; +using namespace MEDMEM; +using namespace MED_EN; + +void addMedFacesGroup (MESHING& meshing, int nFaces, int *groupValue, string groupName) +{ + GROUP faces; + int myNumberOfElements[1]; + medGeometryElement mytypes[1]; + int index[2]; + faces.setName(groupName); + faces.setMesh(&meshing); + faces.setEntity(MED_EN::MED_FACE); + faces.setNumberOfGeometricType(1); + mytypes[0] = MED_EN::MED_POLYGON; + faces.setGeometricType(mytypes); + myNumberOfElements[0] = nFaces; + faces.setNumberOfElements(myNumberOfElements); + index[0] = 1; + index[1] = nFaces; + faces.setNumber(index, groupValue); + meshing.addGroup(faces); +} + +int main() +{ + MESHING *pmesh = new MESHING; + pmesh->setName( "C2MESH" ); + pmesh->setSpaceDimension(3); + pmesh->setNumberOfTypes(0, MED_EN::MED_CELL); + pmesh->setMeshDimension(3); + int nb_hexagone = 7; + int nbmailles_axiales = 2; + int nNodes = 6 * nb_hexagone * nbmailles_axiales; + // int nNodes=*max_element (connec, connec+6*nb_hexagone*nbmailles_axiales); + pmesh->setNumberOfNodes(nNodes); + + double coord[] = { + 44.401823743922364, 0 , 0, 55.698259110886582, 6.5220000000000002, 0, + 55.698259110886582, 19.566000000000003, 0, 44.401823743922364, 26.088000000000001, 0, + 33.105388376958146, 19.566000000000003, 0, 33.105388376958146, 6.5220000000000002, 0, + 66.9946944778508 , 0 , 0, 78.291129844815018, 6.5220000000000002, 0, + 78.291129844815018, 19.566000000000003, 0, 66.9946944778508 , 26.088000000000001, 0, + 55.698259110886582, 19.566000000000003, 0, 55.698259110886582, 6.5220000000000002, 0, + 33.105388376958146, 19.565999999999999, 0, 44.401823743922364, 26.088000000000001, 0, + 44.401823743922364, 39.131999999999998, 0, 33.105388376958146, 45.653999999999996, 0, + 21.808953009993928, 39.131999999999998, 0, 21.808953009993928, 26.088000000000001, 0, + 55.698259110886582, 19.565999999999999, 0, 66.9946944778508 , 26.088000000000001, 0, + 66.9946944778508 , 39.131999999999998, 0, 55.698259110886582, 45.653999999999996, 0, + 44.401823743922364, 39.131999999999998, 0, 44.401823743922364, 26.088000000000001, 0, + 78.291129844815018, 19.565999999999999, 0, 89.587565211779236, 26.088000000000001, 0, + 89.587565211779236, 39.131999999999998, 0, 78.291129844815018, 45.653999999999996, 0, + 66.9946944778508 , 39.131999999999998, 0, 66.9946944778508 , 26.088000000000001, 0, + 44.401823743922364, 39.132000000000005, 0, 55.698259110886582, 45.654000000000003, 0, + 55.698259110886582, 58.698 , 0, 44.401823743922364, 65.219999999999999, 0, + 33.105388376958146, 58.698 , 0, 33.105388376958146, 45.654000000000003, 0, + 66.9946944778508 , 39.132000000000005, 0, 78.291129844815018, 45.654000000000003, 0, + 78.291129844815018, 58.698 , 0, 66.9946944778508 , 65.219999999999999, 0, + 55.698259110886582, 58.698 , 0, 55.698259110886582, 45.654000000000003, 0, + 44.401823743922364, 0 , 1, 55.698259110886582, 6.5220000000000002, 1, + 55.698259110886582, 19.566000000000003, 1, 44.401823743922364, 26.088000000000001, 1, + 33.105388376958146, 19.566000000000003, 1, 33.105388376958146, 6.5220000000000002, 1, + 66.9946944778508 , 0 , 1, 78.291129844815018, 6.5220000000000002, 1, + 78.291129844815018, 19.566000000000003, 1, 66.9946944778508 , 26.088000000000001, 1, + 55.698259110886582, 19.566000000000003, 1, 55.698259110886582, 6.5220000000000002, 1, + 33.105388376958146, 19.565999999999999, 1, 44.401823743922364, 26.088000000000001, 1, + 44.401823743922364, 39.131999999999998, 1, 33.105388376958146, 45.653999999999996, 1, + 21.808953009993928, 39.131999999999998, 1, 21.808953009993928, 26.088000000000001, 1, + 55.698259110886582, 19.565999999999999, 1, 66.9946944778508 , 26.088000000000001, 1, + 66.9946944778508 , 39.131999999999998, 1, 55.698259110886582, 45.653999999999996, 1, + 44.401823743922364, 39.131999999999998, 1, 44.401823743922364, 26.088000000000001, 1, + 78.291129844815018, 19.565999999999999, 1, 89.587565211779236, 26.088000000000001, 1, + 89.587565211779236, 39.131999999999998, 1, 78.291129844815018, 45.653999999999996, 1, + 66.9946944778508 , 39.131999999999998, 1, 66.9946944778508 , 26.088000000000001, 1, + 44.401823743922364, 39.132000000000005, 1, 55.698259110886582, 45.654000000000003, 1, + 55.698259110886582, 58.698 , 1, 44.401823743922364, 65.219999999999999, 1, + 33.105388376958146, 58.698 , 1, 33.105388376958146, 45.654000000000003, 1, + 66.9946944778508 , 39.132000000000005, 1, 78.291129844815018, 45.654000000000003, 1, + 78.291129844815018, 58.698 , 1, 66.9946944778508 , 65.219999999999999, 1, + 55.698259110886582, 58.698 , 1, 55.698259110886582, 45.654000000000003, 1}; + + pmesh->setCoordinates(3, nNodes, coord, "CARTESIAN", MED_EN::MED_FULL_INTERLACE); + + string coordname[3] = { "x", "y", "z" }; + pmesh->setCoordinatesNames(coordname); + + // Set coordinates units + string coordunit[3] = { "cm", "cm", "cm" }; + pmesh->setCoordinatesUnits(coordunit); + + int polyHInd[] = {1, 9, 17, 25, 33, 41, 49, 57}; + int polyHFacesInd[] = {1 , 7 , 13 , 17 , 21 , 25 , 29 , 33 , + 37 , 43 , 49 , 53 , 57 , 61 , 65 , 69 , + 73 , 79 , 85 , 89 , 93 , 97 , 101, 105, + 109, 115, 121, 125, 129, 133, 137, 141, + 145, 151, 157, 161, 165, 169, 173, 177, + 181, 187, 193, 197, 201, 205, 209, 213, + 217, 223, 229, 233, 237, 241, 245, 249, 253}; + int polyHConn[] = { + 1,2,3,4,5,6, 43,44,45,46,47,48, 1,2,44,43, 2,3,45,44, + 3,4,46,45, 4,5,47,46, 5,6,48,47, 6,1,43,48, // #1 + 7,8,9,10,3,2, 49,50,51,52,45,44, 7,8,50,49, 8,9,51,50, + 9,10,52,51, 10,3,45,52, 3,2,44,45, 2,7,49,44, // #2 + 5,4,15,16,17,18, 47,46,57,58,59,60, 5,4,46,47, 4,15,57,46, + 15,16,58,57, 16,17,59,58, 17,18,60,59, 18,5,47,60, // #3 + 3,10,21,22,15,4, 45,52,63,64,57,46, 3,10,52,45, 10,21,63,52, + 21,22,64,63, 22,15,57,64, 15,4,46,57, 4,3,45,46, // #4 + 9,26,27,28,21,10, 51,68,69,70,63,52, 9,26,68,51, 26,27,69,68, + 27,28,70,69, 28,21,63,70, 21,10,52,63, 10,9,51,52, // #5 + 15,22,33,34,35,16, 57,64,75,76,77,58, 15,22,64,57, 22,33,75,64, + 33,34,76,75, 34,35,77,76, 35,16,58,77, 16,15,57,58, // #6 + 21,28,39,40,33,22, 63,70,81,82,75,64, 21,28,70,63, 28,39,81,70, + 39,40,82,81, 40,33,75,82, 33,22,64,75, 22,21,63,64}; // #7 + + pmesh->setPolyhedraConnectivity(polyHInd, polyHFacesInd, polyHConn, + nb_hexagone*(nbmailles_axiales-1), MED_EN::MED_CELL); + + int cpolygonsindex[] = {1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85}; + int connec[] = { + 1 , 2 , 3 , 4 , 5 , 6 , + 7 , 8 , 9 , 10, 3 , 2 , + 5 , 4 , 15, 16, 17, 18, + 3 , 10, 21, 22, 15, 4 , + 9 , 26, 27, 28, 21, 10, + 15, 22, 33, 34, 35, 16, + 21, 28, 39, 40, 33, 22, + 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 45, 44, + 47, 46, 57, 58, 59, 60, + 45, 52, 63, 64, 57, 46, + 51, 68, 69, 70, 63, 52, + 57, 64, 75, 76, 77, 58, + 63, 70, 81, 82, 75, 64}; + + pmesh->setNumberOfTypes(0, MED_EN::MED_FACE); + pmesh->setPolygonsConnectivity(cpolygonsindex, connec, nb_hexagone*nbmailles_axiales, MED_EN::MED_FACE); + + int bottom[] = {1, 2, 3, 4, 5, 6, 7}; + addMedFacesGroup(*pmesh, nb_hexagone, bottom, "BottomFaces"); + + int id = pmesh->addDriver(MED_DRIVER, "cronoshexa.med", pmesh->getName()); + pmesh->write(id); +} diff --git a/src/MEDMEM_I/MEDMEM_Family_i.hxx b/src/MEDMEM_I/MEDMEM_Family_i.hxx index 594b095b4..12a908eec 100644 --- a/src/MEDMEM_I/MEDMEM_Family_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Family_i.hxx @@ -26,14 +26,15 @@ #ifndef MED_FAMILY_I_HXX_ #define MED_FAMILY_I_HXX_ +#include "MEDMEM_I.hxx" #include "MEDMEM_Support_i.hxx" namespace MEDMEM { class FAMILY; -class FAMILY_i: - public POA_SALOME_MED::FAMILY, - public SUPPORT_i +class MEDMEM_I_EXPORT FAMILY_i: + virtual public POA_SALOME_MED::FAMILY, + virtual public SUPPORT_i { protected : FAMILY_i(); diff --git a/src/MEDMEM_I/MEDMEM_Field_i.cxx b/src/MEDMEM_I/MEDMEM_Field_i.cxx index 6b482f32b..f7d36a80a 100644 --- a/src/MEDMEM_I/MEDMEM_Field_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Field_i.cxx @@ -1,4 +1,3 @@ - // Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG // PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT // This library is free software; you can redistribute it and/or @@ -22,15 +21,23 @@ // Created : mer fĂ©v 20 15:47:57 CET 2002 // Author : EDF // Project : SALOME -// $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Field_i.cxx +// $Header : $ //============================================================================= + #include "MEDMEM_Field_i.hxx" +#include "SALOME_NamingService.hxx" +#include "SALOME_LifeCycleCORBA.hxx" + +#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) +#include CORBA_CLIENT_HEADER(MED_Gen) + using namespace MEDMEM; using namespace MED_EN; map < int, ::FIELD_ * > FIELD_i::fieldMap ; int FIELD_i::fieldIndex = 0; + //============================================================================= /*! * Default constructor @@ -96,6 +103,7 @@ FIELD_i::FIELD_i( FIELD_i & f):_fieldTptr(f._fieldTptr), ::FIELD_ * const ptrField =new ::FIELD_(); return ptrField; } + //============================================================================= /*! * CORBA: Accessor for Fields's Name @@ -117,6 +125,22 @@ throw (SALOME::SALOME_Exception) THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); } } + +void FIELD_i::setName(const char* theName) + throw (SALOME::SALOME_Exception) +{ + if (_fieldTptr == NULL) + THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR); + + try { + _fieldTptr->setName(theName); + } + catch (MEDEXCEPTION &ex) { + MESSAGE("Exception en accedant au nom"); + THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); + } +} + //============================================================================= /*! * CORBA: Accessor for Fields's Description @@ -143,7 +167,6 @@ throw (SALOME::SALOME_Exception) * CORBA: Accessor for Fields's Support */ //============================================================================= - SALOME_MED::SUPPORT_ptr FIELD_i::getSupport() throw (SALOME::SALOME_Exception) { @@ -431,72 +454,96 @@ throw (SALOME::SALOME_Exception) } return myseq._retn(); } + //============================================================================= /*! * CORBA: Add in Study */ //============================================================================= -void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy, - SALOME_MED::FIELD_ptr myIor ) - throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) +void FIELD_i::addInStudy (SALOMEDS::Study_ptr myStudy, + SALOME_MED::FIELD_ptr myIor) + throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) +{ + SALOMEDS::SComponent_var aComponent = PublishMedComponent(myStudy); + if (CORBA::is_nil(aComponent)) + THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found", SALOME::INTERNAL_ERROR); + addInStudyToComponent(aComponent, myIor); +} + +static SALOMEDS::SObject_ptr FindChildByName (SALOMEDS::SObject_ptr theFather, + const string theName) +{ + SALOMEDS::SObject_var aChild; + if (CORBA::is_nil(theFather)) + return aChild._retn(); + + SALOMEDS::SObject_var aCurChild; + SALOMEDS::ChildIterator_ptr anIter = theFather->GetStudy()->NewChildIterator(theFather); + for (; anIter->More() && aChild->_is_nil(); anIter->Next()) { + aCurChild = anIter->Value(); + string aCurName = aCurChild->GetName(); + if (aCurName == theName) + aChild = aCurChild; + } + return aChild._retn(); +} + +void FIELD_i::addInStudyToComponent (SALOMEDS::SComponent_ptr myComponent, + SALOME_MED::FIELD_ptr myIor) + throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection) { BEGIN_OF(" FIELD_i::addInStudy"); - if (_fieldTptr==NULL) - THROW_SALOME_CORBA_EXCEPTION("No associated Field", \ - SALOME::INTERNAL_ERROR); - if ( _FieldId != "" ) - { - MESSAGE("Field already in Study"); - THROW_SALOME_CORBA_EXCEPTION("Field already in Study", \ - SALOME::BAD_PARAM); - }; + if (CORBA::is_nil(myComponent) || CORBA::is_nil(myIor)) + THROW_SALOME_CORBA_EXCEPTION("Null parameter", SALOME::BAD_PARAM); + + if (_fieldTptr == NULL) + THROW_SALOME_CORBA_EXCEPTION("No associated Field", SALOME::INTERNAL_ERROR); + + if (_FieldId != "") { + MESSAGE("Field already in Study"); + THROW_SALOME_CORBA_EXCEPTION("Field already in Study", SALOME::BAD_PARAM); + } + + SALOMEDS::Study_var myStudy = myComponent->GetStudy(); + SALOMEDS::StudyBuilder_var aBuilder = myStudy->NewBuilder(); - SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeName_var aName; SALOMEDS::AttributeIOR_var aIOR; - // Create SComponent labelled 'Med' - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); - if ( CORBA::is_nil(medfather) ) - THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'MED' not Found",SALOME::INTERNAL_ERROR); - - // Create SObject labelled 'MEDFIELD' if it doesn't already exit - SALOMEDS::SObject_var medfieldfather = myStudy->FindObject("MEDFIELD"); - if ( CORBA::is_nil(medfieldfather) ) - { + // Create SObject labelled 'MEDFIELD' if it doesn't already exist + SALOMEDS::Study::ListOfSObject_var aMEDFIELDs = + myStudy->FindObjectByName("MEDFIELD", myComponent->ComponentDataType()); + int aLength = aMEDFIELDs->length(); + SALOMEDS::SObject_var medfieldfather; + if (aLength > 0) { + medfieldfather = aMEDFIELDs[0]; + } + else { MESSAGE("Add Object 'MEDFIELD'"); - medfieldfather = myBuilder->NewObject(medfather); - anAttr = myBuilder->FindOrCreateAttribute(medfieldfather, "AttributeName"); + medfieldfather = aBuilder->NewObject(myComponent); + anAttr = aBuilder->FindOrCreateAttribute(medfieldfather, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue("MEDFIELD"); - - } ; - - string fieldName = _fieldTptr->getName(); + } // Create SObject labelled 'FIELDNAME' if it doesn't already exit - SALOMEDS::SObject_var medfieldnamefather = myStudy->FindObject(fieldName.c_str()); + string fieldName = _fieldTptr->getName(); + SALOMEDS::SObject_var medfieldnamefather = FindChildByName(medfieldfather, fieldName); if ( CORBA::is_nil(medfieldnamefather) ) { MESSAGE("Add Object "<<fieldName); - medfieldnamefather = myBuilder->NewObject(medfieldfather); - anAttr = myBuilder->FindOrCreateAttribute(medfieldnamefather, "AttributeName"); + medfieldnamefather = aBuilder->NewObject(medfieldfather); + anAttr = aBuilder->FindOrCreateAttribute(medfieldnamefather, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(fieldName.c_str()); + } - } ; - - // Create object labelled according to Field's Name - - MESSAGE("Add a Field Object under "<<fieldName); - myBuilder->NewCommand(); - SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfieldnamefather); - - ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; - ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; - CORBA::ORB_var &orb = init(0,0); + string fieldEntryPath = "/"; + //fieldEntryPath += "Med/"; + string componentName = myComponent->GetName(); + fieldEntryPath += componentName + "/MEDFIELD/" + fieldName + "/"; int iterationNumber = _fieldTptr->getIterationNumber(); SCRUTE(iterationNumber); @@ -504,13 +551,15 @@ void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy, int orderNumber = _fieldTptr->getOrderNumber(); SCRUTE(orderNumber); - ostringstream iterationName ; + ostringstream iterationName; iterationName<<"(" << iterationNumber << "," << orderNumber << ")"; - // string supportName = _support->getName(); string supportName = (_fieldTptr->getSupport())->getName(); - // string meshName = (_support->getMesh())->getName(); string meshName = ((_fieldTptr->getSupport())->getMesh())->getName(); - string meshNameStudy = meshName; + + SCRUTE(meshName); + for (string::size_type pos=0; pos<meshName.size(); ++pos) { + if (isspace(meshName[pos])) meshName[pos] = '_'; + } char * fieldEntryName; int lenName = strlen(iterationName.str().c_str()) + 4 + @@ -521,66 +570,68 @@ void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy, fieldEntryName = strcat(fieldEntryName,"_ON_"); fieldEntryName = strcat(fieldEntryName,supportName.c_str()); fieldEntryName = strcat(fieldEntryName,"_OF_"); - - for (string::size_type pos=0; pos<meshNameStudy.size();++pos) - { - if (isspace(meshNameStudy[pos])) meshNameStudy[pos] = '_'; - } - - SCRUTE(meshNameStudy); - - fieldEntryName = strcat(fieldEntryName,meshNameStudy.c_str()); + fieldEntryName = strcat(fieldEntryName,meshName.c_str()); SCRUTE(fieldEntryName); + fieldEntryPath += fieldEntryName; - anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName"); + // Create object labelled according to Field's Name + + SALOMEDS::SObject_var fieldSO = myStudy->FindObjectByPath(fieldEntryPath.c_str()); + bool alreadyPublished = ! CORBA::is_nil(fieldSO); + aBuilder->NewCommand(); + if ( !alreadyPublished ) + { + MESSAGE("Add a Field Object under "<<fieldName); + fieldSO = aBuilder->NewObject(medfieldnamefather); + // check that this method and getEntryPath() build the same path, + // though this is true only for MED component + MESSAGE("fieldEntryPath: "<< fieldEntryPath); + MESSAGE("getEntryPath(): "<< getEntryPath()); + if (componentName == "Med") + ASSERT( getEntryPath() == fieldEntryPath ); + } + anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); -// aName->SetValue(iterationName.str().c_str()); aName->SetValue(fieldEntryName); + ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; + ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; + CORBA::ORB_var &orb = init(0,0); string iorStr = orb->object_to_string(myIor); - anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); + anAttr = aBuilder->FindOrCreateAttribute(fieldSO, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); aIOR->SetValue(iorStr.c_str()); - myBuilder->CommitCommand(); - _FieldId = newObj->GetID(); - - MESSAGE("Computing path to Support"); + _FieldId = fieldSO->GetID(); - char * supportEntryPath; - lenName = 28 + 15 + strlen(meshName.c_str()) + 1 + - strlen(supportName.c_str()) + 1; - supportEntryPath = new char[lenName]; - supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/MEDSUPPORTS_OF_"); - supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str()); - supportEntryPath = strcat(supportEntryPath,"/"); - supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - - SCRUTE(supportEntryPath); + if ( !alreadyPublished ) + { + MESSAGE("Computing path to Support"); - MESSAGE("supportEntryPath in field " << supportEntryPath << " length " << lenName); + string supportEntryPath = SUPPORT_i::getEntryPath( _fieldTptr->getSupport() ); + SCRUTE(supportEntryPath); -// SALOMEDS::SObject_var supportObject = myStudy->FindObject(supportName.c_str()); - SALOMEDS::SObject_var supportObject = myStudy->FindObjectByPath(supportEntryPath); + SALOMEDS::SObject_var supportObject = + myStudy->FindObjectByPath(supportEntryPath.c_str()); - SCRUTE(supportObject); + SCRUTE(supportObject); - if ( CORBA::is_nil(supportObject) ) - { - MESSAGE("supportObject is a nil corba object"); - MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ; - } - else - { - MESSAGE("supportObject is OK and is now going to be referenced !"); - SALOMEDS::SObject_var newObjSupport = myBuilder->NewObject(newObj); - myBuilder->Addreference(newObjSupport,supportObject); - MESSAGE(" OUF !!!"); - } + if ( CORBA::is_nil(supportObject) ) + { + MESSAGE("supportObject is a nil corba object"); + MESSAGE("FIELD_i::addInStudy : SUPPORT not found") ; + } + else + { + MESSAGE("supportObject is OK and is now going to be referenced !"); + SALOMEDS::SObject_var newObjSupport = aBuilder->NewObject(fieldSO); + aBuilder->Addreference(newObjSupport,supportObject); + MESSAGE(" OUF !!!"); + } + } - myBuilder->CommitCommand(); + aBuilder->CommitCommand(); - delete [] supportEntryPath; delete [] fieldEntryName; // register the Corba pointer: increase the referrence count @@ -591,6 +642,7 @@ void FIELD_i::addInStudy(SALOMEDS::Study_ptr myStudy, //END_OF("FIELD_i::addInStudy"); } + //============================================================================= /*! * CORBA: write @@ -606,7 +658,7 @@ throw (SALOME::SALOME_Exception) { _fieldTptr->write(i,driverFieldName); } - catch (MEDEXCEPTION &ex) + catch (MEDEXCEPTION &) { MESSAGE("Exception en accedant au champ"); THROW_SALOME_CORBA_EXCEPTION("Unable to acces Field C++ Object"\ @@ -681,3 +733,87 @@ CORBA::Long FIELD_i::addDriver (SALOME_MED::medDriverTypes driverType, } } +//============================================================================= +/*! + * internal method: publish MED component + */ +//============================================================================= + +SALOMEDS::SComponent_ptr FIELD_i::PublishMedComponent(SALOMEDS::Study_ptr theStudy) +{ + if ( CORBA::is_nil(theStudy) ) + return SALOMEDS::SComponent::_nil(); + + SALOMEDS::SComponent_var medfather = theStudy->FindComponent("MED"); + if ( !CORBA::is_nil(medfather) ) + return medfather._retn(); + + ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; + ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; + CORBA::ORB_var &orb = init(0,0); + + SALOME_NamingService* ns = SINGLETON_<SALOME_NamingService>::Instance(); + ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()); + ns->init_orb( orb ); + + SALOME_LifeCycleCORBA* lcc = new SALOME_LifeCycleCORBA( ns ); + + SALOME_ModuleCatalog::ModuleCatalog_var aCatalog = + SALOME_ModuleCatalog::ModuleCatalog::_narrow(ns->Resolve("/Kernel/ModulCatalog")); + if ( CORBA::is_nil( aCatalog ) ) + return medfather._retn(); + SALOME_ModuleCatalog::Acomponent_var aComp = aCatalog->GetComponent( "MED" ); + if ( CORBA::is_nil( aComp ) ) + return medfather._retn(); + + SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder(); + aBuilder->NewCommand(); + bool aLocked = theStudy->GetProperties()->IsLocked(); + if (aLocked) theStudy->GetProperties()->SetLocked(false); + + medfather = aBuilder->NewComponent("MED"); + SALOMEDS::GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(medfather, "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue( aComp->componentusername() ); + + Engines::Component_var aMedComponent = lcc->FindOrLoad_Component("FactoryServer", "MED"); + SALOME_MED::MED_Gen_var aMedEngine = SALOME_MED::MED_Gen::_narrow( aMedComponent ); + aBuilder->DefineComponentInstance(medfather, aMedEngine); + + if (aLocked) theStudy->GetProperties()->SetLocked(true); + aBuilder->CommitCommand(); + + return medfather._retn(); +} + +//================================================================================ +/*! + * \brief Return a default path to publish this field + * \retval string - the path + */ +//================================================================================ + +string FIELD_i::getEntryPath () +{ + string path; + if ( _fieldTptr && + _fieldTptr->getSupport() && + _fieldTptr->getSupport()->getMesh() ) + { + string meshName = _fieldTptr->getSupport()->getMesh()->getName(); + for (string::size_type pos=0; pos<meshName.size(); ++pos) + { + if (isspace(meshName[pos])) meshName[pos] = '_'; + } + ostringstream os ; + + os << "/Med/MEDFIELD/" << _fieldTptr->getName() << "/" + << "(" << _fieldTptr->getIterationNumber() + << "," << _fieldTptr->getOrderNumber() + << ")_ON_" << _fieldTptr->getSupport()->getName() + << "_OF_" << meshName; + + path = os.str(); + } + return path; +} diff --git a/src/MEDMEM_I/MEDMEM_Field_i.hxx b/src/MEDMEM_I/MEDMEM_Field_i.hxx index dbf0adbf3..742b0bd6e 100644 --- a/src/MEDMEM_I/MEDMEM_Field_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Field_i.hxx @@ -20,13 +20,15 @@ // File : MEDMEM_Field_i.hxx // Project : SALOME // Author : EDF -// $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Field_i.hxx +// $Header : $ //============================================================================= #ifndef MED_FIELD_I_HXX_ #define MED_FIELD_I_HXX_ +#include <MEDMEM_I.hxx> + #include <map> #include <string> #include <sstream> @@ -47,7 +49,7 @@ #include "MEDMEM_Field.hxx" namespace MEDMEM { -class FIELD_i: public virtual POA_SALOME_MED::FIELD, +class MEDMEM_I_EXPORT FIELD_i: public virtual POA_SALOME_MED::FIELD, public SALOME::GenericObj_i { public : @@ -71,6 +73,9 @@ public : ~FIELD_i(); char * getName() throw (SALOME::SALOME_Exception); + void setName(const char* theName) + throw (SALOME::SALOME_Exception); + char * getDescription() throw (SALOME::SALOME_Exception); SALOME_MED::SUPPORT_ptr getSupport() throw (SALOME::SALOME_Exception); CORBA::Long getNumberOfComponents() @@ -91,11 +96,17 @@ public : SALOME_MED::string_array * getComponentsNames() throw (SALOME::SALOME_Exception); SALOME_MED::string_array * getComponentsUnits() throw (SALOME::SALOME_Exception); SALOME_MED::string_array * getComponentsDescriptions() throw (SALOME::SALOME_Exception); - void addInStudy(SALOMEDS::Study_ptr myStudy, - SALOME_MED::FIELD_ptr myIor) - throw (SALOME::SALOME_Exception, + + void addInStudy(SALOMEDS::Study_ptr myStudy, + SALOME_MED::FIELD_ptr myIor) + throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); + void addInStudyToComponent(SALOMEDS::SComponent_ptr myComponent, + SALOME_MED::FIELD_ptr myIor) + throw (SALOME::SALOME_Exception, + SALOMEDS::StudyBuilder::LockProtection); + CORBA::Long addDriver (SALOME_MED::medDriverTypes driverType, const char* fileName, const char* fieldName) throw (SALOME::SALOME_Exception); @@ -106,6 +117,12 @@ public : // Cuisine Interne MEDMEM::FIELD_ * constructConstField() const; + // Publish MED Component + SALOMEDS::SComponent_ptr PublishMedComponent(SALOMEDS::Study_ptr theStudy); + + // Return a default path to publish this field + std::string getEntryPath (); + }; } diff --git a/src/MEDMEM_I/MEDMEM_Group_i.cxx b/src/MEDMEM_I/MEDMEM_Group_i.cxx index ffa63d0b3..20ffa385a 100644 --- a/src/MEDMEM_I/MEDMEM_Group_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Group_i.cxx @@ -121,7 +121,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbfam;i++) { FAMILY_i * f1=new FAMILY_i(fam[i]); - myseq[i] = f1->POA_SALOME_MED::FAMILY::_this(); + myseq[i] = f1->_this(); } } catch (MEDEXCEPTION &ex) @@ -147,7 +147,7 @@ throw (SALOME::SALOME_Exception) { FAMILY * fam=_group->getFamily(i); FAMILY_i * f1=new FAMILY_i(fam); - return f1->POA_SALOME_MED::FAMILY::_this(); + return f1->_this(); } catch (MEDEXCEPTION &ex) { diff --git a/src/MEDMEM_I/MEDMEM_Group_i.hxx b/src/MEDMEM_I/MEDMEM_Group_i.hxx index c5a31fe19..517eae839 100644 --- a/src/MEDMEM_I/MEDMEM_Group_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Group_i.hxx @@ -26,15 +26,17 @@ #ifndef MED_GROUP_I_HXX_ #define MED_GROUP_I_HXX_ +#include "MEDMEM_I.hxx" + #include "MEDMEM_Support_i.hxx" namespace MEDMEM { class FAMILY_i; class GROUP; -class GROUP_i: - public POA_SALOME_MED::GROUP, - public SUPPORT_i +class MEDMEM_I_EXPORT GROUP_i: + virtual public POA_SALOME_MED::GROUP, + virtual public SUPPORT_i { protected : GROUP_i(); diff --git a/src/MEDMEM_I/MEDMEM_I.hxx b/src/MEDMEM_I/MEDMEM_I.hxx new file mode 100755 index 000000000..4b469b51b --- /dev/null +++ b/src/MEDMEM_I/MEDMEM_I.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MEDMEM_I.hxx +// Author : Alexander A. BORODIN +// Module : MED + +#ifndef _MEDMEM_I_HXX_ +#define _MEDMEM_I_HXX_ + +#ifdef WNT + #if defined MEDMEM_I_EXPORTS + #if defined WIN32 + #define MEDMEM_I_EXPORT __declspec( dllexport ) + #else + #define MEDMEM_I_EXPORT + #endif + #else + #if defined WIN32 + #define MEDMEM_I_EXPORT __declspec( dllimport ) + #else + #define MEDMEM_I_EXPORT + #endif + #endif +#else + #define MEDMEM_I_EXPORT +#endif + +#endif \ No newline at end of file diff --git a/src/MEDMEM_I/MEDMEM_Med_i.cxx b/src/MEDMEM_I/MEDMEM_Med_i.cxx index 8340ba0d2..98c023aa6 100644 --- a/src/MEDMEM_I/MEDMEM_Med_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Med_i.cxx @@ -26,7 +26,6 @@ #include <deque> //#include "MEDMEM_Field.hxx" - #include "MEDMEM_Med_i.hxx" #include "MEDMEM_Mesh_i.hxx" #include "MEDMEM_FieldTemplate_i.hxx" @@ -35,6 +34,9 @@ #include "MEDMEM_Group_i.hxx" #include "MEDMEM_convert.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDMEM_Group.hxx" + #include "MEDMEM_DriversDef.hxx" #include "utilities.h" #include "Utils_CorbaException.hxx" @@ -52,6 +54,7 @@ MED_i::MED_i():_med((::MED*)NULL) BEGIN_OF("Default Constructor MED_i"); END_OF("Default Constructor MED_i"); } + //============================================================================= /*! * methods @@ -108,7 +111,7 @@ void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const strin familyVectorIt++) { FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt); - SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this(); + SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->_this(); // myFamilyI->addInStudy(myStudy,myFamilyIOR); } @@ -121,7 +124,7 @@ void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const strin groupVectorIt++) { GROUP_i * myGroupI = new GROUP_i(*groupVectorIt); - SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this(); + SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->_this(); // myGroupI->addInStudy(myStudy,myGroupIOR); } } @@ -154,30 +157,19 @@ void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const strin ::FIELD_ * myField = _med->getField(fieldsNames[i], myIteration[j].dt, myIteration[j].it); string meshName = myField->getSupport()->getMesh()->getName(); medEntityMesh myEntity = myField->getSupport()->getEntity(); - map<string, map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> >::const_iterator - itSupportOnMesh = _supports.find(meshName); - if ( itSupportOnMesh == _supports.end() ) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "There is no support on mesh named |" - << meshName << "|" )); - const map<MED_EN::medEntityMesh, SALOME_MED::SUPPORT_ptr> & SupportOnMesh - = (*itSupportOnMesh).second; - map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport - = SupportOnMesh.find(myEntity); - if (itSupport == SupportOnMesh.end()) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "There is no support on entity " - << entity << " in mesh named |" - << meshName << "|")); - SALOME_MED::SUPPORT_ptr mySupportIOR = (*itSupport).second; + SALOME_MED::SUPPORT_var mySupportIOR = getSupport( meshName, myEntity ); + med_type_champ type = myField->getValueType(); + //medModeSwitch mode = myField->getInterlacingType(); SALOME_MED::FIELD_ptr myFieldIOR; switch (type) { case MED_EN::MED_INT32 : { - ((FIELD<int>*)myField)->read(); - FIELDTEMPLATE_I<int> *myFieldIntI = new FIELDTEMPLATE_I<int>((FIELD<int>*)myField); + myField->read(); + //if ( mode == FullInterlace ) + FIELDTEMPLATE_I<int> *myFieldIntI = + new FIELDTEMPLATE_I<int>((FIELD<int>*)myField); myFieldIOR = myFieldIntI->_this(); // myFieldIntI->addInStudy(myStudy,myFieldIOR); break; @@ -185,7 +177,7 @@ void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const strin case MED_EN::MED_REEL64: { - ((FIELD<double>*)myField)->read(); + myField->read(); FIELDTEMPLATE_I<double> *myFieldDoubleI = new FIELDTEMPLATE_I<double>((FIELD<double>*)myField); myFieldIOR = myFieldDoubleI->_this(); // myFieldDoubleI->addInStudy(myStudy,myFieldIOR); @@ -210,14 +202,47 @@ void MED_i::init(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const strin END_OF(LOC); } +//============================================================================= +/*! + * service + * purpose: return true if a support is published in a study + */ +//============================================================================= + +/* +namespace { + bool isPublishedObject(SALOMEDS::Study_ptr study, + string entryPath) + { + SALOMEDS::SObject_var so = study->FindObjectByPath( entryPath.c_str() ); + if ( !so->_is_nil() ) { + CORBA::String_var ior = so->GetIOR(); + // for persistance: "published" means SObject exists but without IOR + bool published = ( strlen( ior ) == 0 ); + return published; + } + return false; + } + bool isPublishedMesh(SALOMEDS::Study_ptr study, + CORBA::String_var meshName) + { + string entryPath("/Med/MEDMESH/"); + entryPath += meshName; + return isPublishedObject( study, entryPath ); + } +} +*/ //============================================================================= /*! * methods */ //============================================================================= -void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const string & fileName) +void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType, const string & fileName, bool persistence) { + // if (persistence): + // some objects can be not published + const char * LOC = "MED_i::initWithFieldType(driverTypes, const string &)"; BEGIN_OF(LOC); @@ -246,7 +271,9 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType MESH_i * myMeshI = new MESH_i(myMesh); SALOME_MED::MESH_ptr myMeshIOR = myMeshI->_this(); _meshes[meshesNames[i]]=myMeshIOR; - myMeshI->addInStudy(myStudy,myMeshIOR); + //if ( !persistence || isPublishedMesh(myStudy,myMeshI->getName() )) + if ( !persistence ) + myMeshI->addInStudy(myStudy,myMeshIOR); } // SUPPORTS : @@ -284,8 +311,12 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType familyVectorIt++) { FAMILY_i * myFamilyI = new FAMILY_i(*familyVectorIt); - SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->POA_SALOME_MED::FAMILY::_this(); - myFamilyI->addInStudy(myStudy,myFamilyIOR); + SALOME_MED::FAMILY_ptr myFamilyIOR = myFamilyI->_this(); + //if ( !persistence || + // isPublishedObject( myStudy, SUPPORT_i::getEntryPath + // ((const SUPPORT *)*familyVectorIt))) + if ( !persistence ) + myFamilyI->addInStudy(myStudy,myFamilyIOR); } // group : @@ -297,8 +328,12 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType groupVectorIt++) { GROUP_i * myGroupI = new GROUP_i(*groupVectorIt); - SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->POA_SALOME_MED::GROUP::_this(); - myGroupI->addInStudy(myStudy,myGroupIOR); + SALOME_MED::GROUP_ptr myGroupIOR = myGroupI->_this(); + //if ( !persistence || + // isPublishedObject( myStudy, SUPPORT_i::getEntryPath + // ((const SUPPORT *)*groupVectorIt))) + if ( !persistence ) + myGroupI->addInStudy(myStudy,myGroupIOR); } } } @@ -314,7 +349,11 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType SUPPORT_i * mySupportI = new SUPPORT_i((*itSupport).second); SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this(); mySupportsIOR[(*itSupport).first]= mySupportIOR; - mySupportI->addInStudy(myStudy,mySupportIOR); + //if ( !persistence || + // isPublishedObject( myStudy, + // SUPPORT_i::getEntryPath (itSupport->second))) + if ( !persistence ) + mySupportI->addInStudy(myStudy,mySupportIOR); } } @@ -471,25 +510,13 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType ::FIELD_ * myField = _med->getField(fieldsNames[i],dt,it); + // check if corresponding support exists string meshName = myField->getSupport()->getMesh()->getName(); medEntityMesh myEntity = myField->getSupport()->getEntity(); - map<string, map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> >::const_iterator - itSupportOnMesh = _supports.find(meshName); - if (itSupportOnMesh == _supports.end() ) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "There is no support on mesh named |" - << meshName << "|")); - const map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> & SupportOnMesh - = (*itSupportOnMesh).second; - map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport - = SupportOnMesh.find(myEntity); - if (itSupport == SupportOnMesh.end() ) - throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) - << "There is no support on entity " - << entity << " in mesh named |" - << meshName << "|")); - SALOME_MED::SUPPORT_ptr mySupportIOR = (*itSupport).second; + SALOME_MED::SUPPORT_var support = getSupport( meshName, myEntity ); + med_type_champ type = myField->getValueType(); + medModeSwitch mode = myField->getInterlacingType(); DT_IT_ dtIt; dtIt.dt = dt; @@ -497,32 +524,56 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType switch (type) { - case MED_EN::MED_INT32: - { - ((FIELD<int>*)myField)->read(); - FIELDTEMPLATE_I<int> *myFieldIntI = new FIELDTEMPLATE_I<int>((FIELD<int>*)myField); - SALOME_MED::FIELDINT_ptr myFieldIntIOR; - myFieldIntIOR = myFieldIntI->_this(); - - MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() << " dt = " << dtIt.dt << " it = " << dtIt.it); - - myFieldIntI->addInStudy(myStudy,myFieldIntIOR); - _fields[fieldsNames[i]][dtIt] = myFieldIntIOR; - break; - } + case MED_EN::MED_INT32: + { + myField->read(); + SALOME_MED::FIELD_ptr myFieldIntIOR; + FIELD_i* myFieldIntI; + if ( mode == MED_FULL_INTERLACE ) + { + myFieldIntI = new FIELDTEMPLATE_I<int,FullInterlace>((FIELD<int,FullInterlace>*)myField); + myFieldIntIOR = myFieldIntI->_this(); + } + else + { + myFieldIntI = new FIELDTEMPLATE_I<int,NoInterlace>((FIELD<int,NoInterlace>*)myField); + myFieldIntIOR = myFieldIntI->_this(); + } + MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() + << " dt = " << dtIt.dt << " it = " << dtIt.it); + + //if ( !persistence || + // isPublishedObject( myStudy, myFieldIntI->getEntryPath() )) + if ( !persistence ) + myFieldIntI->addInStudy(myStudy,myFieldIntIOR); + _fields[fieldsNames[i]][dtIt] = myFieldIntIOR; + break; + } case MED_EN::MED_REEL64: { - ((FIELD<double>*)myField)->read(); - FIELDTEMPLATE_I<double> *myFieldDoubleI = new FIELDTEMPLATE_I<double>((FIELD<double>*)myField); - SALOME_MED::FIELDDOUBLE_ptr myFieldDoubleIOR; - myFieldDoubleIOR = myFieldDoubleI->_this(); - - MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() << " dt = " << dtIt.dt << " it = " << dtIt.it); - - myFieldDoubleI->addInStudy(myStudy,myFieldDoubleIOR); - _fields[fieldsNames[i]][dtIt] = myFieldDoubleIOR; - break; + myField->read(); + SALOME_MED::FIELD_ptr myFieldDoubleIOR; + FIELD_i* myFieldDoubleI; + if ( mode == MED_FULL_INTERLACE ) + { + myFieldDoubleI = new FIELDTEMPLATE_I<double,FullInterlace>((FIELD<double,FullInterlace>*)myField); + myFieldDoubleIOR = myFieldDoubleI->_this(); + } + else + { + myFieldDoubleI = new FIELDTEMPLATE_I<double,NoInterlace>((FIELD<double,NoInterlace>*)myField); + myFieldDoubleIOR = myFieldDoubleI->_this(); + } + MESSAGE(LOC << " add in study of the field " << fieldsNames[i].c_str() + << " dt = " << dtIt.dt << " it = " << dtIt.it); + + //if ( !persistence || + // isPublishedObject( myStudy, myFieldDoubleI->getEntryPath() )) + if ( !persistence ) + myFieldDoubleI->addInStudy(myStudy,myFieldDoubleIOR); + _fields[fieldsNames[i]][dtIt] = myFieldDoubleIOR; + break; } default: @@ -538,140 +589,40 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType MESSAGE("Here we are i="<< i); } - - - - - - - - - - - - - - - -// for (int i=0; i<numberOfMeshes; i++) -// { -// string meshName = meshesNames[i]; -// char * supportEntryPath; -// int lenName; -// string supportName; -// SALOMEDS::SObject_var supportEntry; - -// supportName = "SupportOnAll_MED_MAILLE"; -// lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str()); -// supportEntryPath = new char[lenName]; -// supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/"); -// supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_"); -// supportEntryPath = strcat(supportEntryPath,meshName.c_str()); -// supportEntryPath = strcat(supportEntryPath,"/"); -// supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - -// SCRUTE(supportEntryPath); - -// cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl; - -// supportEntry = myStudy->FindObjectByPath(supportEntryPath); - -// if ( CORBA::is_nil(supportEntry) ) -// cout << "The reuse in Med is OK " << endl; -// else -// cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl; -// delete [] supportEntryPath; - - - -// supportName = "SupportOnAll_MED_FACE"; -// lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str()); -// supportEntryPath = new char[lenName]; -// supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/"); -// supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_"); -// supportEntryPath = strcat(supportEntryPath,meshName.c_str()); -// supportEntryPath = strcat(supportEntryPath,"/"); -// supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - -// SCRUTE(supportEntryPath); - -// cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl; - -// supportEntry = myStudy->FindObjectByPath(supportEntryPath); - -// if ( CORBA::is_nil(supportEntry) ) -// cout << "The reuse in Med is OK " << endl; -// else -// cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl; -// delete [] supportEntryPath; - - - -// supportName = "SupportOnAll_MED_ARETE"; -// lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str()); -// supportEntryPath = new char[lenName]; -// supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/"); -// supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_"); -// supportEntryPath = strcat(supportEntryPath,meshName.c_str()); -// supportEntryPath = strcat(supportEntryPath,"/"); -// supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - -// SCRUTE(supportEntryPath); - -// cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl; - -// supportEntry = myStudy->FindObjectByPath(supportEntryPath); - -// if ( CORBA::is_nil(supportEntry) ) -// cout << "The reuse in Med is OK " << endl; -// else -// cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl; -// delete [] supportEntryPath; - - - - -// supportName = "SupportOnAll_MED_NOEUD"; -// lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str()); -// supportEntryPath = new char[lenName]; -// supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/"); -// supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_"); -// supportEntryPath = strcat(supportEntryPath,meshName.c_str()); -// supportEntryPath = strcat(supportEntryPath,"/"); -// supportEntryPath = strcat(supportEntryPath,supportName.c_str()); - -// SCRUTE(supportEntryPath); - -// cout << "supportEntryPath in Med " << supportEntryPath << " length " << lenName << endl; - -// supportEntry = myStudy->FindObjectByPath(supportEntryPath); - -// if ( CORBA::is_nil(supportEntry) ) -// cout << "The reuse in Med is OK " << endl; -// else -// cout << "the reuse in Med is not OK and there was a problem in the storage in the study" << endl; -// delete [] supportEntryPath; - - - - -// } - - - - - - - - - - - - - + END_OF(LOC); +} +//================================================================================ +/*! + * \brief Return support + * \param meshName - name of the mesh the suppotr belongs to + * \param entity - support entity + * \retval SALOME_MED::SUPPORT_ptr - found support + * + * Raises if support not found + */ +//================================================================================ - END_OF(LOC); +SALOME_MED::SUPPORT_ptr MED_i::getSupport(string meshName, + MED_EN::medEntityMesh entity) + throw (SALOME::SALOME_Exception) +{ + map<string, map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> >::const_iterator + itSupportOnMesh = _supports.find(meshName); + if (itSupportOnMesh == _supports.end() ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "There is no support on mesh named |" + << meshName << "|")); + const map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr> & SupportOnMesh + = (*itSupportOnMesh).second; + map<MED_EN::medEntityMesh,SALOME_MED::SUPPORT_ptr>::const_iterator itSupport + = SupportOnMesh.find(entity); + if (itSupport == SupportOnMesh.end() ) + throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) + << "There is no support on entity " + << entity << " in mesh named |" + << meshName << "|")); + return SALOME_MED::SUPPORT::_duplicate( itSupport->second ); } //============================================================================= @@ -682,6 +633,7 @@ void MED_i::initWithFieldType(SALOMEDS::Study_ptr myStudy,driverTypes driverType MED_i::~MED_i() { } + //============================================================================= /*! * CORBA: Accessor for Number of meshes @@ -801,7 +753,7 @@ throw (SALOME::SALOME_Exception) { MESH * mesh=_med->getMesh(meshName); MESH_i * m1 = new MESH_i(mesh); - return m1->POA_SALOME_MED::MESH::_this(); + return m1->_this(); } catch (MEDEXCEPTION &ex) { @@ -824,7 +776,7 @@ throw (SALOME::SALOME_Exception) int ind=fieldPtr->getCorbaIndex(); SCRUTE(ind); - MESH * mesh; + MESH * mesh = 0; SALOME_MED::FIELDINT_var fieldint =SALOME_MED::FIELDINT::_narrow(fieldPtr); if (CORBA::is_nil(fieldint)) { @@ -836,7 +788,7 @@ throw (SALOME::SALOME_Exception) ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end()); ::FIELD<double> * fdouble = (::FIELD<double> *)FIELD_i::fieldMap[ind]; - MESH * mesh=_med->getMesh(fdouble); + mesh=_med->getMesh(fdouble); } else { @@ -844,10 +796,10 @@ throw (SALOME::SALOME_Exception) ASSERT(FIELD_i::fieldMap.find(ind)!=FIELD_i::fieldMap.end()); ::FIELD<int> * fint = (::FIELD<int> *)FIELD_i::fieldMap[ind]; - MESH * mesh=_med->getMesh(fint); + mesh=_med->getMesh(fint); } MESH_i * meshi = new MESH_i(mesh); - return meshi->POA_SALOME_MED::MESH::_this(); + return meshi->_this(); } //============================================================================= @@ -978,6 +930,7 @@ throw (SALOME::SALOME_Exception) return (*itMap_dtIt).second; } + //============================================================================= /*! * CORBA: Accessor for a specific field @@ -1183,10 +1136,10 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection) ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance(); ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); CORBA::ORB_var &orb = init(0,0); - string iorStr = orb->object_to_string(myIor); + CORBA::String_var iorStr = orb->object_to_string(myIor); anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - aIOR->SetValue(iorStr.c_str()); + aIOR->SetValue(iorStr.in()); anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue("Objet MED"); @@ -1203,18 +1156,21 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection) //============================================================================= /*! * CORBA: Add Med object in Study with a name medObjName + * + * FOR PERSISTANCE: if fileName is NULL string, looks for a SObject with a + * suitable name and bad IOR and update the IOR */ //============================================================================= -void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor, - const char * fileName) +void MED_i::addInStudy (SALOMEDS::Study_ptr myStudy, + SALOME_MED::MED_ptr myIor, + SALOMEDS::SComponent_ptr medfather, + const char * fileName) throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection) { BEGIN_OF("MED_i::addInStudy(myStudy, myIor, fileName)"); - if ( _medId != "" ) - { - MESSAGE("Med already in Study"); - THROW_SALOME_CORBA_EXCEPTION("Med already in Study", \ - SALOME::BAD_PARAM); + if ( _medId != "" ) { + MESSAGE("Med already in Study"); + THROW_SALOME_CORBA_EXCEPTION("Med already in Study", SALOME::BAD_PARAM); }; SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder(); @@ -1224,43 +1180,80 @@ void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor, SALOMEDS::AttributeIOR_var aIOR; // Create SComponent labelled 'MED' if it doesn't already exit - SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); + //SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED"); if ( CORBA::is_nil(medfather) ) { THROW_SALOME_CORBA_EXCEPTION("Component Med not found", SALOME::BAD_PARAM); }; - MESSAGE("Add a MED Object under Med"); - - char * medObjName; - string::size_type pos1=string(fileName).rfind('/'); - string::size_type lenFileName = strlen(fileName); - string fileNameShort = string(fileName,pos1+1,lenFileName-pos1-1); - - SCRUTE(fileNameShort); - - int lenName = 21 + strlen(fileNameShort.c_str()) + 1; - medObjName = new char[lenName]; - medObjName = strcpy(medObjName,"MED_OBJECT_FROM_FILE_"); - medObjName = strcat(medObjName,fileNameShort.c_str()); - - SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather); - + SALOMEDS::SObject_var medObj; + if ( ! fileName ) + { + // FOR PERSISTANCE: if fileName is a NULL string, + // looks for a SObject with a suitable name and + // bad IOR and update the IOR + SALOMEDS::ChildIterator_var anIter = myStudy->NewChildIterator( medfather ); + for ( ; anIter->More(); anIter->Next()) { + SALOMEDS::SObject_var obj = anIter->Value(); + // check name + CORBA::String_var name = obj->GetName(); + const char* suitableName1 = "MED_OBJECT_FROM_FILE_"; + const char* suitableName2 = "Objet MED"; + if ( strncmp( name, suitableName1, strlen(suitableName1)) == 0 || + strcmp( name, suitableName2 ) == 0 ) { + // check IOR + CORBA::String_var ior = obj->GetIOR(); + if ( strlen( ior ) == 0 ) { + medObj = obj; + break; + } + } + } + if ( medObj->_is_nil() ) + return; // nothing looking like MED found in the study + } + else + { + MESSAGE("Add a MED Object under the medfather"); + + char * medObjName; + string::size_type pos1=string(fileName).rfind('/'); + string::size_type lenFileName = strlen(fileName); + string fileNameShort = string(fileName,pos1+1,lenFileName-pos1-1); + + SCRUTE(fileNameShort); + + int lenName = 21 + strlen(fileNameShort.c_str()) + 1; + medObjName = new char[lenName]; + medObjName = strcpy(medObjName,"MED_OBJECT_FROM_FILE_"); + medObjName = strcat(medObjName,fileNameShort.c_str()); + + string path ("/"); + path += string(medfather->GetName()); + path += string("/"); + path += medObjName; + //string path = string("/Med/") + medObjName; + medObj = myStudy->FindObjectByPath(path.c_str()); + if ( medObj->_is_nil() ) + medObj = myBuilder->NewObject(medfather); + + anAttr = myBuilder->FindOrCreateAttribute(medObj, "AttributeName"); + aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue(medObjName); + + delete [] medObjName; + } ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance(); ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); CORBA::ORB_var &orb = init(0,0); string iorStr = orb->object_to_string(myIor); - anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); + anAttr = myBuilder->FindOrCreateAttribute(medObj, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); aIOR->SetValue(iorStr.c_str()); - anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(medObjName); - _medId = newObj->GetID(); - myBuilder->CommitCommand(); - delete [] medObjName; + _medId = medObj->GetID(); + myBuilder->CommitCommand(); // char * medObjName1; // lenName = 26 + strlen(fileNameShort.c_str()); @@ -1284,5 +1277,5 @@ void MED_i::addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor, MESSAGE("Registering of the Corba Med pointer"); Register(); - END_OF("Med_i::addInStudy(myStudy, myIor, medObjName)"); + END_OF("Med_i::addInStudy(myStudy, myIor, medfather, medObjName)"); } diff --git a/src/MEDMEM_I/MEDMEM_Med_i.hxx b/src/MEDMEM_I/MEDMEM_Med_i.hxx index e6bf5587e..76006af84 100644 --- a/src/MEDMEM_I/MEDMEM_Med_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Med_i.hxx @@ -27,6 +27,8 @@ #ifndef _MED_MED_I_HXX_ #define _MED_MED_I_HXX_ +#include <MEDMEM_I.hxx> + #include <string> #include <SALOMEconfig.h> @@ -41,7 +43,7 @@ namespace MEDMEM { typedef map<DT_IT_, SALOME_MED::FIELD_ptr, LT_DT_IT_ > MAP_IOR_DT_IT_; -class MED_i: public POA_SALOME_MED::MED, +class MEDMEM_I_EXPORT MED_i: public POA_SALOME_MED::MED, public SALOME::GenericObj_i { @@ -66,15 +68,20 @@ public: // MED_i(MED_i & m); ~MED_i(); - void init(SALOMEDS::Study_ptr myStudy, driverTypes driverType, const string & fileName); // Analyse the file <fileName> by calling readFileStruct + // Analyse the file <fileName> by calling readFileStruct + void init(SALOMEDS::Study_ptr myStudy, driverTypes driverType, const string & fileName); - void initWithFieldType(SALOMEDS::Study_ptr myStudy, driverTypes driverType, const string & fileName); // Same method as above but with storage of fields with their type + // Same method as above but with storage of fields with their type + void initWithFieldType(SALOMEDS::Study_ptr myStudy, driverTypes driverType, + const string & fileName, bool persistence=false); void addInStudy(SALOMEDS::Study_ptr myStudy, SALOME_MED::MED_ptr myIor, - const char * medObjName) + SALOMEDS::SComponent_ptr mySComp, const char * medObjName) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); - void updateSupportIORs(SALOMEDS::Study_ptr myStudy, const char* meshName); + SALOME_MED::SUPPORT_ptr getSupport(string meshName, + MED_EN::medEntityMesh entity) + throw (SALOME::SALOME_Exception); // IDL Methods diff --git a/src/MEDMEM_I/MEDMEM_Mesh_i.cxx b/src/MEDMEM_I/MEDMEM_Mesh_i.cxx index b3ba73519..714b3147c 100644 --- a/src/MEDMEM_I/MEDMEM_Mesh_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Mesh_i.cxx @@ -516,8 +516,13 @@ throw (SALOME::SALOME_Exception) try { - return _mesh->getNumberOfElements(convertIdlEntToMedEnt(entity), - convertIdlEltToMedElt(geomElement)); +// if ( geomElement == SALOME_MED::MED_POLYGON || +// geomElement == SALOME_MED::MED_POLYHEDRA ) +// return _mesh->getNumberOfElementsWithPoly(convertIdlEntToMedEnt(entity), +// convertIdlEltToMedElt(geomElement)); +// else + return _mesh->getNumberOfElements(convertIdlEntToMedEnt(entity), + convertIdlEltToMedElt(geomElement)); } catch (MEDEXCEPTION &ex) { @@ -561,10 +566,15 @@ SCRUTE(elt2); else { MESSAGE("MED_NODAL"); - const int * tab=_mesh->getConnectivityIndex( - convertIdlConnToMedConn(mode), - convertIdlEntToMedEnt(entity)); - nbelements = elt1*(convertIdlEltToMedElt(geomElement)%100); +// const int * tab=_mesh->getConnectivityIndex( +// convertIdlConnToMedConn(mode), +// convertIdlEntToMedEnt(entity)); + nbelements = _mesh->getConnectivityLength + (convertIdlModeToMedMode(typeSwitch), + convertIdlConnToMedConn(mode), + convertIdlEntToMedEnt(entity), + convertIdlEltToMedElt(geomElement)); + //nbelements = elt1*(convertIdlEltToMedElt(geomElement)%100); // nbelements = tab[elt1 ] - 1 ; } SCRUTE(entity); @@ -679,7 +689,7 @@ SALOME::SenderInt_ptr MESH_i::getSenderForPolygonsConnectivityIndex(SALOME_MED:: SALOME::SenderInt_ptr ret; try { - int nbelements = _mesh->getNumberOfPolygons() + 1; + int nbelements = _mesh->getNumberOfPolygons(entity) + 1; const int * numbers=_mesh->getPolygonsConnectivityIndex (convertIdlConnToMedConn(mode), convertIdlEntToMedEnt(entity)); ret=SenderFactory::buildSender(*this,numbers,nbelements); @@ -795,7 +805,7 @@ throw (SALOME::SALOME_Exception) { int nbelements = _mesh->getNumberOfElements( convertIdlEntToMedEnt(entity), - MED_ALL_ELEMENTS); + MED_ALL_ELEMENTS) + 1; myseq->length(nbelements); const int * numbers=_mesh->getConnectivityIndex(convertIdlConnToMedConn(mode), convertIdlEntToMedEnt(entity)); @@ -996,7 +1006,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbfam;i++) { FAMILY_i * f1=new FAMILY_i(fam[i]); - myseq[i] = f1->POA_SALOME_MED::FAMILY::_this(); + myseq[i] = f1->_this(); } } catch (MEDEXCEPTION &ex) @@ -1046,37 +1056,52 @@ throw (SALOME::SALOME_Exception) * CORBA: Returns connectivity global informations */ //============================================================================= -SALOME_MED::MESH::connectivityInfos * MESH_i::getConnectGlobal - (SALOME_MED::medEntityMesh entity) -throw (SALOME::SALOME_Exception) +SALOME_MED::MESH::connectivityInfos * MESH_i::getConnectGlobal (SALOME_MED::medEntityMesh entity) + throw (SALOME::SALOME_Exception) { - if (_mesh==NULL) - THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \ - SALOME::INTERNAL_ERROR); - SALOME_MED::MESH::connectivityInfos_var all=new SALOME_MED::MESH::connectivityInfos; - try - { - all->numberOfNodes = _mesh->getNumberOfNodes(); + if (_mesh==NULL) + THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \ + SALOME::INTERNAL_ERROR); + SALOME_MED::MESH::connectivityInfos_var all=new SALOME_MED::MESH::connectivityInfos; + try + { + MED_EN::medEntityMesh anEntity = convertIdlEntToMedEnt(entity); + all->numberOfNodes = _mesh->getNumberOfNodes(); - int nbTypes=_mesh->getNumberOfTypesWithPoly(convertIdlEntToMedEnt(entity)); - const medGeometryElement * elemts =_mesh->getTypesWithPoly( - convertIdlEntToMedEnt(entity)); - all->meshTypes.length(nbTypes); - all->numberOfElements.length(nbTypes); - all->entityDimension=_mesh->getConnectivityptr()->getEntityDimension(); - for (int i=0; i<nbTypes; i++) - { - all->meshTypes[i]=convertMedEltToIdlElt(elemts[i]); - all->numberOfElements[i]=_mesh->getNumberOfElementsWithPoly( - convertIdlEntToMedEnt(entity),elemts[i]); - } - } - catch (MEDEXCEPTION &ex) - { - MESSAGE("Unable to acces connectivities informations"); - THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); - } - return all._retn(); + int nbTypes=_mesh->getNumberOfTypesWithPoly(anEntity); + medGeometryElement * types =_mesh->getTypesWithPoly(anEntity); + all->meshTypes.length(nbTypes); + all->numberOfElements.length(nbTypes); + all->nodalConnectivityLength.length(nbTypes); + all->entityDimension=_mesh->getConnectivityptr()->getEntityDimension(); + for (int i=0; i<nbTypes; i++) + { + all->meshTypes[i]=convertMedEltToIdlElt(types[i]); + all->numberOfElements[i]=_mesh->getNumberOfElementsWithPoly(anEntity,types[i]); + switch ( types[i] ) + { + case MED_EN::MED_POLYGON: + all->nodalConnectivityLength[i]= + _mesh->getPolygonsConnectivityLength(MED_EN::MED_NODAL,anEntity); + break; + case MED_EN::MED_POLYHEDRA: + all->nodalConnectivityLength[i]= + _mesh->getPolyhedronConnectivityLength(MED_EN::MED_NODAL); + break; + default: + all->nodalConnectivityLength[i]= + _mesh->getConnectivityLength(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_NODAL, + anEntity,types[i]); + } + } + delete [] types; + } + catch (MEDEXCEPTION &ex) + { + MESSAGE("Unable to acces connectivities informations"); + THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); + } + return all._retn(); } //============================================================================= @@ -1095,7 +1120,7 @@ throw (SALOME::SALOME_Exception) { const FAMILY * fam = _mesh->getFamily(convertIdlEntToMedEnt(entity),i); FAMILY_i * f1=new FAMILY_i(fam); - return f1->POA_SALOME_MED::FAMILY::_this(); + return f1->_this(); } catch (MEDEXCEPTION &ex) { @@ -1131,7 +1156,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbFam;i++) { FAMILY_i * f1=new FAMILY_i(vNode[i]); - all->famNode[i] = f1->POA_SALOME_MED::FAMILY::_this(); + all->famNode[i] = f1->_this(); } nbFam = _mesh->getNumberOfFamilies(MED_EDGE); @@ -1142,7 +1167,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbFam;i++) { FAMILY_i * f1=new FAMILY_i(vEdge[i]); - all->famEdge[i] = f1->POA_SALOME_MED::FAMILY::_this(); + all->famEdge[i] = f1->_this(); } nbFam = _mesh->getNumberOfFamilies(MED_FACE); @@ -1152,7 +1177,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbFam;i++) { FAMILY_i * f1=new FAMILY_i(vFace[i]); - all->famFace[i] = f1->POA_SALOME_MED::FAMILY::_this(); + all->famFace[i] = f1->_this(); } nbFam = _mesh->getNumberOfFamilies(MED_CELL); @@ -1162,7 +1187,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbFam;i++) { FAMILY_i * f1=new FAMILY_i(vCell[i]); - all->famCell[i] = f1->POA_SALOME_MED::FAMILY::_this(); + all->famCell[i] = f1->_this(); } int nbGroup = _mesh->getNumberOfGroups(MED_NODE); @@ -1172,7 +1197,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbGroup;i++) { GROUP_i * f1=new GROUP_i(gNode[i]); - all->groupNode[i] = f1->POA_SALOME_MED::GROUP::_this(); + all->groupNode[i] = f1->_this(); } nbGroup = _mesh->getNumberOfGroups(MED_EDGE); @@ -1182,7 +1207,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbGroup;i++) { GROUP_i * f1=new GROUP_i(gEdge[i]); - all->groupEdge[i] = f1->POA_SALOME_MED::GROUP::_this(); + all->groupEdge[i] = f1->_this(); } nbGroup = _mesh->getNumberOfGroups(MED_FACE); all->groupFace.length(nbGroup); @@ -1191,7 +1216,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbGroup;i++) { GROUP_i * f1=new GROUP_i(gFace[i]); - all->groupFace[i] = f1->POA_SALOME_MED::GROUP::_this(); + all->groupFace[i] = f1->_this(); } nbGroup = _mesh->getNumberOfGroups(MED_CELL); @@ -1201,7 +1226,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbGroup;i++) { GROUP_i * f1=new GROUP_i(gCell[i]); - all->groupCell[i] = f1->POA_SALOME_MED::GROUP::_this(); + all->groupCell[i] = f1->_this(); } } @@ -1233,7 +1258,7 @@ throw (SALOME::SALOME_Exception) for (int i=0;i<nbgroups;i++) { GROUP_i * f1=new GROUP_i(groups[i]); - myseq[i] = f1->POA_SALOME_MED::GROUP::_this(); + myseq[i] = f1->_this(); } } catch (MEDEXCEPTION &ex) @@ -1259,7 +1284,7 @@ throw (SALOME::SALOME_Exception) { const GROUP * grou = _mesh->getGroup(convertIdlEntToMedEnt(entity),i); GROUP_i * f1=new GROUP_i(grou); - return f1->POA_SALOME_MED::GROUP::_this(); + return f1->_this(); } catch (MEDEXCEPTION &ex) { @@ -1457,6 +1482,7 @@ throw (SALOME::SALOME_Exception) THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \ SALOME::INTERNAL_ERROR); MESSAGE("Not Implemented"); + return SALOME_MED::FIELD::_nil(); } //============================================================================= /*! @@ -1498,29 +1524,36 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection) // } ; - SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath("/Med/MEDMESH"); + string aPath = "/Med/MEDMESH"; + SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath( aPath.c_str() ); if ( CORBA::is_nil(medmeshfather) ) { MESSAGE("Add Object MEDMESH"); - myBuilder->AddDirectory("/Med/MEDMESH"); - medmeshfather = myStudy->FindObjectByPath("/Med/MEDMESH"); + myBuilder->AddDirectory( aPath.c_str() ); + medmeshfather = myStudy->FindObjectByPath( aPath.c_str() ); } ; - MESSAGE("Add a mesh Object under MED/MEDMESH"); - SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather); + aPath += "/" + _mesh->getName(); + SALOMEDS::SObject_var meshSO = myStudy->FindObjectByPath( aPath.c_str()); + bool alreadyPublished = ! CORBA::is_nil( meshSO ); + if ( !alreadyPublished ) { + MESSAGE("Add a mesh Object under MED/MEDMESH"); + meshSO = myBuilder->NewObject(medmeshfather); + + anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeName"); + aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue(_mesh->getName().c_str()); + } ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; CORBA::ORB_var &orb = init(0,0); string iorStr = orb->object_to_string(myIor); - anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); + anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); aIOR->SetValue(iorStr.c_str()); - anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(_mesh->getName().c_str()); - _meshId = newObj->GetID(); + _meshId = meshSO->GetID(); myBuilder->CommitCommand(); // register the Corba pointer: increase the referrence count @@ -1576,10 +1609,10 @@ throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection) ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; CORBA::ORB_var &orb = init(0,0); - string iorStr = orb->object_to_string(myIor); + CORBA::String_var iorStr = orb->object_to_string(myIor); anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - aIOR->SetValue(iorStr.c_str()); + aIOR->SetValue(iorStr.in()); anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(_mesh->getName().c_str()); diff --git a/src/MEDMEM_I/MEDMEM_Mesh_i.hxx b/src/MEDMEM_I/MEDMEM_Mesh_i.hxx index 45ca0eace..965b6afc8 100644 --- a/src/MEDMEM_I/MEDMEM_Mesh_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Mesh_i.hxx @@ -27,6 +27,8 @@ #ifndef _MED_MESH_I_HXX_ #define _MED_MESH_I_HXX_ +#include <MEDMEM_I.hxx> + #include <map> #include <string> @@ -39,9 +41,9 @@ namespace MEDMEM { class MESH; -class MESH_i: public POA_SALOME_MED::MESH, - public SALOMEMultiComm, - public SALOME::GenericObj_i +class MEDMEM_I_EXPORT MESH_i: virtual public POA_SALOME_MED::MESH, + virtual public SALOMEMultiComm, + virtual public SALOME::GenericObj_i { public : static std::map < int,::MEDMEM::MESH *> meshMap; diff --git a/src/MEDMEM_I/MEDMEM_Support_i.cxx b/src/MEDMEM_I/MEDMEM_Support_i.cxx index e94d16e46..6f2095724 100644 --- a/src/MEDMEM_I/MEDMEM_Support_i.cxx +++ b/src/MEDMEM_I/MEDMEM_Support_i.cxx @@ -34,6 +34,7 @@ #include "MEDMEM_define.hxx" #include "MEDMEM_Support.hxx" +#include "MEDMEM_Mesh.hxx" #include "MEDMEM_Support_i.hxx" #include "MEDMEM_Mesh_i.hxx" @@ -161,35 +162,84 @@ throw (SALOME::SALOME_Exception) //============================================================================= SALOME_MED::SUPPORT::supportInfos * SUPPORT_i::getSupportGlobal() -throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (_support==NULL) - THROW_SALOME_CORBA_EXCEPTION("No associated Support", \ - SALOME::INTERNAL_ERROR); - SALOME_MED::SUPPORT::supportInfos_var all = new SALOME_MED::SUPPORT::supportInfos; - try - { - all->name = CORBA::string_dup(_support->getName().c_str()); - all->description = CORBA::string_dup(_support->getDescription().c_str()); - const int numberOfTypes = _support->getNumberOfTypes(); - all->numberOfGeometricType = numberOfTypes; - all->entity = _support->getEntity(); - all->isOnAllElements = _support->isOnAllElements(); - all->types.length(numberOfTypes); - all->nbEltTypes.length(numberOfTypes); - const medGeometryElement * elemts = _support->getTypes(); - for (int i=0;i<numberOfTypes;i++) - { - all->types[i] = convertMedEltToIdlElt(elemts[i]); - all->nbEltTypes[i] = _support->getNumberOfElements(elemts[i]); - } + if (_support==NULL) + THROW_SALOME_CORBA_EXCEPTION("No associated Support", \ + SALOME::INTERNAL_ERROR); + SALOME_MED::SUPPORT::supportInfos_var all = new SALOME_MED::SUPPORT::supportInfos; + try + { + all->name = CORBA::string_dup(_support->getName().c_str()); + all->description = CORBA::string_dup(_support->getDescription().c_str()); + const int numberOfTypes = _support->getNumberOfTypes(); + all->numberOfGeometricType = numberOfTypes; + all->entity = _support->getEntity(); + all->isOnAllElements = _support->isOnAllElements(); + all->types.length(numberOfTypes); + all->nbEltTypes.length(numberOfTypes); + all->nodalConnectivityLength.length(numberOfTypes); + const medGeometryElement * types = _support->getTypes(); + for (int i=0;i<numberOfTypes;i++) + { + int nbelements = _support->getNumberOfElements(types[i]); + int connLength = 0; + MESH* mesh = _support->getMesh(); + switch ( types[i] ) + { + case MED_EN::MED_POLYGON: { + if (_support->isOnAllElements() ) { + connLength = mesh->getPolygonsConnectivityLength(MED_EN::MED_NODAL, + _support->getEntity()); } - catch (MEDEXCEPTION &ex) - { - MESSAGE("Unable to access the description of the support "); - THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); + else { + const int * index = mesh->getPolygonsConnectivityIndex(MED_EN::MED_NODAL, + _support->getEntity()); + const int * numbers=_support->getNumber(types[i]); + int canonicNb = mesh->getNumberOfElements(_support->getEntity(), + MED_EN::MED_ALL_ELEMENTS); + for (int j=0;j<nbelements;j++) + { + int elem = numbers[j]-canonicNb-1; + connLength += index[ elem+1 ] - index[ elem ]; + } + } + break; + } + case MED_EN::MED_POLYHEDRA: { + if (_support->isOnAllElements() ) { + connLength = mesh->getPolyhedronConnectivityLength(MED_EN::MED_NODAL); } - return all._retn(); + else { + const int * index = mesh->getPolyhedronIndex(MED_EN::MED_NODAL); + const int * faceIndex = mesh->getPolyhedronFacesIndex(); + const int * numbers=_support->getNumber(types[i]); + int canonicNb = mesh->getNumberOfElements(_support->getEntity(), + MED_EN::MED_ALL_ELEMENTS); + for (int j=0;j<nbelements;j++) + { + int elem = numbers[j]-canonicNb-1 ; + int f1 = index[ elem ]-1, f2 = index[ elem+1 ]-2; + int i1 = faceIndex[ f1 ]-1, i2 = faceIndex[ f2+1 ]-1; + connLength += i2 - i1; + } + } + break; + } + default: + connLength = nbelements * ( types[i] % 100 ); + } + all->types[i] = convertMedEltToIdlElt(types[i]); + all->nbEltTypes[i] = nbelements; + all->nodalConnectivityLength[i] = connLength; + } + } + catch (MEDEXCEPTION &ex) + { + MESSAGE("Unable to access the description of the support "); + THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); + } + return all._retn(); } @@ -215,7 +265,7 @@ throw (SALOME::SALOME_Exception) SCRUTE(mesh) ; MESH_i * m1 = new MESH_i(mesh); - SALOME_MED::MESH_ptr m2 = m1->POA_SALOME_MED::MESH::_this(); + SALOME_MED::MESH_ptr m2 = m1->_this(); MESSAGE("SALOME_MED::MESH_ptr SUPPORT_i::getMesh() checking des pointeurs CORBA"); SCRUTE(m1); @@ -404,6 +454,45 @@ SCRUTE(numbers[i]); } +//============================================================================= +/*! + * CORBA: get Nodes from file + */ +//============================================================================= +SALOME_MED::long_array * SUPPORT_i::getNumberFromFile(SALOME_MED::medGeometryElement geomElement) +throw (SALOME::SALOME_Exception) +{ + SCRUTE(_support); + SCRUTE(geomElement); + SCRUTE(convertIdlEltToMedElt(geomElement)); + + if (_support==NULL) + THROW_SALOME_CORBA_EXCEPTION("No associated Support", \ + SALOME::INTERNAL_ERROR); + SALOME_MED::long_array_var myseq= new SALOME_MED::long_array; + try + { + int nbelements=_support->getNumberOfElements(convertIdlEltToMedElt(geomElement)); + myseq->length(nbelements); +SCRUTE(_support->getName()); +SCRUTE(nbelements); +SCRUTE(convertIdlEltToMedElt(geomElement)); + const int * numbers=_support->getNumberFromFile(convertIdlEltToMedElt(geomElement)); + for (int i=0;i<nbelements;i++) + { + myseq[i]=numbers[i]; +SCRUTE(numbers[i]); + } + } + catch (MEDEXCEPTION &ex) + { + MESSAGE("Unable to access the support optionnal index"); + THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR); + } + return myseq._retn(); + +} + //============================================================================= /*! * CORBA: 2nd get Nodes @@ -512,14 +601,13 @@ throw (SALOME::SALOME_Exception) { (const_cast< ::SUPPORT *>(_support))->getBoundaryElements(); } - catch (MEDEXCEPTION &ex) + catch (MEDEXCEPTION &) { MESSAGE("Unable to access elements"); THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\ ,SALOME::INTERNAL_ERROR); } } - //============================================================================= /*! * CORBA: add the Support in the StudyManager @@ -569,7 +657,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr } MESSAGE(LOC << " Find SObject MESH (represent mesh in support)"); - string meshName = getMesh()->getName() ; + string meshName = _support->getMesh()->getName() ; string meshNameStudy = meshName; for (string::size_type pos=0; pos<meshNameStudy.size();++pos) @@ -583,7 +671,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr THROW_SALOME_CORBA_EXCEPTION("SObject Mesh in Support not Found",SALOME::INTERNAL_ERROR); // perhaps add MESH automatically ? - MESSAGE("Add a support Object under /MED/MESH/MESHNAME"); + MESSAGE("Add a support Object under /Med/MESH/MESHNAME"); char * medsupfatherName; int lenName = 15 + strlen(meshName.c_str()) + 1; @@ -606,28 +694,11 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr //myBuilder->NewCommand(); - string supportName = _support->getName(); - - SCRUTE(supportName); - - SCRUTE(meshNameStudy); + string supportEntryPath = getEntryPath( _support ); - char * supportEntryPath; - lenName = 13 + 15 + strlen(meshName.c_str()) + 1 + strlen(supportName.c_str())+1; - supportEntryPath = new char[lenName]; - supportEntryPath = strcpy(supportEntryPath,"/Med/MEDMESH/"); - supportEntryPath = strcat(supportEntryPath,"MEDSUPPORTS_OF_"); - supportEntryPath = strcat(supportEntryPath,meshNameStudy.c_str()); - supportEntryPath = strcat(supportEntryPath,"/"); - supportEntryPath = strcat(supportEntryPath,supportName.c_str()); + SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath.c_str()); - //SCRUTE(supportEntryPath); - MESSAGE("supportEntryPath in support " << supportEntryPath << " length " << lenName); - -// SALOMEDS::SObject_var supportEntry = myStudy->FindObject(_support->getName().c_str()); - // c'est pas bon, car il faut rechercher uniquement sous le bon MESH !!! - SALOMEDS::SObject_var supportEntry = myStudy->FindObjectByPath(supportEntryPath); if ( CORBA::is_nil(supportEntry) ) { @@ -637,10 +708,10 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; CORBA::ORB_var &orb = init(0,0); - string iorStr = orb->object_to_string(myIor); + CORBA::String_var iorStr = orb->object_to_string(myIor); anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - aIOR->SetValue(iorStr.c_str()); + aIOR->SetValue(iorStr.in()); anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(_support->getName().c_str()); @@ -652,14 +723,14 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ; ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ; CORBA::ORB_var &orb = init(0,0); - string iorStr = orb->object_to_string(myIor); + CORBA::String_var iorStr = orb->object_to_string(myIor); anAttr = myBuilder->FindOrCreateAttribute(supportEntry, "AttributeIOR"); aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - aIOR->SetValue(iorStr.c_str()); + aIOR->SetValue(iorStr.in()); } myBuilder->CommitCommand(); - SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath); + SALOMEDS::SObject_var supportEntryBis = myStudy->FindObjectByPath(supportEntryPath.c_str()); MESSAGE("Just for checking, reuse of the corba pointer"); @@ -673,7 +744,7 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr } delete [] medsupfatherName; - delete [] supportEntryPath; + // register the Corba pointer: increase the referrence count MESSAGE("Registering of the Corba Support pointer"); @@ -681,3 +752,23 @@ void SUPPORT_i::addInStudy (SALOMEDS::Study_ptr myStudy, SALOME_MED::SUPPORT_ptr END_OF(LOC); } + +//======================================================================= +//function : getEntryPath +//purpose : +//======================================================================= + +string SUPPORT_i::getEntryPath(const ::MEDMEM::SUPPORT * aSupport) +{ + string meshNameStudy( aSupport->getMeshName() ); + for (string::size_type pos=0; pos<meshNameStudy.size();++pos) + if (isspace(meshNameStudy[pos])) meshNameStudy[pos] = '_'; + + string supportName = aSupport->getName(); + string supportNameStudy( supportName.c_str(), strlen( supportName.c_str() )); + string supportEntryPath = + "/Med/MEDMESH/MEDSUPPORTS_OF_" + meshNameStudy + "/" + supportNameStudy; + SCRUTE( supportEntryPath ); + + return supportEntryPath; +} diff --git a/src/MEDMEM_I/MEDMEM_Support_i.hxx b/src/MEDMEM_I/MEDMEM_Support_i.hxx index 5400b8e92..12351cd52 100644 --- a/src/MEDMEM_I/MEDMEM_Support_i.hxx +++ b/src/MEDMEM_I/MEDMEM_Support_i.hxx @@ -27,6 +27,8 @@ #ifndef _MED_SUPPORT_I_HXX_ #define _MED_SUPPORT_I_HXX_ +#include "MEDMEM_I.hxx" + #include <map> #include <string> @@ -40,9 +42,9 @@ namespace MEDMEM { class SUPPORT; - class SUPPORT_i: public POA_SALOME_MED::SUPPORT, - public SALOMEMultiComm, - public SALOME::GenericObj_i +class MEDMEM_I_EXPORT SUPPORT_i: virtual public POA_SALOME_MED::SUPPORT, + virtual public SALOMEMultiComm, + virtual public SALOME::GenericObj_i { public : static std::map < int,::MEDMEM::SUPPORT *> supportMap; @@ -77,6 +79,10 @@ public: throw (SALOME::SALOME_Exception); SALOME_MED::long_array* getNumber(SALOME_MED::medGeometryElement geomElement) throw (SALOME::SALOME_Exception); + + SALOME_MED::long_array* getNumberFromFile(SALOME_MED::medGeometryElement geomElement) + throw (SALOME::SALOME_Exception); + SALOME::SenderInt_ptr getSenderForNumber(SALOME_MED::medGeometryElement geomElement) throw (SALOME::SALOME_Exception); SALOME_MED::long_array* getNumberIndex() @@ -99,8 +105,7 @@ public: SALOME_MED::SUPPORT_ptr myIor) throw (SALOME::SALOME_Exception, SALOMEDS::StudyBuilder::LockProtection); - static std::string getEntryPath (const std::string& aMeshName, - const ::MEDMEM::SUPPORT * aSupport); + static std::string getEntryPath (const MEDMEM::SUPPORT * aSupport); void release(); // Cuisine interne diff --git a/src/MEDMEM_I/MEDMEM_TraitsForFields.hxx b/src/MEDMEM_I/MEDMEM_TraitsForFields.hxx index f83a3b15d..977001310 100644 --- a/src/MEDMEM_I/MEDMEM_TraitsForFields.hxx +++ b/src/MEDMEM_I/MEDMEM_TraitsForFields.hxx @@ -64,6 +64,19 @@ struct FIELDI_TRAITS<double, NoInterlace> typedef SALOME::SenderDouble_var SenderVarType; }; +template < > +struct FIELDI_TRAITS<double, NoInterlaceByType> +{ + typedef POA_SALOME_MED::FIELDDOUBLENOBYTYPE InterfaceForServant; + typedef SALOME_MED::FIELDDOUBLENOBYTYPE_ptr FieldCorbaPtrType; + typedef SALOME_MED::FIELDDOUBLE_ptr SimpleFieldCorbaPtrType; + typedef SALOME_MED::FIELDDOUBLE SimpleFieldGlobalType; + typedef SALOME_MED::double_array SeqType; + typedef SALOME_MED::double_array_var SeqVarType; + typedef SALOME::SenderDouble_ptr SenderPtrType; + typedef SALOME::SenderDouble_var SenderVarType; +}; + template < > struct FIELDI_TRAITS<int, FullInterlace> { @@ -89,6 +102,19 @@ struct FIELDI_TRAITS<int, NoInterlace> typedef SALOME::SenderInt_ptr SenderPtrType; typedef SALOME::SenderInt_var SenderVarType; }; + +template < > +struct FIELDI_TRAITS<int, NoInterlaceByType> +{ + typedef POA_SALOME_MED::FIELDINTNOBYTYPE InterfaceForServant; + typedef SALOME_MED::FIELDINTNOBYTYPE_ptr FieldCorbaPtrType; + typedef SALOME_MED::FIELDINT_ptr SimpleFieldCorbaPtrType; + typedef SALOME_MED::FIELDINT SimpleFieldGlobalType; + typedef SALOME_MED::long_array SeqType; + typedef SALOME_MED::long_array_var SeqVarType; + typedef SALOME::SenderInt_ptr SenderPtrType; + typedef SALOME::SenderInt_var SenderVarType; +}; } #endif diff --git a/src/MEDMEM_I/MEDMEM_convert.cxx b/src/MEDMEM_I/MEDMEM_convert.cxx index d4b98d83d..09e20ad4d 100644 --- a/src/MEDMEM_I/MEDMEM_convert.cxx +++ b/src/MEDMEM_I/MEDMEM_convert.cxx @@ -139,8 +139,9 @@ throw (SALOME::SALOME_Exception) { switch (mode) { - case SALOME_MED::MED_FULL_INTERLACE : return MED_FULL_INTERLACE; - case SALOME_MED::MED_NO_INTERLACE : return MED_NO_INTERLACE; + case SALOME_MED::MED_FULL_INTERLACE : return MED_FULL_INTERLACE; + case SALOME_MED::MED_NO_INTERLACE : return MED_NO_INTERLACE; + case SALOME_MED::MED_NO_INTERLACE_BY_TYPE : return MED_NO_INTERLACE_BY_TYPE; default : { MESSAGE("Unknown interlace mode"); THROW_SALOME_CORBA_EXCEPTION("Unknown interlace mode", @@ -154,8 +155,9 @@ throw (SALOME::SALOME_Exception) { switch (mode) { - case MED_FULL_INTERLACE : return SALOME_MED::MED_FULL_INTERLACE; - case MED_NO_INTERLACE : return SALOME_MED::MED_NO_INTERLACE; + case MED_FULL_INTERLACE : return SALOME_MED::MED_FULL_INTERLACE; + case MED_NO_INTERLACE : return SALOME_MED::MED_NO_INTERLACE; + case MED_NO_INTERLACE_BY_TYPE : return SALOME_MED::MED_NO_INTERLACE_BY_TYPE; default : { MESSAGE("Unknown interlace mode"); THROW_SALOME_CORBA_EXCEPTION("Unknown interlace mode", diff --git a/src/MEDMEM_I/MEDMEM_convert.hxx b/src/MEDMEM_I/MEDMEM_convert.hxx index e8d2c3008..55d14f99c 100644 --- a/src/MEDMEM_I/MEDMEM_convert.hxx +++ b/src/MEDMEM_I/MEDMEM_convert.hxx @@ -27,6 +27,8 @@ # if ! defined ( __CONVERT_H__ ) # define __CONVERT_H__ +#include "MEDMEM_I.hxx" + #include <SALOMEconfig.h> #include CORBA_SERVER_HEADER(MED) #include "MEDMEM_define.hxx" @@ -35,30 +37,30 @@ using namespace MED_EN; #include "MEDMEM_GenDriver.hxx" -SALOME_MED::medGeometryElement convertMedEltToIdlElt(medGeometryElement element) +MEDMEM_I_EXPORT SALOME_MED::medGeometryElement convertMedEltToIdlElt(medGeometryElement element) throw (SALOME::SALOME_Exception); -SALOME_MED::medEntityMesh convertMedEntToIdlEnt(medEntityMesh entity) +MEDMEM_I_EXPORT SALOME_MED::medEntityMesh convertMedEntToIdlEnt(medEntityMesh entity) throw (SALOME::SALOME_Exception); -SALOME_MED::medModeSwitch convertMedModeToIdlMode(medModeSwitch mode) +MEDMEM_I_EXPORT SALOME_MED::medModeSwitch convertMedModeToIdlMode(medModeSwitch mode) throw (SALOME::SALOME_Exception); -SALOME_MED::medDriverTypes convertMedDriverToIdlDriver(MEDMEM::driverTypes driverType) +MEDMEM_I_EXPORT SALOME_MED::medDriverTypes convertMedDriverToIdlDriver(MEDMEM::driverTypes driverType) throw (SALOME::SALOME_Exception); -SALOME_MED::medConnectivity convertMedConnToIdlConn(medConnectivity connectivite) +MEDMEM_I_EXPORT SALOME_MED::medConnectivity convertMedConnToIdlConn(medConnectivity connectivite) throw (SALOME::SALOME_Exception); -medGeometryElement convertIdlEltToMedElt (SALOME_MED::medGeometryElement element) +MEDMEM_I_EXPORT medGeometryElement convertIdlEltToMedElt (SALOME_MED::medGeometryElement element) throw (SALOME::SALOME_Exception); -medEntityMesh convertIdlEntToMedEnt(SALOME_MED::medEntityMesh entity) +MEDMEM_I_EXPORT medEntityMesh convertIdlEntToMedEnt(SALOME_MED::medEntityMesh entity) throw (SALOME::SALOME_Exception); -medModeSwitch convertIdlModeToMedMode(SALOME_MED::medModeSwitch mode) +MEDMEM_I_EXPORT medModeSwitch convertIdlModeToMedMode(SALOME_MED::medModeSwitch mode) throw (SALOME::SALOME_Exception); -MEDMEM::driverTypes convertIdlDriverToMedDriver(SALOME_MED::medDriverTypes driverType) +MEDMEM_I_EXPORT MEDMEM::driverTypes convertIdlDriverToMedDriver(SALOME_MED::medDriverTypes driverType) throw (SALOME::SALOME_Exception); -medConnectivity convertIdlConnToMedConn(SALOME_MED::medConnectivity connectivite) +MEDMEM_I_EXPORT medConnectivity convertIdlConnToMedConn(SALOME_MED::medConnectivity connectivite) throw (SALOME::SALOME_Exception); -bool verifieParam (SALOME_MED::medEntityMesh entity, SALOME_MED::medGeometryElement geomElement) +MEDMEM_I_EXPORT bool verifieParam (SALOME_MED::medEntityMesh entity, SALOME_MED::medGeometryElement geomElement) throw (SALOME::SALOME_Exception); # endif /* # if ! defined ( __CONVERT_H__ ) */ diff --git a/src/MEDMEM_I/Makefile.am b/src/MEDMEM_I/Makefile.am new file mode 100644 index 000000000..626d9419e --- /dev/null +++ b/src/MEDMEM_I/Makefile.am @@ -0,0 +1,57 @@ +# MED MEDMEM_I : MED idl descriptions implementation based on the classes of MEDMEM +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDMEMImpl.la + +salomeinclude_HEADERS= \ + MEDMEM_convert.hxx \ + MEDMEM_Med_i.hxx \ + MEDMEM_Family_i.hxx \ + MEDMEM_FieldTemplate_i.hxx \ + MEDMEM_TraitsForFields.hxx \ + MEDMEM_Field_i.hxx \ + MEDMEM_Group_i.hxx \ + MEDMEM_Mesh_i.hxx \ + MEDMEM_Support_i.hxx \ + MEDMEM_I.hxx + +dist_libMEDMEMImpl_la_SOURCES= \ + MEDMEM_Med_i.cxx \ + MEDMEM_Family_i.cxx \ + MEDMEM_Field_i.cxx \ + MEDMEM_Group_i.cxx \ + MEDMEM_Mesh_i.cxx \ + MEDMEM_Support_i.cxx \ + MEDMEM_convert.cxx + +libMEDMEMImpl_la_CPPFLAGS= $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} \ + -I$(srcdir)/../MEDMEM -I$(top_builddir)/idl -I$(top_builddir)/salome_adm/unix -I$(srcdir)/../MEDWrapper/V2_1/Core +libMEDMEMImpl_la_LDFLAGS= \ + ../../idl/libSalomeIDLMED.la \ + ../MEDMEM/libmedmem.la \ + ${KERNEL_LDFLAGS} -lSalomeLifeCycleCORBA -lSALOMELocalTrace -lSalomeCommunication -lSalomeGenericObj -lSalomeNS \ + $(MED2_LIBS) \ + $(HDF5_LIBS) diff --git a/src/MEDMEM_I/Makefile.in b/src/MEDMEM_I/Makefile.in deleted file mode 100644 index e8123beef..000000000 --- a/src/MEDMEM_I/Makefile.in +++ /dev/null @@ -1,76 +0,0 @@ -# MED MEDMEM_I : MED idl descriptions implementation based on the classes of MEDMEM -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# Author : Marc Tajchman -# Module : MED -# $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/Makefile.in - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_builddir)/idl - -MACHINE=PCLINUX - -@COMMENCE@ - - -#EXPORT_PYSCRIPTS = \ -# testMed.py - -EXPORT_HEADERS = \ - MEDMEM_convert.hxx \ - MEDMEM_Med_i.hxx \ - MEDMEM_Family_i.hxx \ - MEDMEM_FieldTemplate_i.hxx \ - MEDMEM_TraitsForFields.hxx \ - MEDMEM_Field_i.hxx \ - MEDMEM_Group_i.hxx \ - MEDMEM_Mesh_i.hxx \ - MEDMEM_Support_i.hxx - -# Libraries targets - -LIB=libMEDMEMImpl.la -LIB_SRC = MEDMEM_Med_i.cxx MEDMEM_Family_i.cxx MEDMEM_Field_i.cxx MEDMEM_Group_i.cxx MEDMEM_Mesh_i.cxx MEDMEM_Support_i.cxx MEDMEM_convert.cxx -LIB_SERVER_IDL = MED.idl -LIB_CLIENT_IDL= SALOME_Component.idl SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Exception.idl SALOME_Comm.idl SALOME_GenericObj.idl - -# Executables targets -BIN_SRC = -BIN_SERVER_IDL = -BIN_CLIENT_IDL = - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS+= $(MED2_INCLUDES) $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} -CXXFLAGS+= ${KERNEL_CXXFLAGS} -LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lmedmem ${KERNEL_LDFLAGS} -lSALOMELocalTrace -lSalomeCommunication -lSalomeGenericObj -#LDFLAGS+=-lmedmem -L. -lSalomeContainer -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -# does we put only -lSalomeContainer and compiler retrieves -lSalomeNS -lRegistry -lOpUtil ???? - -MED.hh MEDSK.cc: MED.idl - omniidl -bcxx -Wbtp -I$(top_builddir)/idl -I${KERNEL_ROOT_DIR}/idl/salome $^ - -@CONCLUDE@ diff --git a/src/MEDMEM_SWIG/MEDMEM_SWIG_Templates.hxx b/src/MEDMEM_SWIG/MEDMEM_SWIG_Templates.hxx index cbfb16476..2d7f22503 100644 --- a/src/MEDMEM_SWIG/MEDMEM_SWIG_Templates.hxx +++ b/src/MEDMEM_SWIG/MEDMEM_SWIG_Templates.hxx @@ -45,37 +45,41 @@ template<> static int Traducer(PyObject *a) { return (int) PyInt_AsLong(a); } static PyObject * Traducer( int value ) { return Py_BuildValue("i", value ); } static int Functor(PyObject *func, int value) - { return Traducer( PyObject_CallFunction( func, "f", value )); } + { return Traducer( PyObject_CallFunction( func, "i", value )); } }; -template<class T> +template<class T, class U> class MyFunction { public: static PyObject *_pyFunc; static int _nbOfComponent; static int _spaceDim; - static void EvalPy2Cpp(const double *coord, T* outputValues) + static void EvalPy2Cpp(const U *coord, T* outputValues) { int i=0,err; PyObject * tuple=PyTuple_New(_spaceDim); for(i=0;i<_spaceDim;i++) { - err=PyTuple_SetItem(tuple,i,Py_BuildValue("d",coord[i])); + err=PyTuple_SetItem(tuple,i,Binding<U>::Traducer(coord[i])); if (err != 0) throw MEDMEM::MEDEXCEPTION("Internal Error in createFieldDoubleFromAnalytic"); } PyObject * function_ret = PyObject_CallObject(_pyFunc,tuple); + if ( !function_ret ) + { + throw MEDMEM::MEDEXCEPTION(MEDMEM::STRING("Internal Error in createFieldIntFromAnalytic : the call to the user callable fonction has failed (possibly wrong nb of arguments that must be equal to space dimension = ")<< _spaceDim << ")"); + } err = PyList_Check(function_ret); if (!err) { Py_DECREF(function_ret); - throw MEDMEM::MEDEXCEPTION("Internal Error in createFieldIntFromAnalytic : the call to the user callable fonction has failed (check its API list of integer fonct (double, double))"); + throw MEDMEM::MEDEXCEPTION("Internal Error in createFieldIntFromAnalytic : the call to the user callable fonction has failed (its return value must be a list"); } int size=PyList_Size(function_ret); if (size!=_nbOfComponent) { Py_DECREF(function_ret); - throw MEDMEM::MEDEXCEPTION("Internal Error in createFieldIntFromAnalytic : the call to the user callable fonction has failed (check its API list of integer fonct (double, double), especially the size of the returned list)"); + throw MEDMEM::MEDEXCEPTION(MEDMEM::STRING("Internal Error in createFieldIntFromAnalytic : the call to the user callable fonction has failed (its return value must be a list of size equal to _nbOfComponent = ") << _nbOfComponent << ")"); } for(i=0;i<_nbOfComponent;i++) { @@ -84,20 +88,20 @@ template<class T> if (!err) { Py_DECREF(function_ret); - throw MEDMEM::MEDEXCEPTION("Internal Error in createFieldDoubleFromAnalytic : the call to the user callable fonction has failed (check its API list of double fonct (double, double), especially the type of the returned list)"); + throw MEDMEM::MEDEXCEPTION("Internal Error in createFieldDoubleFromAnalytic : the call to the user callable fonction has failed (check its return value type)"); } outputValues[i]=Binding<T>::Traducer(tmp); } } }; -template<class T> -PyObject *MyFunction<T>::_pyFunc=0; +template<class T, class U> +PyObject *MyFunction<T,U>::_pyFunc=0; -template<class T> -int MyFunction<T>::_nbOfComponent=0; +template<class T, class U> +int MyFunction<T,U>::_nbOfComponent=0; -template<class T> -int MyFunction<T>::_spaceDim=0; +template<class T, class U> +int MyFunction<T,U>::_spaceDim=0; #endif diff --git a/src/MEDMEM_SWIG/Makefile.am b/src/MEDMEM_SWIG/Makefile.am new file mode 100644 index 000000000..88f889716 --- /dev/null +++ b/src/MEDMEM_SWIG/Makefile.am @@ -0,0 +1,93 @@ +# MED MEDMEM_SWIG : binding of C++ implementation and Python +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDMEM_Swigcmodule.la + +salomeinclude_HEADERS= \ + libMEDMEM_Swig.i \ + my_typemap.i \ + MEDMEM_SWIG_Templates.hxx + +if MED_SWIG_1_3_21 +SWIG_DEF= libMEDMEM_Swig.i dummy.i + +dummy_wrap.cxx: libMEDMEM_Swig_wrap.cxx + sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libMEDMEM_Swig_wrap.cxx > toto + mv toto libMEDMEM_Swig_wrap.cxx + sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libMEDMEM_Swig_wrap.cxx > toto + mv toto libMEDMEM_Swig_wrap.cxx + touch dummy_wrap.cxx +else !MED_SWIG_1_3_21 +SWIG_DEF= libMEDMEM_Swig.i +endif + +SWIG_FLAGS=@SWIG_FLAGS@ -I$(srcdir) + +nodist_libMEDMEM_Swigcmodule_la_SOURCES= libMEDMEM_Swig_wrap.cxx +libMEDMEM_Swig.py: libMEDMEM_Swig_wrap.cxx + +libMEDMEM_Swig_wrap.cxx: $(SWIG_DEF) + $(SWIG) $(SWIG_FLAGS) -o $@ $< + +libMEDMEM_Swigcmodule_la_CPPFLAGS= $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) $(PYTHON_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ + -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core +libMEDMEM_Swigcmodule_la_LDFLAGS= $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) \ + ../MEDMEM/libmedmem.la +if MED_ENABLE_KERNEL + libMEDMEM_Swigcmodule_la_CPPFLAGS+= ${KERNEL_CXXFLAGS} + libMEDMEM_Swigcmodule_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace +endif + +CLEANFILES=libMEDMEM_Swig_wrap.cxx libMEDMEM_Swig.py + +nodist_salomescript_DATA= libMEDMEM_Swig.py +dist_salomescript_DATA= \ + medmem.py \ + med_test1.py \ + med_test2.py \ + med_test3.py \ + med_test_grid.py \ + med_test_skin.py \ + medMeshing_test.py \ + med_field_anal.py \ + med_opfield_test.py \ + med_opsupp_test.py \ + test_gibi.py \ + test_porflow.py \ + testDriverAscii.py \ + testGaussLocalization.py \ + testMedObj.py \ + test_profil_MedFieldDriver.py \ + testWriteAndFam.py \ + testMedMemGeneral.py + +############################################################################# + +install-exec-hook: $(DESTDIR)$(libdir)/_libMEDMEM_Swig.so + +$(DESTDIR)$(libdir)/_libMEDMEM_Swig.so: + ( cd $(DESTDIR)$(libdir); ln -sf libMEDMEM_Swigcmodule.so _libMEDMEM_Swig.so; ) + +uninstall-hook: + ( cd $(DESTDIR)$(libdir); rm -f _libMEDMEM_Swig.so; ) diff --git a/src/MEDMEM_SWIG/Makefile.in b/src/MEDMEM_SWIG/Makefile.in deleted file mode 100644 index ef1b48eb8..000000000 --- a/src/MEDMEM_SWIG/Makefile.in +++ /dev/null @@ -1,108 +0,0 @@ -# MED MEDMEM_SWIG : binding of C++ implementation and Python -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir) - -@COMMENCE@ - -EXPORT_HEADERS = \ - libMEDMEM_Swig.i \ - my_typemap.i \ - MEDMEM_SWIG_Templates.hxx -# MEDMEM_SWIG_MedFieldDoubleDriver.hxx \ -# MEDMEM_SWIG_MedFieldIntDriver.hxx \ -# MEDMEM_SWIG_AsciiFieldDoubleDriver.hxx \ -# MEDMEM_SWIG_AsciiFieldIntDriver.hxx \ -# MEDMEM_SWIG_FieldDouble.hxx \ -# MEDMEM_SWIG_FieldInt.hxx \ - -# Libraries targets - -LIB = libMEDMEM_Swigcmodule.la - -# LIB_SRC = \ -# MEDMEM_SWIG_MedFieldDoubleDriver.cxx \ -# MEDMEM_SWIG_MedFieldIntDriver.cxx \ -# MEDMEM_SWIG_AsciiFieldDoubleDriver.cxx \ -# MEDMEM_SWIG_AsciiFieldIntDriver.cxx -# MEDMEM_SWIG_FieldDouble.cxx \ -# MEDMEM_SWIG_FieldInt.cxx \ - -ifeq (@SWIG_VERSION@, 1.3.21) -SWIG_DEF = libMEDMEM_Swig.i dummy.i - -dummy_wrap.cxx: libMEDMEM_Swig_wrap.cxx - sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libMEDMEM_Swig_wrap.cxx > toto - mv toto libMEDMEM_Swig_wrap.cxx - sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libMEDMEM_Swig_wrap.cxx > toto - mv toto libMEDMEM_Swig_wrap.cxx - touch dummy_wrap.cxx -else -SWIG_DEF = libMEDMEM_Swig.i -endif - -EXPORT_PYSCRIPTS = libMEDMEM_Swig.py \ - medmem.py \ - med_test1.py \ - med_test2.py \ - med_test3.py \ - med_test_grid.py \ - med_test_skin.py \ - medMeshing_test.py \ - med_field_anal.py \ - med_opfield_test.py \ - med_opsupp_test.py \ - test_gibi.py \ - test_porflow.py \ - testDriverAscii.py \ - testGaussLocalization.py \ - testMedObj.py \ - test_profil_MedFieldDriver.py \ - testWriteAndFam.py \ - testMedMemGeneral.py - -############################################################################# - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@//salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS+= $(PYTHON_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) -CXXFLAGS+= @CXXTMPDPTHFLAGS@ -LIBS= $(PYTHON_LIBS) -LDFLAGS+= -lmedmem $(MED2_LIBS) $(HDF5_LIBS) - -ifeq ($(MED_WITH_KERNEL),yes) - CPPFLAGS+= ${KERNEL_CXXFLAGS} - CXXFLAGS+= ${KERNEL_CXXFLAGS} - LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace -endif -############################################################################# - -@CONCLUDE@ diff --git a/src/MEDMEM_SWIG/libMEDMEM_Swig.i b/src/MEDMEM_SWIG/libMEDMEM_Swig.i index b41157dd0..ba08a8655 100644 --- a/src/MEDMEM_SWIG/libMEDMEM_Swig.i +++ b/src/MEDMEM_SWIG/libMEDMEM_Swig.i @@ -61,6 +61,8 @@ typedef FIELD <int, FullInterlace> FIELDINT; typedef FIELD <double, NoInterlace> FIELDDOUBLENOINTERLACE; typedef FIELD <int, NoInterlace> FIELDINTNOINTERLACE; + typedef FIELD <double, NoInterlaceByType> FIELDDOUBLENOINTERLACEBYTYPE; + typedef FIELD <int, NoInterlaceByType> FIELDINTNOINTERLACEBYTYPE; %} @@ -76,6 +78,8 @@ typedef FIELD <double, FullInterlace> FIELDDOUBLE; typedef FIELD <int, FullInterlace> FIELDINT; typedef FIELD <double, NoInterlace> FIELDDOUBLENOINTERLACE; typedef FIELD <int, NoInterlace> FIELDINTNOINTERLACE; +typedef FIELD <double, NoInterlaceByType> FIELDDOUBLENOINTERLACEBYTYPE; +typedef FIELD <int, NoInterlaceByType> FIELDINTNOINTERLACEBYTYPE; %include "typemaps.i" %include "my_typemap.i" @@ -101,8 +105,17 @@ typedef FIELD <int, NoInterlace> FIELDINTNOINTERLACE; %exception { + //class PyAllowThreadsGuard { + // public: + // PyAllowThreadsGuard() { _save = PyEval_SaveThread(); } + // ~PyAllowThreadsGuard() { PyEval_RestoreThread(_save); } + // private: + // PyThreadState *_save; + //}; + try { + //PyAllowThreadsGuard guard; $action } catch(MEDEXCEPTION& exception) @@ -298,7 +311,6 @@ typedef FIELD <int, NoInterlace> FIELDINTNOINTERLACE; %typemap(python,in) vector< FIELDINTNOINTERLACE* >, const vector< FIELDINTNOINTERLACE* > { TYPEMAP_INPUT_VECTOR_BY_VALUE( FIELDINTNOINTERLACE * ) } - /************************************************** OUT typemaps for some std::vector's **************************************************/ @@ -694,7 +706,7 @@ public: }; /* - Class FIELD has now two template parameters T1 is a double or an int + Class FIELD has now two template parameters: T1 is a double or an int, INTERLACING_TAG is FullInterlace or NoInterlace */ @@ -721,6 +733,12 @@ public: T1 getValueIJ(int i,int j) const; + T1 getValueIJK(int i,int j, int k) const; + + T1 getValueIJByType(int i,int j, int type) const; + + T1 getValueIJKByType(int i,int j, int k, int type) const; + void setValue(T1* value); void setRow( int i, T1 * value); @@ -729,6 +747,12 @@ public: void setValueIJ(int i, int j, T1 value); + void setValueIJK(int i, int j, int k, T1 value); + + void setValueIJByType(int i, int j, int type, T1 value); + + void setValueIJKByType(int i, int j, int k, int type, T1 value); + void allocValue(const int NumberOfComponents); void deallocValue(); @@ -759,28 +783,82 @@ public: bool getGaussPresence(); - GAUSS_LOCALIZATION<INTERLACING_TAG> * getGaussLocalizationPtr(MED_EN::medGeometryElement geomElement); + GAUSS_LOCALIZATION<INTERLACING_TAG> * getGaussLocalizationPtr(medGeometryElement geomElement); + + int getNbGaussI(int i); %extend { + + /*! + * \brief create a field with default gauss localizations + */ + FIELD(const SUPPORT * support, const int numberOfComponents, const int* nbGaussByType) + { + FIELD<T1,INTERLACING_TAG>* f = new FIELD<T1,INTERLACING_TAG>(support,numberOfComponents); + + int nbtypegeo = support->getNumberOfTypes(); + vector<int> nbelgeoc (nbtypegeo+1,0); + const int * nbElemByType = support->getNumberOfElements(); + for (int iType = 0; iType < nbtypegeo; ++iType) + { + nbelgeoc [ iType+1 ] = nbelgeoc[ iType ] + nbElemByType[ iType ]; + MED_EN::medGeometryElement type = support->getTypes()[ iType ]; + ostringstream locname; + locname << nbGaussByType[iType] << "points_on" << type << "geomType"; + f->setGaussLocalization + ( type, + GAUSS_LOCALIZATION_::makeDefaultLocalization( locname.str(), + type, + nbGaussByType[ iType ])); + } + typedef MEDMEM_ArrayInterface<T1,INTERLACING_TAG,Gauss>::Array Array; + Array* array = new Array(numberOfComponents, + support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS), + support->getNumberOfTypes(), + &nbelgeoc[0], + nbGaussByType-1); + f->setArray( array ); + return f; + } + + PyObject * getNumberOfGaussPoints() + { + int size = self->getNumberOfGeometricTypes(); + + const int * value = self->getNumberOfGaussPoints(); + TYPEMAP_OUTPUT_ARRAY(value, size, PyInt_FromLong, FIELD::getNumberOfGaussPoints()); + } + + + PyObject * applyPyFunc( PyObject * func ) { - MESSAGE("Appel de applyPyFunc"); - if (!PyCallable_Check(func)) { - PyErr_SetString(PyExc_TypeError, "FIELD.applyPyFunc prend en argument une fonction"); - return NULL; - } + MESSAGE("Appel de applyPyFunc"); + if (!PyCallable_Check(func)) { + PyErr_SetString(PyExc_TypeError, "FIELD.applyPyFunc prend en argument une fonction"); + return NULL; + } - int nComp=self->getNumberOfComponents(); - int nVal=self->getNumberOfValues(); - for (int i=1; i!=nVal+1; ++i) - for ( int j=1 ;j!=nComp+1 ;++j ) - { - self->setValueIJ(i,j, Binding<T1>::Functor( func, self->getValueIJ(i,j) ) ); - } + int nComp=self->getNumberOfComponents(); + int nVal=self->getNumberOfValues(); + for (int i=1; i!=nVal+1; ++i) + for ( int j=1 ;j!=nComp+1 ;++j ) + { + self->setValueIJ(i,j, Binding<T1>::Functor( func, self->getValueIJ(i,j) ) ); + } - PyObject * result = Binding<double>::Traducer(nComp*nVal); + PyObject * result = Binding<double>::Traducer(nComp*nVal); return result; } + + %newobject execFunc( int nbOfCompo, PyObject * func ); + FIELD<T1, INTERLACING_TAG> *execFunc( int nbOfCompo, PyObject *func ) + { + MyFunction<T1,T1>::_pyFunc=func; + MyFunction<T1,T1>::_nbOfComponent=nbOfCompo; + MyFunction<T1,T1>::_spaceDim=self->getNumberOfComponents(); + return self->execFunc(nbOfCompo, MyFunction<T1,T1>::EvalPy2Cpp); + } %newobject __add__(const FIELD<T1, INTERLACING_TAG> & ); FIELD<T1, INTERLACING_TAG> * __add__(const FIELD<T1, INTERLACING_TAG> & m) @@ -865,8 +943,7 @@ public: PyObject * getValue() { - int size = (self->getNumberOfComponents())* - ((self->getSupport())->getNumberOfElements(MED_ALL_ELEMENTS)); + int size = self->getValueLength(); const T1 * value = self->getValue(); @@ -874,11 +951,22 @@ public: FIELD::getValue); } + // returns values for geom type in NoInterlaceByType mode + PyObject * getValueByType(int type) + { + int size = self->getValueByTypeLength(type); + + const T1 * value = self->getValueByType(type); + + TYPEMAP_OUTPUT_ARRAY(value, size, Binding< T1 >::Traducer, + FIELD::getValueByType()); + } + // this method replaces getValueI() in FullInterlace mode /* %newobject getRow(int );*/ PyObject * getRow(int index) { - int size = self->getNumberOfComponents(); + int size = self->getNumberOfComponents() * self->getNbGaussI( index ); const T1 * value = self->getRow(index); @@ -932,9 +1020,11 @@ public: /*%template(FIELDDOUBLEFULLINTERLACE) FIELD<double, FullInterlace>;*/ %template(FIELDDOUBLE) FIELD<double, FullInterlace>; %template(FIELDDOUBLENOINTERLACE) FIELD<double, NoInterlace>; +%template(FIELDDOUBLENOINTERLACEBYTYPE) FIELD<double, NoInterlaceByType>; /*%template(FIELDINTFULLINTERLACE) FIELD<int, FullInterlace>;*/ %template(FIELDINT) FIELD<int, FullInterlace>; %template(FIELDINTNOINTERLACE) FIELD<int, NoInterlace>; +%template(FIELDINTNOINTERLACEBYTYPE) FIELD<int, NoInterlaceByType>; class GROUP : public SUPPORT { @@ -955,6 +1045,7 @@ class MESH { public : MESH(); + MESH(MESH &m); ~MESH(); @@ -1211,7 +1302,7 @@ public : medEntityMesh Entity) { const int * array = self->getPolygonsConnectivityIndex(ConnectivityType,Entity); - int size = self->getNumberOfPolygons() + 1; + int size = self->getNumberOfPolygons(Entity) + 1; TYPEMAP_OUTPUT_ARRAY(array, size, PyInt_FromLong, MESH::getPolygonsConnectivity); } @@ -1323,7 +1414,7 @@ public : const int * FacesIndex, const int * Nodes, int nbOfPolyhedra, - const MED_EN::medEntityMesh Entity); + const medEntityMesh Entity); %extend { void setCoordinates(const int SpaceDimension, const int NumberOfNodes, @@ -1450,6 +1541,8 @@ class MED void read (int index=0); + void readFileStruct (int index=0); + void addField ( FIELD_ * const ptrField ); void addMesh ( MESH * const ptrMesh ); @@ -2361,13 +2454,9 @@ template <class INTERLACING_TAG> class GAUSS_LOCALIZATION PyObject * getWeight () const { vector<double> wg = self->getWeight(); - int size = wg.size(); - double * wgPtr = new double [size]; - for (int index = 0; index<size; index++) - wgPtr[index] = wg[index]; - TYPEMAP_OUTPUT_ARRAY(wgPtr, size, PyFloat_FromDouble, + double * wgPtr = &wg[0]; + TYPEMAP_OUTPUT_ARRAY(wgPtr, wg.size(), PyFloat_FromDouble, GAUSS_LOCALIZATION::getWeight); - delete wgPtr; } } }; @@ -2398,6 +2487,12 @@ template <class INTERLACING_TAG> class GAUSS_LOCALIZATION { MESSAGE("createTypedFieldFromField : Constructor (for Python API) FIELD<T> with parameter FIELD_"); MESSAGE("Its returns a proper cast of the input pointer :: FIELD_ --> FIELD<T>"); + if ( field ) { + if (field->getInterlacingType() != SET_INTERLACING_TYPE<INTERLACING_TAG>::_interlacingType) + throw MEDEXCEPTION("cast to wrong medModeSwitch (_interlacingType)"); + if (field->getValueType() != SET_VALUE_TYPE<T>::_valueType) + throw MEDEXCEPTION("cast to wrong med_type_champ (_valueType)"); + } return (FIELD<T, INTERLACING_TAG> *) field; } @@ -2419,26 +2514,36 @@ template<class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createTyped %template ( createFieldIntFromField ) createTypedFieldFromField < int, FullInterlace >; %template ( createFieldDoubleNoInterlaceFromField ) createTypedFieldFromField < double, NoInterlace>; %template ( createFieldIntNoInterlaceFromField ) createTypedFieldFromField < int, NoInterlace >; +%template ( createFieldDoubleNoInterlaceByTypeFromField ) createTypedFieldFromField < double, NoInterlaceByType>; +%template ( createFieldIntNoInterlaceByTypeFromField ) createTypedFieldFromField < int, NoInterlaceByType >; template <class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldScalarProduct(FIELD<T, INTERLACING_TAG> * field1, FIELD<T, INTERLACING_TAG> * field2); %newobject createFieldDoubleScalarProduct ; %newobject createFieldIntScalarProduct ; %newobject createFieldDoubleNoInterlaceScalarProduct ; %newobject createFieldIntNoInterlaceScalarProduct ; +%newobject createFieldDoubleNoInterlaceByTypeScalarProduct ; +%newobject createFieldIntNoInterlaceByTypeScalarProduct ; %template ( createFieldDoubleScalarProduct ) createFieldScalarProduct < double, FullInterlace >; %template ( createFieldIntScalarProduct ) createFieldScalarProduct < int, FullInterlace >; %template ( createFieldDoubleNoInterlaceScalarProduct ) createFieldScalarProduct < double, NoInterlace >; %template ( createFieldIntNoInterlaceScalarProduct ) createFieldScalarProduct < int, NoInterlace >; +%template ( createFieldDoubleNoInterlaceByTypeScalarProduct ) createFieldScalarProduct < double, NoInterlaceByType >; +%template ( createFieldIntNoInterlaceByTypeScalarProduct ) createFieldScalarProduct < int, NoInterlaceByType >; template <class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldScalarProductDeep(FIELD<T, INTERLACING_TAG> * field1, FIELD<T, INTERLACING_TAG> * field2); %newobject createFieldDoubleScalarProductDeep ; %newobject createFieldIntScalarProductDeep ; %newobject createFieldDoubleNoInterlaceScalarProductDeep ; %newobject createFieldIntNoInterlaceScalarProductDeep ; +%newobject createFieldDoubleNoInterlaceByTypeScalarProductDeep ; +%newobject createFieldIntNoInterlaceByTypeScalarProductDeep ; %template ( createFieldDoubleScalarProductDeep ) createFieldScalarProductDeep < double, FullInterlace >; %template ( createFieldIntScalarProductDeep ) createFieldScalarProductDeep < int, FullInterlace >; %template ( createFieldDoubleNoInterlaceScalarProductDeep ) createFieldScalarProductDeep < double, NoInterlace >; %template ( createFieldIntNoInterlaceScalarProductDeep ) createFieldScalarProductDeep < int, NoInterlace >; +%template ( createFieldDoubleNoInterlaceByTypeScalarProductDeep ) createFieldScalarProductDeep < double, NoInterlaceByType >; +%template ( createFieldIntNoInterlaceByTypeScalarProductDeep ) createFieldScalarProductDeep < int, NoInterlaceByType >; template<class T, class INTERLACING_TAG> FIELD<T, INTERLACING_TAG> * createFieldFromAnalytic(SUPPORT * Support, int NumberOfComponents, PyObject * double_function); @@ -2449,6 +2554,7 @@ template <class T> FIELD<T, FullInterlace> * createTypedFieldConvertFullInterlac %template (createFieldIntConvertFullInterlace) createTypedFieldConvertFullInterlace<int>; template <class T> FIELD<T, NoInterlace> * createTypedFieldConvertNoInterlace(const FIELD<T, FullInterlace> & field ); +//template <class T> FIELD<T, NoInterlace> * createTypedFieldConvertNoInterlace(const FIELD<T, NoInterlaceByType> & field ); %template (createFieldDoubleConvertNoInterlace) createTypedFieldConvertNoInterlace<double>; @@ -2486,10 +2592,10 @@ GRID * createGridFromMesh( MESH * aMesh ); FIELD<T, INTERLACING_TAG> * fieldAnalytic = new FIELD<T, INTERLACING_TAG>(Support, NumberOfComponents); - MyFunction<T>::_pyFunc=double_function; - MyFunction<T>::_nbOfComponent=NumberOfComponents; - MyFunction<T>::_spaceDim=Support->getMesh()->getSpaceDimension(); - fieldAnalytic->fillFromAnalytic(MyFunction<T>::EvalPy2Cpp); + MyFunction<T,double>::_pyFunc=double_function; + MyFunction<T,double>::_nbOfComponent=NumberOfComponents; + MyFunction<T,double>::_spaceDim=Support->getMesh()->getSpaceDimension(); + fieldAnalytic->fillFromAnalytic(MyFunction<T,double>::EvalPy2Cpp); return fieldAnalytic; } %} diff --git a/src/MEDMEM_SWIG/med_field_anal.py b/src/MEDMEM_SWIG/med_field_anal.py index c984e9849..933923ad1 100755 --- a/src/MEDMEM_SWIG/med_field_anal.py +++ b/src/MEDMEM_SWIG/med_field_anal.py @@ -83,7 +83,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "carre_en_quad4_seg2.med" medFile = filePath + "cube_hexa8_quad4.med" diff --git a/src/MEDMEM_SWIG/med_opfield_test.py b/src/MEDMEM_SWIG/med_opfield_test.py index 78a4668b0..de479c8c9 100755 --- a/src/MEDMEM_SWIG/med_opfield_test.py +++ b/src/MEDMEM_SWIG/med_opfield_test.py @@ -29,7 +29,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "pointe.med" diff --git a/src/MEDMEM_SWIG/med_opsupp_test.py b/src/MEDMEM_SWIG/med_opsupp_test.py index 67b6d1b44..6fa18d9de 100755 --- a/src/MEDMEM_SWIG/med_opsupp_test.py +++ b/src/MEDMEM_SWIG/med_opsupp_test.py @@ -30,7 +30,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "pointe.med" diff --git a/src/MEDMEM_SWIG/med_test1.py b/src/MEDMEM_SWIG/med_test1.py index 2873f444e..6697b6e19 100644 --- a/src/MEDMEM_SWIG/med_test1.py +++ b/src/MEDMEM_SWIG/med_test1.py @@ -32,7 +32,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "carre_en_quad4_seg2.med" #medFile = filePath + "cube_hexa8_quad4.med" @@ -442,7 +442,10 @@ if (nbMeshes>0): nbElmBound = suppBound.getNumberOfElements(MED_ALL_ELEMENTS) print "Getting normal field on the boundary",nbElmBound normalBound = mesh.getNormal(suppBound) - numberSuppBound = suppBound.getNumber(MED_ALL_ELEMENTS) + if suppBound.isOnAllElements(): + numberSuppBound = range(1,nbElmBound+1) + else: + numberSuppBound = suppBound.getNumber(MED_ALL_ELEMENTS) for j in range(nbElmBound): valInd = numberSuppBound[j] normalBoundJ = normalBound.getRow(valInd) @@ -456,7 +459,10 @@ if (nbMeshes>0): nbElmBound = suppBound.getNumberOfElements(MED_ALL_ELEMENTS) print "Getting normal field on the boundary",nbElmBound normalBound = mesh.getNormal(suppBound) - numberSuppBound = suppBound.getNumber(MED_ALL_ELEMENTS) + if suppBound.isOnAllElements(): + numberSuppBound = range(1,nbElmBound+1) + else: + numberSuppBound = suppBound.getNumber(MED_ALL_ELEMENTS) for j in range(nbElmBound): valInd = numberSuppBound[j] normalBoundJ = normalBound.getRow(valInd) diff --git a/src/MEDMEM_SWIG/med_test2.py b/src/MEDMEM_SWIG/med_test2.py index 0cff34423..397a144ea 100644 --- a/src/MEDMEM_SWIG/med_test2.py +++ b/src/MEDMEM_SWIG/med_test2.py @@ -77,7 +77,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "carre_en_quad4_seg2.med" #medFile = filePath + "cube_hexa8_quad4.med" diff --git a/src/MEDMEM_SWIG/med_test3.py b/src/MEDMEM_SWIG/med_test3.py index 4d91a3e24..728f0581c 100644 --- a/src/MEDMEM_SWIG/med_test3.py +++ b/src/MEDMEM_SWIG/med_test3.py @@ -30,7 +30,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "carre_en_quad4_seg2.med" #medFile = filePath + "cube_hexa8_quad4.med" diff --git a/src/MEDMEM_SWIG/med_test_grid.py b/src/MEDMEM_SWIG/med_test_grid.py index ee4fbb0f6..6dc48da7c 100755 --- a/src/MEDMEM_SWIG/med_test_grid.py +++ b/src/MEDMEM_SWIG/med_test_grid.py @@ -30,7 +30,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "test19.med" print "Read file", medFile diff --git a/src/MEDMEM_SWIG/med_test_skin.py b/src/MEDMEM_SWIG/med_test_skin.py index a708ee5be..4cba008a7 100644 --- a/src/MEDMEM_SWIG/med_test_skin.py +++ b/src/MEDMEM_SWIG/med_test_skin.py @@ -25,7 +25,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "cube_hexa8_quad4.med" diff --git a/src/MEDMEM_SWIG/testDriverAscii.py b/src/MEDMEM_SWIG/testDriverAscii.py index 17ff86bea..529fa53f9 100644 --- a/src/MEDMEM_SWIG/testDriverAscii.py +++ b/src/MEDMEM_SWIG/testDriverAscii.py @@ -25,7 +25,7 @@ import os # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + "test_2D.med" diff --git a/src/MEDMEM_SWIG/testMedMemCxxTests.py b/src/MEDMEM_SWIG/testMedMemCxxTests.py index 3478bd56b..3ac5b42b1 100644 --- a/src/MEDMEM_SWIG/testMedMemCxxTests.py +++ b/src/MEDMEM_SWIG/testMedMemCxxTests.py @@ -21,7 +21,7 @@ from libMEDMEM_Swig import * import os,string filesPath=os.environ["MED_ROOT_DIR"] -filesPath=filesPath+"/share/salome/resources/" +filesPath=filesPath+"/share/salome/resources/med/" testExecfiles = [] argListTest = [] diff --git a/src/MEDMEM_SWIG/testMedMemGeneral.py b/src/MEDMEM_SWIG/testMedMemGeneral.py index b6ddf0ce9..af523a014 100755 --- a/src/MEDMEM_SWIG/testMedMemGeneral.py +++ b/src/MEDMEM_SWIG/testMedMemGeneral.py @@ -32,7 +32,7 @@ from random import * import sys,os,string filesPath=os.environ["MED_ROOT_DIR"] -filesPath=filesPath+"/share/salome/resources/" +filesPath=filesPath+"/share/salome/resources/med/" os.system("rm -rf "+filesPath+"*_test.*") diff --git a/src/MEDMEM_SWIG/testMedObj.py b/src/MEDMEM_SWIG/testMedObj.py index 29c162ca6..4a00a63be 100755 --- a/src/MEDMEM_SWIG/testMedObj.py +++ b/src/MEDMEM_SWIG/testMedObj.py @@ -34,7 +34,7 @@ import os #befor running this script, please be sure about the path the files # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = "pointe.med" diff --git a/src/MEDMEM_SWIG/testWriteAndFam.py b/src/MEDMEM_SWIG/testWriteAndFam.py index 20a2c4deb..4e745c8af 100755 --- a/src/MEDMEM_SWIG/testWriteAndFam.py +++ b/src/MEDMEM_SWIG/testWriteAndFam.py @@ -31,7 +31,7 @@ import os #befor running this script, please be sure about the path the files # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFiles = [] medFiles.append("geomMesh21.med") diff --git a/src/MEDMEM_SWIG/test_gibi.py b/src/MEDMEM_SWIG/test_gibi.py index 802fa637f..0be3e8966 100644 --- a/src/MEDMEM_SWIG/test_gibi.py +++ b/src/MEDMEM_SWIG/test_gibi.py @@ -29,7 +29,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" gibiFile = "elle_2D_QT_2x2.sauve" mesh1Name = string.split(gibiFile,".")[0]+"_fromGibiDriver" diff --git a/src/MEDMEM_SWIG/test_porflow.py b/src/MEDMEM_SWIG/test_porflow.py index c7b1e3dc0..c5a84e834 100644 --- a/src/MEDMEM_SWIG/test_porflow.py +++ b/src/MEDMEM_SWIG/test_porflow.py @@ -29,7 +29,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" porflowFile = "boitenew.inp" mesh1Name = string.split(porflowFile,".")[0]+"_fromPorflowDriver" diff --git a/src/MEDMEM_SWIG/test_profil_MedFieldDriver.py b/src/MEDMEM_SWIG/test_profil_MedFieldDriver.py index 148211840..6f9e9d5a9 100644 --- a/src/MEDMEM_SWIG/test_profil_MedFieldDriver.py +++ b/src/MEDMEM_SWIG/test_profil_MedFieldDriver.py @@ -50,7 +50,7 @@ import os #befor running this script, please be sure about the path the file fileName # filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFile = filePath + medFile diff --git a/src/MEDSPLITTER/MEDSPLITTER.hxx b/src/MEDSPLITTER/MEDSPLITTER.hxx new file mode 100755 index 000000000..1ea1cf44f --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER.hxx @@ -0,0 +1,39 @@ +// Copyright (C) 2003 OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : MEDSPLITTER.hxx +// Author : Alexander A. BORODIN +// Module : MED +// Exporting/Importing defines for Windows Platform + +#ifndef MEDSPLITTER_HXX_ +#define MEDSPLITTER_HXX_ + +#ifdef WNT +# ifdef MEDSPLITTER_EXPORTS +# define MEDSPLITTER_EXPORT __declspec( dllexport ) +# else +# define MEDSPLITTER_EXPORT __declspec( dllimport ) +# endif +#else +# define MEDSPLITTER_EXPORT +#endif + +#endif //MEDSPLITTER_HXX_ diff --git a/src/MEDSPLITTER/MEDSPLITTER_API.cxx b/src/MEDSPLITTER/MEDSPLITTER_API.cxx new file mode 100644 index 000000000..885c9bf94 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_API.cxx @@ -0,0 +1,75 @@ +/*! + * API for the MEDSPLITTER tool + * + * API has a C binding so that it can be used + * in a C/C++ program and it can easily be wrapped + * in a Fortran program + */ + +#include "MEDSPLITTER_API.hxx" + +#include <string> +#include "MEDMEM_define.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_Topology.hxx" + +using namespace std; +/*! + * MEDSPLITTER high-level API + * + * \param inputfilename name of the input file + * \param mesh name of the input mesh (only used for the sequential input file case) + * \param outputfilename name out the master output file + * \param is_distributed sequential input (0) or distributed input (1) + * \param nprocs number of subdomains + * \param method METIS(0) or SCOTCH(1) + * \param meshonly projects mesh and fields (0) or only the mesh (1) + */ + +int medsplitter(const char* inputfilename, + const char* mesh, + const char* outputfilename, + int is_distributed, + int nprocs, + int method, + int meshonly) +{ + + //Pointer to the initial collection + MEDSPLITTER::MESHCollection* collection; + + // Loading the mesh collection + string input(inputfilename); + + if (is_distributed ==0) + { + string meshname (mesh); + collection=new MEDSPLITTER::MESHCollection(input,meshname); + } + else + collection = new MEDSPLITTER::MESHCollection(input); + + // Creating the graph and partitioning it + MEDSPLITTER::Topology* new_topo; + if (method==0) + new_topo = collection->createPartition(nprocs,MEDSPLITTER::Graph::METIS); + else + new_topo = collection->createPartition(nprocs,MEDSPLITTER::Graph::SCOTCH); + + // Creating a new mesh collection from the partitioning + MEDSPLITTER::MESHCollection new_collection(*collection, new_topo); + + //Writing the output files (master + MED files) + string output(outputfilename); + new_collection.write(output); + + // Casting the fields on the new collection + if (meshonly!=0) + new_collection.castAllFields(*collection); + delete collection; + + return 0; +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_API.hxx b/src/MEDSPLITTER/MEDSPLITTER_API.hxx new file mode 100644 index 000000000..35238762b --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_API.hxx @@ -0,0 +1,14 @@ +#ifndef MEDSPLITTER_API_HXX_ +#define MEDSPLITTER_API_HXX_ + +#include "MEDSPLITTER.hxx" +MEDSPLITTER_EXPORT +extern "C" int medsplitter(const char* inputfilename, + const char* mesh, + const char* outputfilename, + int is_distributed, + int nprocs, + int method, + int meshonly); + +#endif diff --git a/src/MEDSPLITTER/MEDSPLITTER_FaceModel.hxx b/src/MEDSPLITTER/MEDSPLITTER_FaceModel.hxx new file mode 100644 index 000000000..4f82cc105 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_FaceModel.hxx @@ -0,0 +1,28 @@ +#ifndef MEDSPLITTER_FACEMODEL_HXX_ +#define MEDSPLITTER_FACEMODEL_HXX_ + +namespace MEDSPLITTER +{ + +class MEDSPLITTER_FaceModel +{ +public: + MEDSPLITTER_FaceModel():_conn(0){}; + virtual ~MEDSPLITTER_FaceModel() {if (_conn!=0) delete[] _conn;} + MED_EN::medGeometryElement getType() const {return _type;} + void setType(MED_EN::medGeometryElement type) {_type=type;} + void setNbNodes(int nbnodes){_conn=new int[nbnodes];} + int& operator[](int i){return *(_conn+i);} + int getGlobal(){return _global;} + void setGlobal(int i){_global=i;} + + private: + int _nbnodes; + int* _conn; + MED_EN::medGeometryElement _type; + int _global; +}; + +} + +#endif /*MEDSPLITTER_FACEMODEL_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_Graph.cxx b/src/MEDSPLITTER/MEDSPLITTER_Graph.cxx new file mode 100644 index 000000000..e0c2ea911 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_Graph.cxx @@ -0,0 +1,9 @@ +#include "MEDSPLITTER_Graph.hxx" + +using namespace MEDSPLITTER; + +Graph::Graph(const MEDMEM::MEDSKYLINEARRAY* array, int* edgeweight):m_graph(array),m_partition(0),m_edgeweight(edgeweight),m_cellweight(0) +{ + +} + diff --git a/src/MEDSPLITTER/MEDSPLITTER_Graph.hxx b/src/MEDSPLITTER/MEDSPLITTER_Graph.hxx new file mode 100644 index 000000000..4a6489631 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_Graph.hxx @@ -0,0 +1,48 @@ +#ifndef GRAPH_HXX_ +#define GRAPH_HXX_ + +#include "MEDSPLITTER.hxx" + +#include "MEDMEM_SkyLineArray.hxx" + +namespace MEDSPLITTER { + +class MEDSPLITTER_EXPORT Graph +{ + + public: + typedef enum {METIS,SCOTCH} splitter_type; + + Graph(){} + + //creates a graph from a SKYLINEARRAY + Graph(const MEDMEM::MEDSKYLINEARRAY* graph, int* edgeweight=0); + + virtual ~Graph(){} + + void setEdgesWeights(int* edgeweight){m_edgeweight=edgeweight;} + void setVerticesWeights(int* cellweight){m_cellweight=cellweight;} + + //computes partitioning of the graph + virtual void partGraph(int ndomain, const string&)=0; + + //! returns the partitioning + const int* getPart() const {return m_partition->getValue();} + + //! returns the number of graph vertices (which can correspond to the cells in the mesh!) + int nbVertices() const {return m_graph->getNumberOf();} + + const MEDMEM::MEDSKYLINEARRAY* getGraph() const {return m_graph;} + + protected: + const MEDMEM::MEDSKYLINEARRAY* m_graph; + + MEDMEM::MEDSKYLINEARRAY* m_partition; + + int* m_edgeweight; + + int* m_cellweight; +}; + +} +#endif /*GRAPH_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.H b/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.H new file mode 100644 index 000000000..25f2da90c --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.H @@ -0,0 +1,269 @@ +#ifndef MEDSPLITTER_MESHCOLLECTION_H_ +#define MEDSPLITTER_MESHCOLLECTION_H_ + +/*! Projects an integer or double field onto a new mesh + * + * \param old_collection initial mesh collection supporting the field + * \param fieldname name of the field to be cast + * \param itnumber time iteration number of the field to be cast + * \param ordernumber inner iteration number of the field to be cast + * \param type_of_template dummy argument passed for separate template instanciation + */ + +template <class T> +void MESHCollection::castFields (const MESHCollection& old_collection, + const string& fieldname, int itnumber, int ordernumber) +{ + char fieldchar[80]; + strcpy(fieldchar,fieldname.c_str()); + + int nb_old_domains=old_collection.m_topology->nbDomain(); + int nb_new_domains=m_topology->nbDomain(); + + vector <list<int> > element_array (m_topology->nbDomain()); + + vector <MEDMEM::FIELD<T> *> old_fields ; + + //cout << "MEDSPLITTER - reading fields from old collection"<<endl; + old_collection.getDriver()->readFields(old_fields,fieldchar, itnumber, ordernumber); + + //if (dynamic_cast<MEDMEM::FIELD<int>*> (old_fields[0])==0) + // old_collection.getDriver()->readFieldsDouble(old_fields,fieldchar, itnumber, ordernumber); + //else + // old_collection.getDriver()->readFieldsInt(old_fields,fieldchar, itnumber, ordernumber); + //cout <<"MEDSPLITTER - end of read"<<endl; + + vector <const MEDMEM::SUPPORT*> old_supports(nb_old_domains); + vector <MEDMEM::SUPPORT*> new_supports(nb_new_domains); + vector <MEDMEM::FIELD<T> *> new_fields(nb_new_domains); + + for (int iold = 0; iold < nb_old_domains; iold++) + { + old_supports[iold]=old_fields[iold]->getSupport(); + } + for (int inew = 0; inew < nb_new_domains; inew++) + { + new_supports[inew]=new MEDMEM::SUPPORT(); + } + + //cout << "MEDSPLITTER - casting supports"<<endl; + castSupport(old_collection,old_supports,new_supports); + //cout << "MEDSPLITTER - end of cast"<<endl; + + int nb_components = old_fields[0]->getNumberOfComponents(); + const string* components_names = old_fields[0]->getComponentsNames(); + const string* components_description = old_fields[0]->getComponentsDescriptions(); + const string* components_units = old_fields[0]->getMEDComponentsUnits(); + if (itnumber != old_fields[0]->getIterationNumber()) {cout << "PB with iteration number"<<endl;exit (1);} + int iteration_number=old_fields[0]->getIterationNumber(); + int order_number=old_fields[0]->getOrderNumber(); + double time=old_fields[0]->getTime(); + bool has_gauss_pts = old_fields[0]->getGaussPresence(); + //bool has_gauss_pts=true; + + // Creating the fields objects + // Two different procedures are used whether the field contains Gauss points + // or not + + vector <MEDMEM::MEDMEM_Array<T, FullInterlaceGaussPolicy>*> medarray (nb_new_domains); + + for (int inew=0; inew < nb_new_domains; inew++) + { + if (!has_gauss_pts) { + new_fields[inew] = new MEDMEM::FIELD<T>(new_supports[inew],nb_components); + new_fields[inew]->setName(fieldname); + new_fields[inew]->setComponentsNames(components_names); + new_fields[inew]->setComponentsDescriptions(components_description); + new_fields[inew]->setMEDComponentsUnits(components_units); + new_fields[inew]->setIterationNumber(iteration_number); + new_fields[inew]->setOrderNumber(order_number); + new_fields[inew]->setTime(time); + } + if (has_gauss_pts) + { + new_fields[inew]=new MEDMEM::FIELD<T>(); + //copying the structures describing the field + new_fields[inew]->setNumberOfComponents(nb_components); + new_fields[inew]->setSupport(new_supports[inew]); + new_fields[inew]->setName(fieldname); + new_fields[inew]->setComponentsNames(components_names); + new_fields[inew]->setComponentsDescriptions(components_description); + new_fields[inew]->setMEDComponentsUnits(components_units); + new_fields[inew]->setIterationNumber(iteration_number); + new_fields[inew]->setOrderNumber(order_number); + new_fields[inew]->setTime(time); + + //counters for the gauss points + //nbtypegeo is the number of geometric types on the field + //nbelgeoc is the count of element for each type + //nbgaussgeo is the number of gauss points for each type + int nbtypegeo=0; + int* nbelgeoc=0; + int* nbgaussgeo=0; + + vector<int> gauss_pts_number; + vector<int> nb_elem; + + // the GaussLocalization structures are browsed in the old field + // and copied to the new one + // the nbtypegeo counter is incremented so that + // it contains the number of types for which a gauss localization is defined + MED_EN::MESH_ENTITIES::const_iterator currentEntity; + std::list<MED_EN::medGeometryElement>::const_iterator iter; + currentEntity = MED_EN::meshEntities.find(MED_EN::MED_CELL); + for (iter = (*currentEntity).second.begin();iter != (*currentEntity).second.end(); iter++) + { + // getGaussLocalization throws an exception + // if the GaussLocalization is not available + try + { + MEDMEM::GAUSS_LOCALIZATION<FullInterlace> + gaussloc(old_fields[0]->getGaussLocalization(*iter)); + new_fields[inew]->setGaussLocalization(*iter,gaussloc); + + nbtypegeo++; + gauss_pts_number.push_back(gaussloc.getNbGauss()); + + nb_elem.push_back(new_supports[inew]->getNumberOfElements(*iter)); + } + catch(...) + { + continue; + } + } + + // les tableaux nbelgeoc commencent a 1 + nbelgeoc = new int [nbtypegeo+1]; + nbgaussgeo= new int [nbtypegeo+1]; + int size=0; + nbelgeoc[0]=0; + nbgaussgeo[0]=-1; + for (int i=1; i<=nbtypegeo;i++) + { + size+=nb_elem[i-1]; + nbelgeoc [i]=nb_elem[i-1]+nbelgeoc[i-1]; + nbgaussgeo[i]=gauss_pts_number[i-1]; + } + + //a MEDMEM_Array structure is created to contain + //the data on the Gauss points + + medarray[inew]=new MEDMEM::MEDMEM_Array<T,FullInterlaceGaussPolicy> + (new_fields[inew]->getNumberOfComponents(), size, nbtypegeo, + static_cast<const int* const>(nbelgeoc), + static_cast<const int* const> (nbgaussgeo)); + new_fields[inew]->setArray(medarray[inew]); + // delete[] nbelgeoc; + // delete[] nbgaussgeo; + } + } + + for (int idomain=0; idomain < old_collection.m_topology->nbDomain(); idomain++) + { + //retrieves the group igroup on domain idomain + + const MEDMEM::SUPPORT* support = old_supports[idomain]; + int nbelem = support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); + if (nbelem==0) continue; + int* list_of_elems=0; + + if (support->isOnAllElements()) + { + list_of_elems = new int[nbelem]; + for (int i=0; i<nbelem;i++) + list_of_elems[i]=i+1; + } + else + list_of_elems = const_cast<int*> (support->getNumber(MED_EN::MED_ALL_ELEMENTS)); + + int* array=new int[nbelem]; + int* ip; + int* local; + int* initial_local=0; + int* full_array; + + int size=0; + MED_EN::medEntityMesh entity = support->getEntity(); + switch (entity) + { + case MED_EN::MED_CELL : + ip=new int[nbelem]; + local=new int[nbelem]; + initial_local=list_of_elems; + old_collection.getTopology()->convertCellToGlobal(idomain,list_of_elems,nbelem,array); + m_topology->convertGlobalCellList(array,nbelem,local,ip); + size=nbelem; + break; + case MED_EN::MED_FACE : + old_collection.getTopology()->convertFaceToGlobal(idomain,list_of_elems,nbelem,array); + m_topology->convertGlobalFaceListWithTwins(array,nbelem,local,ip,full_array,size); + initial_local=new int[size]; + old_collection.getTopology()->convertGlobalFaceList(full_array,size,initial_local,idomain); + delete[] full_array; + break; + case MED_EN::MED_NODE : + old_collection.getTopology()->convertNodeToGlobal(idomain,list_of_elems,nbelem,array); + m_topology->convertGlobalNodeListWithTwins(array,nbelem,local,ip,full_array,size); + initial_local=new int[size]; + old_collection.getTopology()->convertGlobalNodeList(full_array,size,initial_local,idomain); + delete[] full_array; + break; + } + + if (!has_gauss_pts) { + for (int i=0; i<size; i++) + { + for (int j=0; j<nb_components;j++) + { + T value = old_fields[idomain]->getValueIJ(initial_local[i],j+1); + + new_fields[ip[i]]->setValueIJ(local[i],j+1, value); + } + } + } + else + { + for (int i=0; i<size; i++) + { + MED_EN::medGeometryElement type = + old_collection.m_mesh[idomain]->getElementType(entity,initial_local[i]); + int nb_gauss_points=old_fields[idomain]->getNumberOfGaussPoints(type); + for (int j=0; j<nb_components;j++) + for (int k=0;k<nb_gauss_points; k++) + { + T value = old_fields[idomain]->getValueIJK(initial_local[i],j+1,k+1); + medarray[ip[i]]->setIJK(local[i],j+1,k+1, value); + } + } + } + delete[]array; + delete[]ip; + delete[]local; + if (support->isOnAllElements()) + { + delete[] list_of_elems; + list_of_elems=0; + } + if (entity==MED_EN::MED_FACE || entity==MED_EN::MED_NODE) delete[] initial_local; + } + + retrieveDriver()->writeFields(new_fields,fieldchar); + //if (dynamic_cast<MEDMEM::FIELD<int>*>(new_fields[0])==0) + // retrieveDriver()->writeFieldsDouble(new_fields,fieldchar); + //else + // retrieveDriver()->writeFieldsInt(new_fields,fieldchar); + for (int i=0; i<nb_new_domains; i++) + { + delete new_fields[i]; + delete new_supports[i]; + //delete medarray[i]; + } + for (int i=0; i<old_fields.size(); i++) + { + cout << "old field deletion" <<endl; + delete old_fields[i]; + delete old_supports[i]; + } +} + +#endif /*MEDSPLITTER_MESHCOLLECTION_H_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.cxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.cxx new file mode 100644 index 000000000..d9d2b4102 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.cxx @@ -0,0 +1,2016 @@ +#include <vector> +#include <string> +#ifndef WNT +# include <ext/hash_map> +#else +# include <hash_map> +#endif +#include <set> + +#include <iostream> +#include <fstream> + +#include "MEDMEM_ConnectZone.hxx" +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_GaussLocalization.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_Group.hxx" + +#include "MEDMEM_Exception.hxx" + +#include "MEDSPLITTER_utils.hxx" + +#include "MEDSPLITTER_Graph.hxx" + +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" + +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_MESHCollectionDriver.hxx" +#include "MEDSPLITTER_MESHCollectionMedXMLDriver.hxx" +#include "MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx" + +#include "MEDSPLITTER_UserGraph.hxx" + +#ifdef ENABLE_METIS +#include "MEDSPLITTER_METISGraph.hxx" +#endif +#ifdef ENABLE_SCOTCH +#include "MEDSPLITTER_SCOTCHGraph.hxx" +#endif + +using namespace MEDSPLITTER; + +#ifndef WNT +using namespace __gnu_cxx; +#else +using namespace std; +#endif + +//template inclusion +#include "MEDSPLITTER_MESHCollection.H" +//#include "MEDSPLITTER_MESHCollectionDriver.H" + + + +MESHCollection::MESHCollection() + : m_topology(0), + m_owns_topology(false), + m_driver(0), + m_driver_type(MEDSPLITTER::MedXML), + m_subdomain_boundary_creates(false), + m_family_splitting(false), + m_create_empty_groups(false) +{ +} + +/*!constructor creating a new mesh collection (mesh series + topology) + *from an old collection and a new topology + * + * On output, the constructor has built the meshes corresponding to the new mesh collection. + * The new topology has been updated so that face and node mappings are included. + * The families have been cast to their projections in the new topology. + * + * \param initial_collection collection from which the data (coordinates, connectivity) are taken + * \param topology topology containing the cell mappings + */ + +MESHCollection::MESHCollection(const MESHCollection& initial_collection, Topology* topology, bool family_splitting, bool create_empty_groups) + : m_name(initial_collection.m_name), + m_topology(topology), + m_owns_topology(false), + m_cell_graph(topology->getGraph()), + m_driver(0), + m_driver_type(MEDSPLITTER::MedXML), + m_subdomain_boundary_creates(false), + m_family_splitting(family_splitting), + m_create_empty_groups(create_empty_groups) +{ + string mesh_name = initial_collection.getName(); + m_mesh.resize(m_topology->nbDomain()); + for (int idomain=0; idomain < m_topology->nbDomain(); idomain++) + { + //creating the new mesh + MEDMEM::MESHING* mesh_builder=new MEDMEM::MESHING; + m_mesh[idomain]= static_cast<MEDMEM::MESH*> (mesh_builder); + ostringstream osname; + osname << mesh_name<<"_"<<idomain+1; + SCRUTE(osname.str()); + mesh_builder->setName(osname.str()); + + createNodalConnectivity(initial_collection,idomain, MED_EN::MED_CELL); + mesh_builder->setMeshDimension(initial_collection.getMeshDimension()); + mesh_builder->setSpaceDimension(initial_collection.getSpaceDimension()); + } + + m_topology->createFaceMapping(initial_collection); + for (int idomain=0; idomain<m_topology->nbDomain(); idomain++) + { + switch (getMeshDimension()) + { + case 3: + createNodalConnectivity(initial_collection,idomain, MED_EN::MED_FACE); + break; + case 2: + createNodalConnectivity(initial_collection,idomain, MED_EN::MED_EDGE); + break; + default : + cerr<<"MEDSPLITTER : Mesh dimension must be 2 or 3"<<endl; + } + } + + castFamilies(initial_collection); +} + +/*! constructing the MESH collection from a distributed file + * + * \param filename name of the master file containing the list of all the MED files + */ +MESHCollection::MESHCollection(const string& filename) + : m_topology(0), + m_owns_topology(true), + m_driver(0), + m_driver_type(MEDSPLITTER::Undefined), + m_subdomain_boundary_creates(false), + m_family_splitting(false), + m_create_empty_groups(false) +{ + char filenamechar[256]; + strcpy(filenamechar,filename.c_str()); + try + { + m_driver=new MESHCollectionMedXMLDriver(this); + m_driver->read (filenamechar); + m_driver_type = MedXML; + + } + catch(MEDEXCEPTION){ + delete m_driver; + try + { + m_driver=new MESHCollectionMedAsciiDriver(this); + m_driver->read (filenamechar); + m_driver_type=MedAscii; + } + catch(MEDEXCEPTION) + { + delete m_driver; + throw MEDEXCEPTION("file does not comply with any recognized format"); + } + } +} + +/*! constructing the MESH collection from a sequential MED-file + * + * \param filename MED file + * \param meshname name of the mesh that is to be read + */ +MESHCollection::MESHCollection(const string& filename, const string& meshname) + : m_name(meshname), + m_topology(0), + m_owns_topology(true), + m_driver(0), + m_driver_type(MEDSPLITTER::MedXML), + m_subdomain_boundary_creates(false), + m_family_splitting(false), + m_create_empty_groups(false) +{ + char filenamechar[256]; + char meshnamechar[256]; + strcpy(filenamechar,filename.c_str()); + strcpy(meshnamechar,meshname.c_str()); + retrieveDriver()->readSeq (filenamechar,meshnamechar); +} + +MESHCollection::~MESHCollection() +{ + for (int i=0; i<m_mesh.size();i++) + if (m_mesh[i]!=0) {delete m_mesh[i]; } + for (int i=0; i<m_connect_zones.size();i++) + if (m_connect_zones[i]!=0) {delete m_connect_zones[i];} + if (m_driver !=0) {delete m_driver; m_driver=0;} + if (m_topology!=0 && m_owns_topology) {delete m_topology; m_topology=0;} +} + +/*!gets the connectivity for a certain type + * + * The output array type_connectivity should have been allocated + * at dimension nbnode_per_type* nb_cells before the call + * + * \param cell_list list of elements (global cell numbers) for which the connectivity is required + * \param nb_cells number of elements + * \param entity type of entity for which the nodal connectivity is required + * \param type type of the elements for which the connectivity is required + * \param type_connectivity on output contains the connectivity of all the elements of the list + * */ + +void MESHCollection::getNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + MED_EN::medGeometryElement type, int* type_connectivity) const +{ + int *local=new int[nb_cells]; + int *ip=new int[nb_cells]; + switch (entity) + { + case MED_EN::MED_CELL: + m_topology->convertGlobalCellList(cell_list,nb_cells,local,ip); + break; + case MED_EN::MED_FACE: + case MED_EN::MED_EDGE: + m_topology->convertGlobalFaceList(cell_list,nb_cells,local,ip); + break; + } + + +// int nbnode_per_type=(int)type%100; +// vector<int> number_of_types_array(m_topology->nbDomain(),0); +// for (int i=0; i<m_topology->nbDomain(); i++) +// number_of_types_array[i]=m_mesh[i]->getNumberOfTypes(entity); + + //defining a connectivity table for different domains + vector <const int*> conn_ip(m_topology->nbDomain()); + vector <const int*> conn_index_ip(m_topology->nbDomain()); + + + vector< map <MED_EN::medGeometryElement, int> > offset; +// offset.resize(m_topology->nbDomain()); + + for (int i=0; i<m_topology->nbDomain();i++) + { + + int nb_elem = m_mesh[i]->getNumberOfElementsWithPoly(entity,type); + if (nb_elem>0) + { + conn_ip[i]=m_mesh[i]->getConnectivity(MED_EN::MED_FULL_INTERLACE, + MED_EN::MED_NODAL,entity,MED_EN::MED_ALL_ELEMENTS); + conn_index_ip[i] = m_mesh[i]->getConnectivityIndex(MED_EN::MED_NODAL,entity); + // global_index= m_mesh[i]->getGlobalNumberingIndex(entity); + } + else + { + conn_ip[i]=0; + conn_index_ip[i]=0; + } +// int number_of_types = number_of_types_array[i]; +// const MEDMEM::CELLMODEL* types = m_mesh[ip[icell]]->getCellsTypes(entity); +// for (int itype=0; itype<number_of_types; itype++) +// offset[i][types[itype].getType()]=global_index[itype]-1; + } + + int* type_connectivity_ptr=type_connectivity; + for (int icell=0; icell<nb_cells; icell++) + { +// int type_offset = offset[ip[icell]][type]; + const int* conn=conn_ip[ip[icell]]; + const int* conn_index=conn_index_ip[ip[icell]]; + for (int inode=conn_index[local[icell]-1]; inode<conn_index[local[icell]]; inode++) + { + *type_connectivity_ptr= + m_topology->convertNodeToGlobal(ip[icell],conn[inode-1]); + type_connectivity_ptr++; + } + } + + delete[]local; + delete[]ip; +} + +/*!gets the connectivity for MED_POLYGON type + * + * \param cell_list list of elements (global cell numbers) for which the connectivity is required + * \param nb_cells number of elements + * \param entity type of entity for which the nodal connectivity is required + * \param type_connectivity on output contains the connectivity of all the elements of the list + * \param connectivity_index on output contains the connectivity index for all polygons + * */ + +void MESHCollection::getPolygonNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + vector<int>& type_connectivity, vector<int>& connectivity_index) const +{ + + int *local=new int[nb_cells]; + int *ip=new int[nb_cells]; + switch (entity) + { + case MED_EN::MED_CELL: + m_topology->convertGlobalCellList(cell_list,nb_cells,local,ip); + break; + case MED_EN::MED_FACE: + case MED_EN::MED_EDGE: + m_topology->convertGlobalFaceList(cell_list,nb_cells,local,ip); + break; + } + + + //defining a connectivity table for different domains + vector <const int*> conn_ip(m_topology->nbDomain()); + vector <const int*> conn_index_ip(m_topology->nbDomain()); + vector <const int* > conn_face_index(m_topology->nbDomain()); + vector<int> nb_plain_elems(m_topology->nbDomain()); + + vector< map <MED_EN::medGeometryElement, int> > offset; + + for (int i=0; i<m_topology->nbDomain();i++) + { + nb_plain_elems[i] = m_mesh[i]->getNumberOfElements(entity, MED_EN::MED_ALL_ELEMENTS); + int nb_elem = m_mesh[i]->getNumberOfElementsWithPoly(entity,MED_EN::MED_POLYGON); + if (nb_elem>0) + { + conn_ip[i]=m_mesh[i]->getPolygonsConnectivity(MED_EN::MED_NODAL,entity); + conn_index_ip[i] = m_mesh[i]->getPolygonsConnectivityIndex(MED_EN::MED_NODAL,entity); + } + else + { + conn_ip[i]=0; + conn_index_ip[i]=0; + } + } + + connectivity_index.resize(nb_cells+1); + connectivity_index[0]=1; + for (int icell=0; icell<nb_cells; icell++) + { + int nb_plain= nb_plain_elems[ip[icell]]; + const int* conn=conn_ip[ip[icell]]; + const int* conn_index=conn_index_ip[ip[icell]]; + for (int inode=conn_index[local[icell]-1-nb_plain]; inode<conn_index[local[icell]-nb_plain]; inode++) + { + type_connectivity.push_back( + m_topology->convertNodeToGlobal(ip[icell],conn[inode-1])); + } + connectivity_index[icell+1]=connectivity_index[icell] + -conn_index[local[icell]-1-nb_plain]+conn_index[local[icell]-nb_plain]; + } + + delete[]local; + delete[]ip; +} + + +/*!gets the connectivity for MED_POLYHEDRA type + * + * \param cell_list list of elements (global cell numbers) for which the connectivity is required + * \param nb_cells number of elements + * \param entity type of entity for which the nodal connectivity is required + * \param type_connectivity on output contains the connectivity of all the elements of the list + * \param connectivity_index on output contains the connectivity index for all polygons + * */ + +void MESHCollection::getPolyhedraNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + vector<int>& type_connectivity, vector<int>& connectivity_index, vector<int>& face_connectivity_index) const +{ + + int *local=new int[nb_cells]; + int *ip=new int[nb_cells]; + switch (entity) + { + case MED_EN::MED_CELL: + m_topology->convertGlobalCellList(cell_list,nb_cells,local,ip); + break; + case MED_EN::MED_FACE: + case MED_EN::MED_EDGE: + m_topology->convertGlobalFaceList(cell_list,nb_cells,local,ip); + break; + } + + + //defining a connectivity table for different domains + vector <const int*> conn_ip(m_topology->nbDomain()); + vector <const int*> conn_index_ip(m_topology->nbDomain()); + vector <const int*> conn_face_index_ip(m_topology->nbDomain()); + vector<int> nb_plain_elems(m_topology->nbDomain()); + + vector< map <MED_EN::medGeometryElement, int> > offset; + + for (int i=0; i<m_topology->nbDomain();i++) + { + nb_plain_elems[i] = m_mesh[i]->getNumberOfElements(entity, MED_EN::MED_ALL_ELEMENTS); + int nb_elem = m_mesh[i]->getNumberOfElementsWithPoly(entity,MED_EN::MED_POLYHEDRA); + if (nb_elem>0) + { + conn_ip[i]=m_mesh[i]->getPolyhedronConnectivity(MED_EN::MED_NODAL); + conn_index_ip[i] = m_mesh[i]->getPolyhedronIndex(MED_EN::MED_NODAL); + conn_face_index_ip[i]= m_mesh[i]->getPolyhedronFacesIndex(); + } + else + { + conn_ip[i]=0; + conn_index_ip[i]=0; + conn_face_index_ip[i]=0; + } + } + + connectivity_index.resize(nb_cells+1); + connectivity_index[0]=1; + face_connectivity_index.resize(1); + face_connectivity_index[0]=1; + for (int icell=0; icell<nb_cells; icell++) + { + const int* conn=conn_ip[ip[icell]]; + const int* conn_index=conn_index_ip[ip[icell]]; + const int* conn_face_index=conn_face_index_ip[ip[icell]]; + int local_in_poly = local[icell]-nb_plain_elems[ip[icell]]; + connectivity_index[icell+1]=connectivity_index[icell]+ + conn_index[local_in_poly]-conn_index[local_in_poly-1]; + + for (int iface=conn_index[local_in_poly-1]; iface<conn_index[local_in_poly]; iface++) + { + int last_face= face_connectivity_index[face_connectivity_index.size()-1]; + face_connectivity_index.push_back(last_face+conn_face_index[iface]-conn_face_index[iface-1]); + for (int inode=conn_face_index[iface-1]; + inode < conn_face_index[iface]; + inode++) + type_connectivity.push_back( + m_topology->convertNodeToGlobal(ip[icell],conn[inode-1])); + } + + } + + delete[]local; + delete[]ip; +} + +/*! constructing the MESH collection from a file + * + * The method creates as many MED-files as there are domains in the + * collection. It also creates a master file that lists all the MED files. + * The MED files created in ths manner contain joints that describe the + * connectivity between subdomains. + * + * \param filename name of the master file that will contain the list of the MED files + * + */ +void MESHCollection::write(const string& filename) +{ + //building the connect zones necessary for writing joints + if (m_topology->nbDomain()>1) + buildConnectZones(); + + //suppresses link with driver so that it can be changed for writing + if (m_driver!=0)delete m_driver; + m_driver=0; + + char filenamechar[256]; + strcpy(filenamechar,filename.c_str()); + retrieveDriver()->write (filenamechar); +} + +/*! creates or gets the link to the collection driver + */ +MESHCollectionDriver* MESHCollection::retrieveDriver() +{ + if (m_driver==0) + { + switch(m_driver_type) + { + case MedXML: + m_driver=new MESHCollectionMedXMLDriver(this); + break; + case MedAscii: + m_driver=new MESHCollectionMedAsciiDriver(this); + break; + default: + throw MEDEXCEPTION("Unrecognized driver"); + } + } + + return m_driver; +} + + +/*! gets an existing driver + * + */ +MESHCollectionDriver* MESHCollection::getDriver() const +{ + return m_driver; +} + + +/*! gets the list of types for global numbers cell_list + * + * \param cell_list list of global numbers + * \param entity entity type + * \param type_list on output, list of types for the cells given in cell_list + */ +void MESHCollection::getTypeList(int* cell_list,int nb_cells, + MED_EN::medEntityMesh entity, + MED_EN::medGeometryElement* type_list) const +{ + MESSAGE (" Beginning of getTypeList with entity "<<entity); + int *local=new int[nb_cells]; + int *ip=new int[nb_cells]; + switch (entity) + { + case MED_EN::MED_CELL: + m_topology->convertGlobalCellList(cell_list,nb_cells,local,ip); + break; + case MED_EN::MED_FACE: + case MED_EN::MED_EDGE: + m_topology->convertGlobalFaceList(cell_list,nb_cells,local,ip); + break; + } + + for (int icell=0; icell<nb_cells; icell++) + { + type_list[icell]=m_mesh[ip[icell]]->getElementTypeWithPoly(entity,local[icell]); + } + delete[]local; + delete[]ip; + MESSAGE("end of getTypeList"); +} + + + +/*!gets the descending connectivity for a certain type + * + * The output array type_connectivity should have been allocated + * at dimension nbnode_per_type* nb_cells before the call + * + * \param cell_list list of elements (global cell numbers) for which the connectivity is required + * \param nb_cells number of elements + * \param entity type of entity for which the nodal connectivity is required + * \param type type of the elements for which the connectivity is required + * \param type_connectivity on output contains the connectivity of all the elements of the list + * */ + +void MESHCollection::getFaceConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + MED_EN::medGeometryElement type, int* type_connectivity) const +{ + int *local=new int[nb_cells]; + int *ip=new int[nb_cells]; + switch (entity) + { + case MED_EN::MED_CELL: + m_topology->convertGlobalCellList(cell_list,nb_cells,local,ip); + break; + case MED_EN::MED_FACE: + case MED_EN::MED_EDGE: + m_topology->convertGlobalFaceList(cell_list,nb_cells,local,ip); + break; + } + + + int nbface_per_type; + switch (type){ + case 308: + nbface_per_type=6; + break; + case 304: + nbface_per_type=4; + break; + case 306: + nbface_per_type=5; + break; + } + + vector<int> number_of_types_array(m_topology->nbDomain(),0); + for (int i=0; i<m_topology->nbDomain(); i++) + number_of_types_array[i]=m_mesh[i]->getNumberOfTypesWithPoly(entity); + + //defining a connectivity table for different domains + vector <const int*> conn_ip(m_topology->nbDomain()); + for (int i=0; i<m_topology->nbDomain();i++) + { + int nb_elem = m_mesh[i]->getNumberOfElementsWithPoly(entity,type); + if (nb_elem>0) + conn_ip[i]=m_mesh[i]->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_EN::MED_DESCENDING,entity,type); + else + conn_ip[i]=0; + } + + for (int icell=0; icell<nb_cells; icell++) + { + int number_of_types = number_of_types_array[ip[icell]]; + const MEDMEM::CELLMODEL* types = m_mesh[ip[icell]]->getCellsTypes(entity); + int type_offset=0; + for (int itype=0; itype< number_of_types; itype++) + { + if (types[itype].getType() < type) + type_offset += m_mesh[ip[icell]]->getNumberOfElementsWithPoly(entity,types[itype].getType()); + } + const int* conn=conn_ip[ip[icell]]; + for (int iface=0; iface<nbface_per_type; iface++) + { + type_connectivity[icell*nbface_per_type+iface] = m_topology->convertFaceToGlobal + (ip[icell], abs(conn[(local[icell] - type_offset - 1) * nbface_per_type + iface])); + } + } + + delete[]local; + delete[]ip; +} + +/*! gets the list of coordinates for a given list of global node numbers + * + * The vector containing the coordinates on output should + * have been allocated at a dimension m_space_dimension * nb_nodes + * before the call + * + * \param node_list list of global node numbers + * \param nb_nodes number of nodes in the list + * \param coordinates on output, contains the coordinates + */ + +void MESHCollection::getCoordinates(int* node_list,int nb_nodes, double* coordinates) const +{ + int* local=new int[nb_nodes]; + int* ip=new int[nb_nodes]; + int space_dimension= getSpaceDimension(); + m_topology->convertGlobalNodeList(node_list,nb_nodes,local,ip); + for (int i=0; i< nb_nodes; i++) + { + const double* coord=m_mesh[ip[i]]->getCoordinates(MED_EN::MED_FULL_INTERLACE); + for (int icoord=0; icoord<space_dimension; icoord++) + coordinates[i*space_dimension+icoord]=coord[(local[i]-1)*space_dimension+icoord]; + } + delete[]local; + delete[] ip; +} + +/*! retrieves the space dimension*/ +int MESHCollection::getSpaceDimension() const +{ + return m_mesh[0]->getSpaceDimension(); +} +/*! retrieves the mesh dimension*/ +int MESHCollection::getMeshDimension() const +{ + return m_mesh[0]->getMeshDimension(); +} + +/*! retrieves the type of coordinates system*/ +string MESHCollection::getSystem() const +{ + return m_mesh[0]->getCoordinatesSystem(); +} + +/*!retrieves the name of the mesh*/ +string MESHCollection::getMeshName() const +{ + return m_mesh[0]->getName(); +} + +vector<MEDMEM::MESH*>& MESHCollection::getMesh() +{ + return m_mesh; +} + +MEDMEM::MESH* MESHCollection::getMesh(int idomain) const +{ + return m_mesh[idomain]; +} + +vector<MEDMEM::CONNECTZONE*>& MESHCollection::getCZ() +{ + return m_connect_zones; +} + +Topology* MESHCollection::getTopology() const +{ + return m_topology; +} + +void MESHCollection::setTopology(Topology* topo) +{ + if (m_topology!=0) + { + throw MED_EXCEPTION(STRING("Erreur : topology is already set")); + } + else + m_topology = topo; +} + +void MESHCollection::setIndivisibleGroup(const string& name) +{ + m_indivisible_regions.push_back(name); + +} + +/*! Browses the domains and the regions that have + * been marked as indivisible in order to create a vector + * the dimlension of which is the total number of cells, and + * that contains 0 if the cell belongs to no indivisible group + * and that contains an integer corresponding to the group otherwise. + * + * \param indivisible_tag on input is an int* allocated as int[nbcells] + * on output contains the tags + */ + + +void MESHCollection::treatIndivisibleRegions(int* indivisible_tag) +{ + //tag 0 is positioned on all the cells that are not affected by these tags + for (int i=0; i<m_topology->nbCells(); i++) + indivisible_tag[i]=0; + + //treating cell groups + for (int idomain=0; idomain<m_topology->nbDomain();idomain++) + for (int igroup=0; igroup<m_mesh[idomain]->getNumberOfGroups(MED_EN::MED_CELL); igroup++) + for (int i=0; i<m_indivisible_regions.size(); i++) + { + const MEDMEM::GROUP* group = m_mesh[idomain]->getGroup(MED_EN::MED_CELL,igroup+1); + string groupname = group->getName(); + if (trim(groupname)==trim(m_indivisible_regions[i])) + { + int nbcells=group->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); + const int* numbers=group->getNumber(MED_EN::MED_ALL_ELEMENTS); + int* global=new int[nbcells]; + m_topology->convertCellToGlobal(idomain,numbers,nbcells,global); + for (int icell=0; icell<nbcells; icell++) + indivisible_tag[global[icell]-1]=i+1; + delete[] global; + } + } + +} + + +/*! Method creating the cell graph + * + * \param array returns the pointer to the structure that contains the graph + * \param edgeweight returns the pointer to the table that contains the edgeweights + * (only used if indivisible regions are required) + */ + +void MESHCollection::buildCellGraph(MEDMEM::MEDSKYLINEARRAY* & array,int *& edgeweights ) +{ + + int cell_number=1; + int node_number=1; + for (int i=0; i<m_topology->nbDomain(); i++) + { + cell_number+=m_topology->getCellNumber(i); + node_number+=m_topology->getNodeNumber(i); + } + //list of cells for a given node + vector< vector<int> > node2cell(node_number); + + //list of nodes for a given cell + vector< vector <int> > cell2node(cell_number); + +// map<MED_EN::medGeometryElement,int*> type_cell_list; + + //tagging for the indivisible regions + int* indivisible_tag=0; + bool has_indivisible_regions=false; + if (!m_indivisible_regions.empty()) + { + has_indivisible_regions=true; + indivisible_tag=new int[m_topology->nbCells()]; + treatIndivisibleRegions(indivisible_tag); + } + + + //browsing through all domains to create cell->node and node->cell connectivities + for (int idomain=0; idomain<m_topology->nbDomain(); idomain++) + { + // MED_EN::medGeometryElement* type_array; + int nb_cells= m_topology->nbCells(idomain); + int* cell_list = new int[nb_cells]; + + //retrieving global id list + m_topology->getCellList(idomain, cell_list); + + int nb_plain_cells = m_mesh[idomain]->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + + if (nb_plain_cells >0) + { + const int* conn_index = m_mesh[idomain]->getConnectivityIndex(MED_EN::MED_NODAL, + MED_EN::MED_CELL); + + const int* conn = m_mesh[idomain]->getConnectivity(MED_EN::MED_FULL_INTERLACE, + MED_EN::MED_NODAL, + MED_EN::MED_CELL, + MED_EN::MED_ALL_ELEMENTS); + int nbnodes = conn_index[nb_plain_cells]-1; + int* global_nodes =new int [nbnodes]; + m_topology->convertNodeToGlobal(idomain, conn, nbnodes, global_nodes); + //cout << "global nodes"<<endl; + //for (int inode=0; inode<nbnodes;inode++) cout << global_nodes[inode]<<" "; + for (int icell=0; icell< nb_plain_cells; icell++) + { + //cout << " nb nodes"<< conn_index[icell+1]-conn_index[icell]<<endl; + for (int inode=conn_index[icell]; inode < conn_index[icell+1]; inode++) + { + int node_global_id = global_nodes[inode-1]; + int cell_global_id = cell_list[icell]; + cell2node [cell_global_id].push_back(node_global_id); + node2cell [node_global_id].push_back(cell_global_id); + } + } + delete[] global_nodes; + } + if (m_mesh[idomain]->existPolygonsConnectivity(MED_EN::MED_CELL, MED_EN::MED_POLYGON)) + { + + const int* conn_index = m_mesh[idomain]->getPolygonsConnectivityIndex(MED_EN::MED_NODAL, + MED_EN::MED_CELL); + + const int* conn = m_mesh[idomain]->getPolygonsConnectivity(MED_EN::MED_NODAL, + MED_EN::MED_CELL); + + int nb_poly_cells = m_mesh[idomain]->getNumberOfPolygons(); + int nbnodes = conn_index[nb_poly_cells]-1; + int* global_nodes =new int [nbnodes]; + m_topology->convertNodeToGlobal(idomain, conn, nbnodes, global_nodes); + //cout << "global nodes"<<endl; + //for (int inode=0; inode<nbnodes;inode++) cout << global_nodes[inode]<<" "; + for (int icell=0; icell< nb_poly_cells; icell++) + { + //cout << " nb nodes"<< conn_index[icell+1]-conn_index[icell]<<endl; + for (int inode=conn_index[icell]; inode < conn_index[icell+1]; inode++) + { + int node_global_id = global_nodes[inode-1]; + int cell_global_id = cell_list[icell]; + cell2node [cell_global_id].push_back(node_global_id); + node2cell [node_global_id].push_back(cell_global_id); + } + } + delete[] global_nodes; + } + if (m_mesh[idomain]->existPolyhedronConnectivity(MED_EN::MED_CELL, MED_EN::MED_POLYHEDRA)) + { + + const int* conn_index = m_mesh[idomain]->getPolyhedronIndex(MED_EN::MED_NODAL); + const int* conn = m_mesh[idomain]->getPolyhedronConnectivity(MED_EN::MED_NODAL); + const int* face_conn = m_mesh[idomain]->getPolyhedronFacesIndex(); + + int nb_poly_cells = m_mesh[idomain]->getNumberOfPolyhedron(); + int nbfaces = face_conn[nb_poly_cells]-1; + int nbnodes = conn_index[nbfaces]-1; + int* global_nodes =new int [nbnodes]; + m_topology->convertNodeToGlobal(idomain, conn, nbnodes, global_nodes); + //cout << "global nodes"<<endl; + //for (int inode=0; inode<nbnodes;inode++) cout << global_nodes[inode]<<" "; + for (int icell=0; icell< nb_poly_cells; icell++) + { + for (int iface=conn_index[icell]; iface < conn_index[icell+1]; iface++) + { + //cout << " nb nodes"<< conn_index[icell+1]-conn_index[icell]<<endl; + for (int inode=face_conn[iface-1]; inode < face_conn[iface]; inode++) + { + int node_global_id = global_nodes[inode-1]; + int cell_global_id = cell_list[icell]; + cell2node [cell_global_id].push_back(node_global_id); + node2cell [node_global_id].push_back(cell_global_id); + } + } + } + + if (nbnodes>0) delete[] global_nodes; + } + if (nb_cells>0) delete[] cell_list; + } + + cout << "beginning of skyline creation"<<endl; + //creating the MEDMEMSKYLINEARRAY containing the graph + + int* size = new int[m_topology->nbCells()]; + int** temp=new int*[m_topology->nbCells()]; + int** temp_edgeweight=0; + if (has_indivisible_regions) + temp_edgeweight=new int*[m_topology->nbCells()]; + + + + + //going across all cells + + map<int,int> cells_neighbours; + for (int i=0; i< m_topology->nbCells(); i++) + { + + + vector<int> cells(50); + +// /*// cout << "size cell2node "<<cell2node[i+1].size()<<endl; +// for (vector<int>::const_iterator iternode=cell2node[i+1].begin(); +// iternode!=cell2node[i+1].end(); +// iternode++) +// { +// int nodeid=*iternode; +// // cout << "size node2cell "<<node2cell[nodeid].size()<<endl; +// for (vector<int>::const_iterator iter=node2cell[nodeid].begin(); +// iter != node2cell[nodeid].end(); +// iter++) +// cells_neighbours[*iter]++; +// }*/ + + for (int inode=0; inode< cell2node[i+1].size(); inode++) + { + int nodeid=cell2node[i+1][inode]; + // cout << "size node2cell "<<node2cell[nodeid].size()<<endl; + for (int icell=0; icell<node2cell[nodeid].size();icell++) + cells_neighbours[node2cell[nodeid][icell]]++; + } + size[i]=0; + int dimension = getMeshDimension(); + cells.clear(); + + for (map<int,int>::const_iterator iter=cells_neighbours.begin(); iter != cells_neighbours.end(); iter++) + { + if (iter->second >= dimension && iter->first != i+1) + { + cells.push_back(iter->first); + // cells[isize++]=iter->first; + } + } + size[i]=cells.size(); + // size[i]=isize; + + //cout << cells.size()<<endl; + //cout << cells_neighbours.size()<<endl; + + temp[i]=new int[size[i]]; + if (has_indivisible_regions) + temp_edgeweight[i]=new int[size[i]]; +// + int itemp=0; + + // memcpy(temp[i],cells,isize*sizeof(int)); + + for (vector<int>::const_iterator iter=cells.begin(); iter!=cells.end();iter++) + //for(int j=0; j<isize; j++) + { + temp[i][itemp]=*iter; + //temp[i][itemp]=cells[j]; + if (has_indivisible_regions) + { + int tag1 = indivisible_tag[(i+1)-1]; + //int tag2 = indivisible_tag[iter->first-1]; + int tag2 = indivisible_tag[*iter-1]; + if (tag1==tag2 && tag1!=0) + temp_edgeweight[i][itemp]=m_topology->nbCells()*100000; + else + temp_edgeweight[i][itemp]=1; + } + itemp++; + } + cells_neighbours.clear(); + } + cout <<"end of graph definition"<<endl; + int* index=new int[m_topology->nbCells()+1]; + index[0]=1; + for (int i=0; i<m_topology->nbCells(); i++) + index[i+1]=index[i]+size[i]; + + node2cell.clear(); + cell2node.clear(); + if (indivisible_tag!=0) delete [] indivisible_tag; + + //SKYLINEARRAY structure holding the cell graph + array= new MEDMEM::MEDSKYLINEARRAY(m_topology->nbCells(),index[m_topology->nbCells()]); + array->setIndex(index); + + for (int i=0; i<m_topology->nbCells(); i++) + { + array->setI(i+1,temp[i]); + delete[]temp[i]; + } + + + if (has_indivisible_regions) + { + edgeweights=new int[array->getLength()]; + for (int i=0; i<m_topology->nbCells(); i++) + { + for (int j=index[i]; j<index[i+1];j++) + edgeweights[j-1]=temp_edgeweight[i][j-index[i]]; + delete[] temp_edgeweight[i]; + } + delete[]temp_edgeweight; + } + delete[] index; + delete[] temp; + delete[] size; + +cout<< "end of graph creation"<<endl; +} + +/*! Creates the partition corresponding to the cell graph and the partition number + * + * \param nbdomain number of subdomains for the newly created graph + * + * returns a topology based on the new graph + */ +Topology* MESHCollection::createPartition(int nbdomain, + Graph::splitter_type split, + const string& options_string, + int* user_edge_weights, + int* user_vertices_weights) +{ + if (nbdomain <1) throw MEDEXCEPTION("Number of subdomains must be >0"); + MEDMEM::MEDSKYLINEARRAY* array=0; + int* edgeweights=0; + + MESSAGE("Building cell graph"); + buildCellGraph(array,edgeweights); + + switch (split) + { + case Graph::METIS: +#ifdef ENABLE_METIS + m_cell_graph=boost::shared_ptr<Graph>(new METISGraph(array,edgeweights)); +#else + throw MEDEXCEPTION("METIS Graph is not available. Check your products, please."); +#endif + break; + case Graph::SCOTCH: +#ifdef ENABLE_SCOTCH + m_cell_graph=boost::shared_ptr<Graph>(new SCOTCHGraph(array,edgeweights)); +#else + throw MEDEXCEPTION("SCOTCH Graph is not available. Check your products, please."); +#endif + break; + } + + //!user-defined weights + if (user_edge_weights!=0) + m_cell_graph->setEdgesWeights(user_edge_weights); + if (user_vertices_weights!=0) + m_cell_graph->setVerticesWeights(user_vertices_weights); + + MESSAGE("Partitioning graph"); + m_cell_graph->partGraph(nbdomain,options_string); + + MESSAGE("Building new topology"); + //m_cell_graph is a shared pointer + Topology* topology = new ParallelTopology (m_cell_graph, nbdomain, getMeshDimension()); + + //cleaning + if (edgeweights!=0) delete[] edgeweights; + //if (array!=0) delete array; + MESSAGE("End of partition creation"); + return topology; +} + +/*! Creates a topology for a partition specified by the user + * + * \param table user-specified partition (for each cell contains the domain number from 0 to n-1) + * + * returns a topology based on the new partition + */ +Topology* MESHCollection::createPartition(const int* partition) +{ + MEDMEM::MEDSKYLINEARRAY* array=0; + int* edgeweights=0; + + buildCellGraph(array,edgeweights); + + set<int> domains; + for (int i=0; i<m_topology->nbCells(); i++) + { + domains.insert(partition[i]); + } + int nbdomain=domains.size(); + + m_cell_graph=boost::shared_ptr<Graph>(new UserGraph(array, partition, m_topology->nbCells())); + + //m_cell_graph is a shared pointer + Topology* topology = new ParallelTopology (m_cell_graph, nbdomain, getMeshDimension()); + + //if (array!=0) delete array; + return topology; +} + + +/*! building Connect Zones for storing the informations + * of the connectivity + * + * The connect zones are created for every domain that has common nodes with + * domain \a idomain + * + * \param idomain domain number for which the connect zones are created + * */ + +void MESHCollection::buildConnectZones(int idomain) +{ + // constructing node/node correspondencies + vector<MEDMEM::MEDSKYLINEARRAY*> node_node_correspondency; + node_node_correspondency.resize(m_topology->nbDomain()); + m_topology->computeNodeNodeCorrespondencies(idomain, node_node_correspondency ); + + for (int idistant=0; idistant< m_topology->nbDomain(); idistant++) + { + // on regarde si une correspondance noeud/noeud a Ă©tĂ© trouvĂ©e + // entre idomain et idistant + // si oui, on crĂ©e une connectzone + if (node_node_correspondency[idistant]!=0) + { + MEDMEM::CONNECTZONE* cz= new MEDMEM::CONNECTZONE(); + cz->setLocalMesh(m_mesh[idomain]); + cz->setDistantMesh(m_mesh[idistant]); + cz->setLocalDomainNumber(idomain); + cz->setDistantDomainNumber(idistant); + cz-> setName ("Connect zone defined by SPLITTER"); + cz->setNodeCorresp(node_node_correspondency[idistant]); + m_connect_zones.push_back(cz); + } + } + vector<MEDMEM::MEDSKYLINEARRAY*> cell_cell_correspondency; + cell_cell_correspondency.resize(m_topology->nbDomain()); + m_topology->computeCellCellCorrespondencies(idomain, cell_cell_correspondency, m_cell_graph.get()); + + for (int idistant=0; idistant< m_topology->nbDomain(); idistant++) + { + //the connect zone has been created by the node/node computation + if (cell_cell_correspondency[idistant]!=0) + { + MEDMEM::CONNECTZONE* cz=0; + for (int icz=0; icz<m_connect_zones.size();icz++) + if (m_connect_zones[icz]->getLocalDomainNumber()==idomain && + m_connect_zones[icz]->getDistantDomainNumber()==idistant) + cz = m_connect_zones[icz]; + if (cz!=0) + cz->setEntityCorresp(MED_EN::MED_CELL,MED_EN::MED_CELL, cell_cell_correspondency[idistant]); + else + throw MEDEXCEPTION("MESHCollection::buildConnectZones() -A connect zone should exist"); + //delete cell_cell_correspondency[idistant]; + } + + } +} +/*! building Connect Zones for storing the informations + * of the connectivity + * */ + +void MESHCollection::buildConnectZones() +{ + + //Creating nodes + for (int idomain=0; idomain<m_topology->nbDomain(); idomain++) + { + + // constructing node/node correspondencies + vector<MEDMEM::MEDSKYLINEARRAY*> node_node_correspondency; + node_node_correspondency.resize(m_topology->nbDomain()); + m_topology->computeNodeNodeCorrespondencies(idomain, node_node_correspondency ); + + for (int idistant=0; idistant< m_topology->nbDomain(); idistant++) + { + // on regarde si une correspondance noeud/noeud a Ă©tĂ© trouvĂ©e + // entre idomain et idistant + // si oui, on crĂ©e une connectzone + if (node_node_correspondency[idistant]!=0) + { + MEDMEM::CONNECTZONE* cz= new MEDMEM::CONNECTZONE(); + cz->setLocalMesh(m_mesh[idomain]); + cz->setDistantMesh(m_mesh[idistant]); + cz->setLocalDomainNumber(idomain); + cz->setDistantDomainNumber(idistant); + cz-> setName ("Connect zone defined by SPLITTER"); + cz->setNodeCorresp(node_node_correspondency[idistant]); + m_connect_zones.push_back(cz); + } + } + } + + //creating faces if required + if (m_subdomain_boundary_creates) + { + int global_face_id = m_topology->getFaceNumber()+1; + vector <map <MED_EN::medGeometryElement, vector<MEDSPLITTER_FaceModel*> > > face_map(m_topology->nbDomain()); + + map <pair<int,int>, vector<int> > faces_in_joint; + + // taking faces that are already present in the mesh into account + for (int idomain=0; idomain<m_topology->nbDomain(); idomain++) + { + getFaces(idomain,face_map[idomain]); + } + + // creating faces that are located at the interface between + // subdomains + + for (int idomain=0; idomain<m_topology->nbDomain(); idomain++) + { + vector<MEDMEM::MEDSKYLINEARRAY*> cell_cell_correspondency; + cell_cell_correspondency.resize(m_topology->nbDomain()); + + m_topology->computeCellCellCorrespondencies(idomain, cell_cell_correspondency, m_cell_graph.get()); + + for (int idistant=0; idistant< m_topology->nbDomain(); idistant++) + { + if (idistant <= idomain) continue; + + //the connect zone has been created by the node/node computation + + if (cell_cell_correspondency[idistant]!=0) + { + int nbcells = cell_cell_correspondency[idistant]->getNumberOf(); + for (int ilocal=0; ilocal<nbcells; ilocal++) + { + medGeometryElement local_type = m_mesh[idomain]->getElementType(MED_EN::MED_CELL,ilocal+1); + MEDMEM::CELLMODEL local_model (local_type); + const int* index = cell_cell_correspondency[idistant]->getIndex(); + const int* value = cell_cell_correspondency[idistant]->getValue(); + for (int icelldistant = index[ilocal]; icelldistant < index[ilocal+1]; icelldistant++) + { + int distant_id = value[icelldistant-1]; + medGeometryElement distant_type = m_mesh[idistant]->getElementType(MED_EN::MED_CELL,distant_id); + MEDMEM::CELLMODEL distant_model (distant_type); + MEDSPLITTER_FaceModel* face = getCommonFace(idomain,ilocal+1,idistant,distant_id,global_face_id); + face_map[idomain][face->getType()].push_back(face); + MEDSPLITTER_FaceModel* face2 = getCommonFace(idistant,distant_id,idomain, ilocal+1,global_face_id); + face_map[idistant][face->getType()].push_back(face2); + faces_in_joint[make_pair(idomain,idistant)].push_back(global_face_id); + global_face_id++; + } + } + } + + } + //cleaning up + for (int idistant=0; idistant< m_topology->nbDomain(); idistant++) + delete cell_cell_correspondency[idistant]; + } + + + m_topology->recreateFaceMapping(face_map); + + //transforming the face_map into a constituent entity connectivity + for (int idomain=0; idomain< m_topology->nbDomain();idomain++) + { + int nbtypes = face_map[idomain].size(); + vector<medGeometryElement> types; + vector <int> nb_elems; + vector <int*> conn; + + MEDMEM::MESHING* meshing = dynamic_cast<MEDMEM::MESHING*> (m_mesh[idomain]); + MED_EN::medEntityMesh constituent_entity = (getMeshDimension()==3)?MED_EN::MED_FACE:MED_EN::MED_EDGE; + + for (map <medGeometryElement, vector<MEDSPLITTER_FaceModel*> >::const_iterator iter= face_map[idomain].begin(); + iter != face_map[idomain].end(); iter ++) + { + types.push_back(iter->first); + int nb_elem_in_type = (iter->second).size(); + nb_elems.push_back(nb_elem_in_type); + int nb_node_per_type=(iter->first)%100; + int* connectivity= new int [nb_node_per_type*nb_elem_in_type]; + for (int ielem=0; ielem<nb_elem_in_type; ielem++) + { + for (int inode=0; inode<nb_node_per_type; inode++) + connectivity[ielem*nb_node_per_type+inode]=(*(iter->second)[ielem])[inode]; + } + conn.push_back(connectivity); + + } + //setting the faces in the mesh + meshing->setNumberOfTypes(nbtypes,constituent_entity); + meshing->setTypes(&types[0],constituent_entity); + meshing->setNumberOfElements(&nb_elems[0],constituent_entity); + + for (int itype=0; itype<nbtypes; itype++) + { + meshing->setConnectivity(conn[itype], constituent_entity, types[itype]); + delete[]conn[itype]; + } + for (int idistant =0; idistant<m_topology->nbDomain(); idistant++) + { + map <pair<int,int>, vector<int> >::iterator iter; + iter = faces_in_joint.find(make_pair(idomain,idistant)); + if (iter == faces_in_joint.end()) + { + iter = faces_in_joint.find (make_pair(idistant,idomain)); + if (iter == faces_in_joint.end()) + continue; + } + + int nbfaces = (iter->second).size(); + vector<int> face_joint(nbfaces*2); + MEDMEM::CONNECTZONE* cz=0; + for (int icz=0; icz<m_connect_zones.size();icz++) + if (m_connect_zones[icz]->getLocalDomainNumber()==idomain && + m_connect_zones[icz]->getDistantDomainNumber()==idistant) + cz = m_connect_zones[icz]; + + int nbtotalfaces= m_topology->getFaceNumber(idomain); + + //creating arrays for the MEDSKYLINEARRAY structure containing the joint + int* index =new int[nbtotalfaces+1]; + for (int i=0; i<nbtotalfaces+1;i++) + index[i]=0; + int*value=new int[nbfaces]; + + map<int,int> faces; + for (int iface=0; iface<nbfaces; iface++) + { + int iglobal = (iter->second)[iface]; + int localid=m_topology->convertGlobalFace(iglobal,idomain); + int distantid=m_topology->convertGlobalFace(iglobal,idistant); + faces.insert(make_pair(localid,distantid)); + } + + int iloc=0; + index[0]=1; + for (map<int,int>::const_iterator iter=faces.begin(); + iter != faces.end(); + iter++) + { + index[iter->first]=1; + value[iloc++]=iter->second; + } + + //creating a group for the faces constituting the joint + ostringstream jointname ; + jointname << "joint_"<<idistant+1; + MEDMEM::GROUP joint_group; + joint_group.setName(jointname.str().c_str()); + joint_group.setMesh(meshing); + joint_group.setEntity(constituent_entity); + map<MED_EN::medGeometryElement, vector<int> > joint_types; + + for (int i=0; i<nbfaces; i++) + { + int iglobal = (iter->second)[i]; + int localid=m_topology->convertGlobalFace(iglobal,idomain); + MED_EN::medGeometryElement type = meshing->getElementType(constituent_entity,localid); + joint_types[type].push_back(localid); + + } + joint_group.setNumberOfGeometricType(joint_types.size()); + MED_EN::medGeometryElement* types=new MED_EN::medGeometryElement[joint_types.size()]; + int* nb_in_types=new int[joint_types.size()]; + int* group_index=new int[joint_types.size()+1]; + + group_index[0]=1; + int itype=0; + int iface =0; + int* group_value=new int[nbfaces]; + for (map<MED_EN::medGeometryElement, vector<int> >::const_iterator iterj=joint_types.begin(); + iterj != joint_types.end(); + iterj++) + { + nb_in_types[itype]=(iterj->second).size(); + types[itype]=iterj->first; + itype++; + group_index[itype]=group_index[itype-1]+(iterj->second).size(); + for (int i=0; i< (iterj->second).size(); i++) + group_value[iface++]=(iterj->second)[i]; + } + joint_group.setGeometricType(types); + joint_group.setNumberOfElements(nb_in_types); + joint_group.setNumber(group_index, group_value); + delete[] types; + delete[] nb_in_types; + //delete[] group_index; + meshing->addGroup(joint_group); + delete[] group_index; + delete[] group_value; + //end of group creation + + for (int i=0; i<nbtotalfaces;i++) + index[i+1]+=index[i]; + bool shallowcopy=true; + MEDMEM::MEDSKYLINEARRAY* skarray=new MEDMEM::MEDSKYLINEARRAY(nbtotalfaces,nbfaces,index,value,shallowcopy); + + if (cz!=0) + cz->setEntityCorresp(constituent_entity,constituent_entity,skarray); + else + throw MEDEXCEPTION("MESHCollection::buildConnectZones() -A connect zone should exist"); + } + } + + for (int idomain=0; idomain<m_topology->nbDomain(); idomain++) + for (map <medGeometryElement, vector<MEDSPLITTER_FaceModel*> >::const_iterator iter= face_map[idomain].begin(); + iter != face_map[idomain].end(); iter ++) + for (int i=0; i<(iter->second).size();i++) + delete (iter->second)[i]; + } + + + //Creating cell/cell correspondencies + for (int idomain=0;idomain<m_topology->nbDomain();idomain++) + { + vector<MEDMEM::MEDSKYLINEARRAY*> cell_cell_correspondency; + cell_cell_correspondency.resize(m_topology->nbDomain()); + m_topology->computeCellCellCorrespondencies(idomain, cell_cell_correspondency, m_cell_graph.get()); + + for (int idistant=0; idistant< m_topology->nbDomain(); idistant++) + { + //the connect zone has been created by the node/node computation + if (cell_cell_correspondency[idistant]!=0) + { + MEDMEM::CONNECTZONE* cz=0; + for (int icz=0; icz<m_connect_zones.size();icz++) + if (m_connect_zones[icz]->getLocalDomainNumber()==idomain && + m_connect_zones[icz]->getDistantDomainNumber()==idistant) + cz = m_connect_zones[icz]; + if (cz!=0) + cz->setEntityCorresp(MED_EN::MED_CELL,MED_EN::MED_CELL, cell_cell_correspondency[idistant]); + else + throw MEDEXCEPTION("MESHCollection::buildConnectZones() -A connect zone should exist"); + //delete cell_cell_correspondency[idistant]; + } + + } + } +} + +/*! projects old collection families on new collection families + */ +void MESHCollection::castFamilies(const MESHCollection& old_collection) +{ + vector <list<int> > element_array (m_topology->nbDomain()); + + //loop on old domains to create groups out of the existing families + if (m_family_splitting) + for (int idomain=0; idomain < old_collection.m_topology->nbDomain(); idomain++) + old_collection.getMesh(idomain)->createGroups(); + + //definition of the entities array which + //defines the entities over which the information is cast + MED_EN::medEntityMesh entities[3]; + entities[0]=MED_EN::MED_NODE; + entities[2]=MED_EN::MED_CELL; + switch (getMeshDimension()) + { + case 3: + entities[1]= MED_EN::MED_FACE; + break; + case 2: + entities[1]= MED_EN::MED_EDGE; + break; + } + + for (int ientity=0; ientity<=2;ientity++) + { + + //int nbgroups = old_collection.getMesh(0)->getNumberOfGroups(entities[ientity]); + + map <string, set<int> > group_map; + for (int idomain=0; idomain < old_collection.m_topology->nbDomain(); idomain++) + { + for (int igroup=0; igroup<old_collection.getMesh(idomain)->getNumberOfGroups(entities[ientity]); igroup++) + { + //retrieves a group + MEDMEM::GROUP* group = (old_collection.getMesh(idomain)->getGroups(entities[ientity]))[igroup]; + //increments the number of groups if it is a new group + //if (group_map.find(group->getName())==group_map.end()) + + group_map[group->getName()].insert(idomain); + // group_map.insert(make_pair(group->getName(), idomain); + + } + } + int nbgroups=group_map.size(); + vector <int> igroupold(old_collection.m_topology->nbDomain(),0); + map<string,set<int> >::const_iterator iter=group_map.begin(); + + for (int igroup=0; igroup<nbgroups; igroup++) + { + vector <const MEDMEM::SUPPORT*> old_supports(old_collection.m_topology->nbDomain()); + string group_name = iter->first; + iter++; + + //parameters stored for passing group description + // form the old meshes to the new ones + + for (int idomain=0; idomain < old_collection.m_topology->nbDomain(); idomain++) + { + // for (set<int>::iterator iter=group_map[group_name].begin(); iter!=group_map[group_name].end(); iter++) + // cout << *iter<<" "; + // cout <<endl; + if (group_map[group_name].find(idomain)==group_map[group_name].end()) continue; + + //retrieves the group igroup on domain idomain + MEDMEM::GROUP* group = (old_collection.getMesh(idomain)->getGroups(entities[ientity]))[igroupold[idomain]]; + old_supports[idomain] = static_cast<const MEDMEM::SUPPORT*> (group); + igroupold[idomain]++; + } + + vector <MEDMEM::GROUP*>new_groups(m_topology->nbDomain()); + vector <MEDMEM::SUPPORT*> new_supports(m_topology->nbDomain()); + for (int i=0; i<m_topology->nbDomain(); i++) + { + new_groups[i]=new MEDMEM::GROUP(); + new_supports[i]=static_cast<MEDMEM::SUPPORT*>(new_groups[i]); + } + castSupport(old_collection,old_supports,new_supports); + + //creating new groups from the previous list of elements + for (int idomain=0; idomain <m_topology->nbDomain(); idomain++) + { + MEDMEM::MESHING* mesh_builder=static_cast<MEDMEM::MESHING*> (m_mesh[idomain]); + mesh_builder->addGroup(*new_groups[idomain]); + } + //groups are copied by the addGroup method, + //so they can be safely deleted here + for (int i=0; i<m_topology->nbDomain(); i++) + { + delete new_groups[i]; + } + + }// on groups + }//on entities +} + + +void MESHCollection::castSupport(const MESHCollection& old_collection, vector<const MEDMEM::SUPPORT*> old_support, vector<MEDMEM::SUPPORT*> new_support) +{ + + if (old_collection.m_topology->nbDomain() != old_support.size()) + { + throw MED_EXCEPTION(STRING("Error : wrong call to MESHCollection::castSupport")); + } + vector <list<int> > element_array (m_topology->nbDomain()); + + //parameters stored for passing description + // form the old meshes to the new ones + string name; + string description; + MED_EN::medEntityMesh entity; + vector <string> support_name(1); + support_name[0]="support"; + for (int inew=0; inew< m_topology->nbDomain(); inew++) + element_array[inew].clear(); + + for (int idomain=0; idomain < old_collection.m_topology->nbDomain(); idomain++) + { + //retrieves the group igroup on domain idomain + const MEDMEM::SUPPORT* support = old_support[idomain]; + if (old_support[idomain]==0) continue; + name = support->getName(); + description=support->getDescription(); + int nbelem = support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); + if (nbelem==0 && !m_create_empty_groups) continue; + + int* list_of_elems; + if (support->isOnAllElements()) + { + list_of_elems = new int[nbelem]; + for (int i=0; i<nbelem;i++) + list_of_elems[i]=i+1; + } + else + list_of_elems = const_cast<int*> (support->getNumber(MED_EN::MED_ALL_ELEMENTS)); + + int* array=new int[nbelem]; + int* ip=0; + int* local=0; + int* full_array=0; + entity = support->getEntity(); + int size; + + switch (entity) + { + case MED_EN::MED_CELL : + ip=new int[nbelem]; + local= new int[nbelem]; + size=nbelem; + old_collection.getTopology()->convertCellToGlobal(idomain,list_of_elems,nbelem,array); + m_topology->convertGlobalCellList(array,nbelem,local,ip); + for (int i=0; i<nbelem; i++) + // cell_arrays[ip[i]][local[i]]=id; + { + // cout <<"(glob,ip,iloc)/nbelem"<<array[i]<<" "<<ip[i]<<" "<<local[i]<<"/"<<nbelem<<endl; + element_array[ip[i]].push_back(local[i]); + } + break; + case MED_EN::MED_FACE : + case MED_EN::MED_EDGE : + old_collection.getTopology()->convertFaceToGlobal(idomain,list_of_elems,nbelem,array); + m_topology->convertGlobalFaceListWithTwins(array,nbelem,local,ip,full_array,size); + for (int i=0; i<size; i++) + element_array[ip[i]].push_back(local[i]); + delete[] full_array; + break; + case MED_EN::MED_NODE : + old_collection.getTopology()->convertNodeToGlobal(idomain,list_of_elems,nbelem,array); + m_topology->convertGlobalNodeListWithTwins(array,nbelem,local,ip,full_array,size); + for (int i=0; i<size; i++) + element_array[ip[i]].push_back(local[i]); + delete[] full_array; + break; + + } + delete[] ip; + delete[] local; + delete[] array; + + if (support->isOnAllElements()) delete[] list_of_elems; + } + + //creating new groups from the previous list of elements + for (int idomain=0; idomain <m_topology->nbDomain(); idomain++) + { + MEDMEM::SUPPORT* support= new_support[idomain]; + support->setName(name); + support->setMesh(m_mesh[idomain]); + support->setDescription(description); + support->setEntity(entity); + + element_array[idomain].sort(); + element_array[idomain].unique(); + + if (entity != MED_EN::MED_NODE) + support->fillFromElementList(element_array[idomain]); + else + { + support->fillFromNodeList(element_array[idomain]); + } + } +} + +void MESHCollection::castField(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber) +{ + int type=old_collection.getDriver()->getFieldType(fieldname); + char field_char[80]; + strcpy(field_char,fieldname.c_str()); + + if (type ==0) + castFields<int>(old_collection, field_char, itnumber, ordernumber); + else + castFields<double>(old_collection, field_char, itnumber, ordernumber); +} + +void MESHCollection::castAllFields(const MESHCollection& initial_collection) +{ + vector <string> field_names; + vector <int> iternumber; + vector <int> ordernumber; + vector <int> types; + initial_collection.getDriver()->readFileStruct(field_names,iternumber,ordernumber,types); + + for (int i=0; i<field_names.size(); i++) + { + char field_char[80]; + strcpy(field_char,field_names[i].c_str()); + + // choosing whether the field is of int or double type + if (types[i] ==0) + castFields<int>(initial_collection, field_char, iternumber[i], ordernumber[i]); + else + castFields<double>(initial_collection, field_char, iternumber[i], ordernumber[i]); + } +} + +void MESHCollection::createNodalConnectivity(const MESHCollection& initial_collection,int idomain, MED_EN::medEntityMesh entity) +{ + MESSAGE ("beginning of createNodalConnectivity for entity "<<entity); + int dimension=0; + int nb_elems=0; + MEDMEM::MESHING* mesh_builder = static_cast<MEDMEM::MESHING*>(m_mesh[idomain]); + + + //number of elements per type + std::map<MED_EN::medGeometryElement,int> type_numbers; + + //creating arrays for storing global numbers and cell types + switch (entity) + { + case MED_EN::MED_CELL: + dimension=initial_collection.getMeshDimension(); + nb_elems=m_topology->getCellNumber(idomain); + break; + case MED_EN::MED_EDGE: + case MED_EN::MED_FACE: + dimension=initial_collection.getMeshDimension()-1; + nb_elems=m_topology->getFaceNumber(idomain); + break; + default: + nb_elems=0; + break; + } + + if (nb_elems == 0) return; + SCRUTE(nb_elems); + + + int *list= new int[nb_elems]; + MED_EN::medGeometryElement *cell_type_list= new MED_EN::medGeometryElement[nb_elems]; + + + // cout << "Beginning of retrieval "<<endl; + //retrieving global id list + switch (entity) + { + case MED_EN::MED_CELL: + m_topology->getCellList(idomain,list); + break; + case MED_EN::MED_EDGE: + case MED_EN::MED_FACE: + m_topology->getFaceList(idomain,list); + break; + default: + + break; + } + + //retrieving cell_types + initial_collection.getTypeList(list,nb_elems,entity,cell_type_list); + // cout <<"end of type retrieval"<<endl; + //vector containing the number of cells per type + type_numbers.clear(); + for (int icell=0; icell<nb_elems; icell++) + { + map<MED_EN::medGeometryElement,int>::iterator iter= type_numbers.find(cell_type_list[icell]); + if (iter!=type_numbers.end()) + (iter->second)++; + else + type_numbers[cell_type_list[icell]]=1; + + } + //cout << "Nombre de tetras"<<type_numbers[304]<<endl; + int nb_present_types=type_numbers.size(); + + //setting the list of cells for each type + map<MED_EN::medGeometryElement,int> index; + + map<MED_EN::medGeometryElement,int*> type_cell_list; + + MED_EN::MESH_ENTITIES::const_iterator currentEntity; + std::map<MED_EN::medGeometryElement,int>::const_iterator iter; + //currentEntity = MED_EN::meshEntities.find(entity); + for (iter = type_numbers.begin();iter != type_numbers.end(); iter++) + { + MED_EN::medGeometryElement type = iter->first; + if (!isDimensionOK(type,dimension)) continue; + //if (iter->second==0) continue; + index[type]=0; + type_cell_list[type]=new int[type_numbers[type]]; + // cout << "type :"<<type<<" nb:"<<type_numbers[type]<<endl; + } + + for (int icell=0; icell<nb_elems; icell++) + { + type_cell_list[cell_type_list[icell]][index[cell_type_list[icell]]++]=list[icell]; + } + + delete[]list; + delete[]cell_type_list; + + //setting the list of present ypes + int* present_type_numbers=new int[nb_present_types]; + MED_EN::medGeometryElement* type_array = new MED_EN::medGeometryElement[nb_present_types]; + MESSAGE("Nb de types presents "<<nb_present_types); + int itype=0; + for (iter = type_numbers.begin();iter != type_numbers.end(); iter++) + { + MED_EN::medGeometryElement type = iter->first; + if (!isDimensionOK(type,dimension)) continue; + + type_array[itype]=type; + + present_type_numbers[itype]=type_numbers[type]; + + MESSAGE("Nombre d'elements de type "<<type<<" : "<<type_numbers[type]); + itype++; + } + + //retrieving connectivity in global numbering for each typeinitial_collection.getMesh(iold)->get + map<MED_EN::medGeometryElement,int*> type_connectivity; + vector<int> polygon_conn; + vector<int> polygon_conn_index; + vector<int> polyhedron_conn; + vector<int> polyhedron_conn_index; + vector<int> polyhedron_face_index; + + //Treating nodes + + + for (iter = type_numbers.begin();iter != type_numbers.end(); iter++) + { + MED_EN::medGeometryElement type = iter->first; + + + if (!isDimensionOK(type,dimension)) continue; + //if (type_numbers[type]==0) continue; + if (type != MED_EN::MED_POLYGON && type != MED_EN::MED_POLYHEDRA) + { + int nbnode_per_type = (int)type%100; + type_connectivity[type]=new int[type_numbers[type]*nbnode_per_type]; + initial_collection.getNodeConnectivity(type_cell_list[type],type_numbers[type],entity,type,type_connectivity[type]); + } + else if (type == MED_EN::MED_POLYGON && dimension==2) + { + initial_collection.getPolygonNodeConnectivity(type_cell_list[type],type_numbers[type],entity,polygon_conn,polygon_conn_index); + //type_connectivity[type]=&polygon_conn[0]; + } + else if (type == MED_EN::MED_POLYHEDRA && dimension==3) + { + initial_collection.getPolyhedraNodeConnectivity(type_cell_list[type],type_numbers[type],entity,polyhedron_conn, + polyhedron_conn_index, polyhedron_face_index); + //type_connectivity[type]=&polygon_conn[0]; + } + delete[] type_cell_list[type]; + } + + //creating node mapping + //!TODO : compute the total number of nodes + if (entity==MED_EN::MED_CELL) + { + m_topology->createNodeMapping(type_connectivity,type_numbers,polygon_conn,polygon_conn_index, + polyhedron_conn,polyhedron_conn_index,polyhedron_face_index,idomain); + } + + //converting node global numberings to local numberings + //for (iter = (*currentEntity).second.begin();iter != (*currentEntity).second.end(); iter++) + for (iter = type_numbers.begin();iter != type_numbers.end(); iter++) + { + MED_EN::medGeometryElement type = iter->first; + + if (!isDimensionOK(type, dimension)) continue; + if (type_numbers[type]==0) continue; + if (type != MED_EN::MED_POLYGON && type != MED_EN::MED_POLYHEDRA) + { + int nbnode_per_type = (int)type%100; + m_topology->convertToLocal2ndVersion(type_connectivity[type],type_numbers[type]*nbnode_per_type,idomain); + } + else if (type == MED_EN::MED_POLYGON && dimension==2) + { + int nbpoly = type_numbers[type]; + m_topology->convertToLocal2ndVersion(&polygon_conn[0], polygon_conn_index[nbpoly]-1, idomain); + } + else if (type == MED_EN::MED_POLYHEDRA && dimension==3) + { + int nbpoly = type_numbers[type]; + m_topology->convertToLocal2ndVersion(&polyhedron_conn[0], polyhedron_face_index[polyhedron_conn_index[nbpoly]-1]-1, idomain); + } + + } + + + //writing coordinates + if (entity==MED_EN::MED_CELL) + { + //setting coordinates from initial_collection coordinates + int nbnode=m_topology->getNodeNumber(idomain); + MESSAGE("Number of nodes on domain "<< idomain <<" : "<<nbnode); + + double* coordinates=new double[initial_collection.getSpaceDimension()*nbnode]; + int* node_list=new int[nbnode]; + m_topology->getNodeList(idomain,node_list); + initial_collection.getCoordinates(node_list,nbnode,coordinates); + delete[] node_list; + + // redundant specification of number of nodes is required!! MED imperfection, sorry... + + mesh_builder->setNumberOfNodes(nbnode); + //TODO : change MEDMEM so that it accepts a direct setting of coordinates + // (in the present version, it is deep-copied) + mesh_builder->setCoordinates(initial_collection.getSpaceDimension(), + m_topology->getNodeNumber(idomain), coordinates, initial_collection.getSystem(), + MED_EN::MED_FULL_INTERLACE); + delete [] coordinates; + } + + int nb_plain_types=0; + for (iter = type_numbers.begin();iter != type_numbers.end(); iter++) + { + MED_EN::medGeometryElement type = iter->first; + + if (!isDimensionOK(type, dimension)) continue; + if (type_numbers[type]==0) continue; + if (type != MED_EN::MED_POLYGON && type != MED_EN::MED_POLYHEDRA) + nb_plain_types++; + } + mesh_builder->setNumberOfTypes(nb_plain_types,entity); + mesh_builder->setTypes(type_array,entity); + mesh_builder->setNumberOfElements(present_type_numbers,entity); + if (entity==MED_EN::MED_CELL) + mesh_builder->setMeshDimension(dimension); + + delete[]present_type_numbers; + delete[]type_array; + //setting node connectivities + for (iter = type_numbers.begin();iter != type_numbers.end(); iter++) + { + MED_EN::medGeometryElement type = iter->first; + + if (!isDimensionOK(type,dimension)) continue; + if (type_numbers[type]==0) continue; + + if (type != MED_EN::MED_POLYHEDRA && type != MED_EN::MED_POLYGON) + { + mesh_builder->setConnectivity(type_connectivity[type],entity,type); + delete[] type_connectivity[type]; + } + else if (type == MED_EN::MED_POLYGON && dimension ==2) + { + mesh_builder->setPolygonsConnectivity(&polygon_conn_index[0], + &polygon_conn[0], + type_numbers[type], + entity); + } + else if (type == MED_EN::MED_POLYHEDRA && dimension ==3) + { + mesh_builder->setPolyhedraConnectivity(&polyhedron_conn_index[0], + &polyhedron_face_index[0], + &polyhedron_conn[0], + type_numbers[type], + entity); + + } + } + MESSAGE("end of createNodalConnectivity"); +} + + +/*! retrieves the faces that are present in a mesh and stores them in a + * dynamic structure made of a map of MEDSPLITTER_FaceModel + * + * \param idomain domain id on which the faces are collected + * \param face_map container storing the faces + */ +void MESHCollection::getFaces(int idomain, + map<MED_EN::medGeometryElement, vector<MEDSPLITTER_FaceModel*> >& face_map) +{ + MED_EN::medEntityMesh constituent_entity = (getMeshDimension()==3)?MED_EN::MED_FACE:MED_EN::MED_EDGE; + const medGeometryElement* types; + try + { + types = m_mesh[idomain]->getTypes(constituent_entity); + } + catch(MEDEXCEPTION){ return;} + + int nbtypes = m_mesh[idomain]->getNumberOfTypes(constituent_entity); + const int* global_numbering= m_mesh[idomain]->getGlobalNumberingIndex(constituent_entity); + int* conn = const_cast<int*> (m_mesh[idomain]->getConnectivity(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_NODAL,constituent_entity, MED_EN::MED_ALL_ELEMENTS)); + for (int itype=0; itype<nbtypes; itype++) + { + for (int iface=global_numbering[itype]; iface<global_numbering[itype+1]; iface++) + { + MEDSPLITTER_FaceModel* face_model = new MEDSPLITTER_FaceModel(); + MED_EN::medGeometryElement type = types[itype]; + face_model->setType(type); + int nbnodes = type%100; + face_model->setNbNodes(nbnodes); + face_model->setGlobal(m_topology->convertFaceToGlobal(idomain,iface)); + for (int i=0; i<nbnodes; i++) + { + (*face_model)[i]=*conn++; + } + face_map[type].push_back(face_model); + } + } +} + +/*! retrieves the face that is common to two cells located on two different processors + * + * \param ip1 domain id for cell 1 + * \param ilocal1 cell id for cell 1 + * \param ip2 domain id for cell 2 + * \param ilocal2 cell id for cell 2 + * \param face_index global index for the newly created face + */ +MEDSPLITTER_FaceModel* MESHCollection::getCommonFace(int ip1,int ilocal1,int ip2,int ilocal2,int face_index) +{ + MEDSPLITTER_FaceModel* face_model = new MEDSPLITTER_FaceModel(); + + MED_EN::medGeometryElement type1 = m_mesh[ip1]->getElementType(MED_EN::MED_CELL,ilocal1); + MEDMEM::CELLMODEL celltype1 (type1); + + const int* conn_index1 = m_mesh[ip1]->getConnectivityIndex(MED_EN::MED_NODAL,MED_EN::MED_CELL); + const int* conn1 = m_mesh[ip1]->getConnectivity(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_NODAL,MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + + // MED_EN::medGeometryElement type2 = m_mesh[ip2]->getElementType(MED_EN::MED_CELL,ilocal2); + //MEDMEM::CELLTYPE celltype2 (type2); + const int* conn_index2 = m_mesh[ip2]->getConnectivityIndex(MED_EN::MED_NODAL,MED_EN::MED_CELL); + const int* conn2 = m_mesh[ip2]->getConnectivity(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_NODAL,MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + + vector<int> nodes1; + vector<int> nodes2; + for (int i= conn_index1[ilocal1-1]; i<conn_index1[ilocal1]; i++) + nodes1.push_back(m_topology->convertNodeToGlobal(ip1,*(conn1+i-1))); + for (int i= conn_index2[ilocal2-1]; i<conn_index2[ilocal2]; i++) + nodes2.push_back(m_topology->convertNodeToGlobal(ip2,*(conn2+i-1))); + + int nbfaces= celltype1.getNumberOfConstituents(1); + int ** faces = celltype1.getConstituents(1); + MED_EN::medGeometryElement* types = celltype1.getConstituentsType(1); + int iface=0; + + while (iface<nbfaces) + { + //SCRUTE (iface); + int nbnodes= types[iface]%100; + const int* nodes = celltype1.getNodesConstituent(1,iface+1); + int common_nodes=0; + int dimension=getMeshDimension(); + for (int i=0; i<nbnodes;i++) + { + for (int i2=0; i2<nodes2.size(); i2++) + { + if (nodes1[nodes[i]-1]==nodes2[i2]) common_nodes++; + } + } + if (common_nodes>=dimension) break; + iface++; + } + + if (iface==nbfaces) + throw MEDEXCEPTION("MEDSPLITTER::buildCommonFace - No common face found !"); + face_model->setType(types[iface]); + int nbnodes = types[iface]%100; + face_model->setNbNodes(nbnodes); + face_model->setGlobal(face_index); + for (int i=0; i<nbnodes; i++) + (*face_model)[i]=m_topology->convertGlobalNode(nodes1[faces[iface][i]-1],ip1); + + return face_model; +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.hxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.hxx new file mode 100644 index 000000000..e1a1b43dc --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollection.hxx @@ -0,0 +1,211 @@ +#ifndef MESHCOLLECTION_ +#define MESHCOLLECTION_ + +#include "MEDSPLITTER.hxx" + +//#include "MESHCollectionDriver.hxx" +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_FaceModel.hxx" +#include "boost/shared_ptr.hpp" +#include <vector> + + +namespace MEDMEM{ +class MESH; +class CONNECTZONE; +class MEDSKYLINEARAY; +class SUPPORT; +} + +namespace MEDSPLITTER{ + +class Topology; +class MESHCollectionDriver; + +typedef enum{MedAscii, MedXML, Undefined} DriverType; + +class MEDSPLITTER_EXPORT MESHCollection +{ + +public: + +//Default constructor +MESHCollection(); + +//Constructing from an existing mesh and a new topology + MESHCollection(const MESHCollection&, Topology*, bool family_splitting=false, bool create_empty_groups=false); + +//Constructing the mesh collection from a file +MESHCollection(const std::string& filename); + +//Constructing the mesh collection from a file +MESHCollection(const std::string& filename, const std::string& meshname); + +~MESHCollection(); + +//writing to a distributed file +void write(const std::string& filename); + +//getting the driver +MESHCollectionDriver* retrieveDriver(); +MESHCollectionDriver* getDriver() const; + void setDriverType(MEDSPLITTER::DriverType type) {m_driver_type=type;} + +//creation of the cell graph +void buildCellGraph(MEDMEM::MEDSKYLINEARRAY* & array,int *& edgeweights ); + +//creation and partition of the associated graph + Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS, + const string& ="", int* edgeweights=0, int* verticesweights=0); + +//creation of a user specified partition +Topology* createPartition(const int* partition); + +//retrieving list of types +void getTypeList(int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + MED_EN::medGeometryElement* type_list) const ; + +//getting list of coordinates +void getCoordinates(int* node_list,int nb_nodes, double* coordinates) const ; + +//getting connectivities +void getNodeConnectivity( const int* cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ; +void getPolygonNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + vector<int>& type_connectivity, vector<int>& connectivity_index) const; +void getPolyhedraNodeConnectivity(const int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + vector<int>& type_connectivity, vector<int>& connectivity_index, vector<int>& face_connectivity_index) const; + +void getFaceConnectivity( const int* cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ; + + //void getFaceConnectivity( const int* cell_list,int nb_cells,MED_EN::medGeometryElement type, int* type_connectivity) const ; + +//getting mesh dimension +int getMeshDimension() const ; + +//getting space dimension +int getSpaceDimension() const ; + +//getting system of coordinates +std::string getSystem() const; + +//getting name of the mesh +std::string getMeshName() const; + +//getting a reference to mesh vector +std::vector<MEDMEM::MESH*>& getMesh() ; + +//getting a reference to mesh vector +MEDMEM::MESH* getMesh(int) const; + +//getting a reference to connect zones vector +std::vector<MEDMEM::CONNECTZONE*>& getCZ(); + +//getting a pointer to topology +Topology* getTopology() const ; + + +//settig a new topology +void setTopology(Topology* topology); + +//getting/setting the name of the global mesh (as opposed +//to the name of a subdomain \a nn, which is name_nn) +string getName() const {return m_name;} +void setName(const string& name) {m_name=name;} + +//getting/setting the description of the global mesh +string getDescription() const {return m_description;} +void setDescription(const string& name) { m_description=name;} + +//!transfers families from an old MESHCollection to new mesh +void castFamilies(const MESHCollection& old_collection); + +void castSupport(const MESHCollection& old_collection, std::vector<const MEDMEM::SUPPORT*> old_support, std::vector<MEDMEM::SUPPORT*> new_support); + +//!casts all the fields to the new mesh collection +void castAllFields(const MESHCollection& old_collection); + +//!casts one specific field to the new mesh collection +void castField(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber); + +//choosing a group to be indivisible +void setIndivisibleGroup(const string& a); + +//!constructing connect zones +void buildConnectZones(int idomain); +void buildConnectZones(); + +bool isDimensionOK(MED_EN::medGeometryElement type, int dim) +{ + return ((type/100 == dim) || (dim==2 && type == MED_EN::MED_POLYGON) || (dim==3 && type == MED_EN::MED_POLYHEDRA)); +} +void setSubdomainBoundaryCreates(bool flag) { m_subdomain_boundary_creates=flag;} +bool getSubdomainBoundaryCreates(){return m_subdomain_boundary_creates;} + + void setFamilySplitting(bool flag){m_family_splitting=flag;} + bool getFamilySplitting(){return m_family_splitting;} + + void setCreateEmptyGroups(bool flag){m_create_empty_groups=flag;} + bool getCreateEmptyGroups(){return m_create_empty_groups;} +private: +//!creates connectivities for a domain and an entity (face or cell) +void createNodalConnectivity(const MESHCollection & initial_collection, int idomain, MED_EN::medEntityMesh entity); + +//!creates the tags for indivisible groups +void treatIndivisibleRegions(int* tag); + +//!projects a field from an old collection to the present one +//!field is identified by (name, dt, it) +template <class T> +void castFields(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber); + +void getFaces(int idomain, std::map<MED_EN::medGeometryElement, vector<MEDSPLITTER_FaceModel*> >&); + +MEDSPLITTER_FaceModel* getCommonFace(int ip1,int ilocal1,int ip2,int ilocal2,int face_index); + + +//!link to mesh_collection topology +Topology* m_topology; + +//!control over topology +bool m_owns_topology; + +//!link to graph +boost::shared_ptr<Graph> m_cell_graph; + +//! Driver for read/write operations +MESHCollectionDriver* m_driver; + +//!links to meshes +std::vector<MEDMEM::MESH*> m_mesh; + +//!links to connectzones +std::vector<MEDMEM::CONNECTZONE*> m_connect_zones; + +//!list of groups that are not to be splitted +std::vector<std::string> m_indivisible_regions; + +//!name of global mesh +string m_name; + +//!description of global mesh +string m_description; + +//! specifies the driver associated to the collection +DriverType m_driver_type; + +/*! flag specifying that the splitter should create boundary constituent entity +so that they are written in joints*/ +bool m_subdomain_boundary_creates; + + /*! flag specifying that families must be preserved by the + splitting*/ + bool m_family_splitting; + + /*! flag specifying that groups must be created on all domains, + even if they are empty*/ + bool m_create_empty_groups; +}; + +}//of namespace + +#endif /*MESHCOLLECTION_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.H b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.H new file mode 100644 index 000000000..b71ea2d0f --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.H @@ -0,0 +1,73 @@ +#ifndef MEDSPLITTER_MESHCOLLECTIONDRIVER_H +#define MEDSPLITTER_MESHCOLLECTIONDRIVER_H + + +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +/*!reads a distributed field + * + * \param fields vector of fields (one field per subdomain) + * \param fieldname name of the field + * \param itnumber number of iteration + * \param ordernumber internal number inside the iteration + * */ +template <class T> +void MESHCollectionDriver::readFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname, int itnumber, int ordernumber) +{ + for (int i=0; i<m_collection->getMesh().size(); i++) + { + char filename[256]; + strcpy(filename,m_filename[i].c_str()); + cout << "maillage : " << filename << " champ : " << fieldname << endl; + // MEDMEM::FIELD<T>* field = new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber); + fields.push_back (new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber)); + } +} + + +/*!writes a distributed field + * + * \param fields vector of fields (one field per subdomain) + * \param fieldname name of the field + * */ +template <class T> +void MESHCollectionDriver::writeFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname) +{ + xmlDocPtr master_doc=xmlParseFile(m_master_filename.c_str()); + + if (!master_doc) + throw MEDEXCEPTION("MEDSPLITTER writeFields - Master File does not exist"); + + //number of domains + + xmlXPathContextPtr xpathCtx = xmlXPathNewContext(master_doc); + xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(BAD_CAST "//mapping/mesh", xpathCtx); + //assuming there is only one mesh in the XML file + xmlNodePtr mesh_node= xpathObj->nodesetval->nodeTab[0]; + xmlNodePtr field_node = xmlNewChild(mesh_node, 0, BAD_CAST "field",0); + xmlNewProp(field_node,BAD_CAST "name",BAD_CAST fieldname); + + + for (int i=0; i<m_collection->getMesh().size(); i++) + { + char filename[256]; + strcpy(filename,m_filename[i].c_str()); + int driverid = fields[i]->addDriver(MEDMEM::MED_DRIVER, filename, fieldname); + fields[i]->write(driverid); + xmlNodePtr chunk_node= xmlNewChild(field_node,0,BAD_CAST "chunk",0); + char id[8]; + sprintf(id,"%d",i+1); + xmlNewProp(chunk_node,BAD_CAST "subdomain",BAD_CAST id); + xmlNewProp(chunk_node,BAD_CAST "name", BAD_CAST fieldname); + + } + xmlSaveFormatFileEnc(m_master_filename.c_str(), master_doc, "UTF-8", 1); + xmlFreeDoc(master_doc); + xmlCleanupParser(); + +} + +#endif diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.cxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.cxx new file mode 100644 index 000000000..84dc23812 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.cxx @@ -0,0 +1,534 @@ + +#include <vector> +#include <string> +#include <map> +#include <set> + +#include <iostream> +#include <fstream> + +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +#include <sys/time.h> +//Debug macros +#include "MEDMEM_Utilities.hxx" + +//MEDMEM includes +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_ConnectZone.hxx" + +//MEDSPLITTER includes +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" +#include "MEDSPLITTER_MESHCollectionDriver.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" + +using namespace MEDSPLITTER; + +//template inclusion +//#include "MEDSPLITTER_MESHCollectionDriver.H" + + +MESHCollectionDriver::MESHCollectionDriver(MESHCollection* collection):m_collection(collection) +{ +} + + +/*!reads a unique MED File v>=2.1 + * and mounts the corresponding mesh in memory + *\param filename binary file + *\param meshname mesh name in the MED file + * */ +int MESHCollectionDriver::readSeq(char* filename, char* meshname) +{ + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::readSeq()"); + + m_filename.resize(1); + m_filename[0]=string(filename); + //puts the only mesh in the mesh vector + MEDMEM::MESH* new_mesh = new MEDMEM::MESH(MEDMEM::MED_DRIVER,filename, meshname); + (m_collection->getMesh()).push_back(new_mesh); + + m_collection->setName(meshname); + (m_collection->getCZ()).clear(); + vector<int*> cellglobal,nodeglobal,faceglobal; + cellglobal.resize(1); + nodeglobal.resize(1); + faceglobal.resize(1); + cellglobal[0]=0; + nodeglobal[0]=0; + faceglobal[0]=0; + //creation of topology from mesh + //connectzone argument is 0 + ParallelTopology* aPT = new ParallelTopology + ((m_collection->getMesh()), (m_collection->getCZ()), cellglobal, nodeglobal, faceglobal); + m_collection->setTopology(aPT); + END_OF("MEDSPLITTER::MESHCollectionDriver::readSeq()"); + return 0; +} + +/*! + * Reads the file structure to determine the list + * of all the available fields + * + * \param field_names, vector<string> containing the field names + * \param iternumber, vector<int> containing the iteration numbers + * \param ordernumber, vector<int> containing the order numbers + * \param types, vector<int> containing 0 for int fields and 1 for double fields + * + */ + +void MESHCollectionDriver::readFileStruct(vector <string>& field_names,vector<int>& iternumber,vector <int>& ordernumber, vector <int>& types) +{ + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::readFileStruct()") + + const MEDMEM::MED med_struct (MEDMEM::MED_DRIVER,m_filename[0]); + int nb_fields = med_struct.getNumberOfFields(); + + MESSAGE("found "<<nb_fields<<" fields in file") + deque<string> names = med_struct.getFieldNames(); + for (int ifield = 0; ifield < nb_fields; ifield++) + { + deque<MEDMEM::DT_IT_> dtit=med_struct.getFieldIteration(names[ifield]); + + for (deque<MEDMEM::DT_IT_>::const_iterator iter =dtit.begin(); iter!=dtit.end(); iter++) + { + field_names.push_back(names[ifield]); + iternumber.push_back(iter->dt); + ordernumber.push_back(iter->it); + + // testing whether the field is of double or int type + MEDMEM::FIELD_* field = med_struct.getField(names[ifield],iter->dt,iter->it); + if (dynamic_cast<MEDMEM::FIELD<double>*>(field)) + types.push_back(1); + else + types.push_back(0); + + } + } + END_OF("MEDSPLITTER::MESHCollectionDriver::readFileStruct()") + } + +//!retrieves the type of a field for a given fieldname +int MESHCollectionDriver::getFieldType(const string& fieldname) +{ + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::getFieldType()") + const MEDMEM::MED med_struct (MEDMEM::MED_DRIVER,m_filename[0]); + + deque<MEDMEM::DT_IT_> dtit=med_struct.getFieldIteration(fieldname); + deque<MEDMEM::DT_IT_>::const_iterator iter =dtit.begin(); + + // testing whether the field is of double or int type + MEDMEM::FIELD_* field = med_struct.getField(fieldname,iter->dt,iter->it); + + END_OF("MEDSPLITTER::MESHCollectionDriver::getFieldType()") + + if (dynamic_cast<MEDMEM::FIELD<double>*>(field)) + return 1; + else + return 0; + + } + + +void MESHCollectionDriver::readSubdomain(const string& meshstring, +vector<int*>& cellglobal, +vector<int*>& faceglobal, +vector<int*>& nodeglobal, int idomain +) +{ + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::readSubdomain()"); + char file[256]; + char meshname[MED_TAILLE_NOM]; + + strcpy(meshname,meshstring.c_str()); + strcpy(file,m_filename[idomain].c_str()); + cout << "Reading "<<meshstring<<" in "<<m_filename[idomain]<<endl; + (m_collection->getMesh())[idomain]=new MEDMEM::MESH(MEDMEM::MED_DRIVER,file, meshname); + cout <<"End of Read"<<endl; + //reading MEDSPLITTER::CONNECTZONEs NODE/NODE and CELL/CELL + med_2_3::med_idt fid = med_2_3::MEDouvrir(file,med_2_3::MED_LECTURE); + med_2_3::med_int njoint = med_2_3::MEDnJoint(fid, meshname); + for (int ijoint=0; ijoint<njoint; ijoint++) + { + int distant; + char joint_description[MED_TAILLE_DESC]; + char name[MED_TAILLE_NOM]; + char name_distant[MED_TAILLE_NOM]; + + int ncorr = med_2_3::MEDjointInfo(fid,meshname, ijoint+1, name, + joint_description, + &distant, name_distant); + + for (int ic=0; ic<ncorr; ic++) + { + med_2_3::med_entite_maillage cor_typent_local; + med_2_3::med_geometrie_element cor_typgeo_local; + med_2_3::med_entite_maillage cor_typent_dist; + med_2_3::med_geometrie_element cor_typgeo_dist; + + + int ncouples; + ncouples = med_2_3::MEDjointTypeCorres(fid, meshname, name, ic+1, + &cor_typent_local, &cor_typgeo_local, + &cor_typent_dist, &cor_typgeo_dist + ); + int* node_corresp=new int[ncouples]; + if (cor_typent_local == med_2_3::MED_NOEUD && cor_typent_dist == med_2_3::MED_NOEUD) + { + + med_2_3::MEDjointLire(fid, meshname, name, + node_corresp,ncouples, + cor_typent_local, cor_typgeo_local, + cor_typent_dist, cor_typgeo_dist + ); + } + //constructing the connect zone and adding it to the connect zone list + MEDMEM::CONNECTZONE* cz = new MEDMEM::CONNECTZONE(); + cz->setName(string(name)); + cz->setDescription(joint_description); + cz->setLocalDomainNumber(idomain); + cz->setDistantDomainNumber(distant); + cz->setLocalMesh((m_collection->getMesh())[idomain]); + cz->setDistantMesh((m_collection->getMesh())[distant]); + cz->setNodeCorresp(node_corresp,ncouples); + (m_collection->getCZ()).push_back(cz); + + }//loop on correspom_topology->nbDomain())ndances + }//loop on joints + + // Reading global numbering + // + int ncell=(m_collection->getMesh())[idomain]->getNumberOfElementsWithPoly(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + if (ncell>0) + { + int * array=new int[ncell]; + int offset=0; + MESSAGE("Reading cell global numbering for mesh "<< idomain); + list<MED_EN::medGeometryElement>::const_iterator iter; + char meshchar[MED_TAILLE_NOM]; + strcpy(meshchar,(m_collection->getMesh())[idomain]->getName().c_str()); + int nbtypes = (m_collection->getMesh())[idomain]->getNumberOfTypesWithPoly(MED_EN::MED_CELL); + MED_EN::medGeometryElement* types =(m_collection->getMesh())[idomain]->getTypesWithPoly(MED_EN::MED_CELL); + for (int itype=0; itype<nbtypes;itype++) + { + MED_EN::medGeometryElement type=types[itype]; + if (!m_collection->isDimensionOK(type,m_collection->getMeshDimension())) continue; + int ntype = (m_collection->getMesh())[idomain]->getNumberOfElementsWithPoly(MED_EN::MED_CELL,type); + if (ntype==0) continue; + med_2_3::MEDglobalNumLire(fid,meshname, array+offset, ntype, + med_2_3::MED_MAILLE, (med_2_3::med_geometrie_element)type); + offset+=ntype; + } + cellglobal[idomain]=array; + delete[] types; + } + + MESSAGE("Reading node global numbering"); + int nnode= (m_collection->getMesh())[idomain]->getNumberOfNodes(); + { + int* array=new int[nnode]; + med_2_3::MEDglobalNumLire(fid,meshname, array, nnode, + med_2_3::MED_NOEUD, med_2_3::MED_POINT1); + nodeglobal[idomain]=array; + } + + MESSAGE("Reading face global numbering for mesh "<<idomain); + int nbface=(m_collection->getMesh())[idomain]->getNumberOfElementsWithPoly(MED_EN::MED_FACE,MED_EN::MED_ALL_ELEMENTS); + if (nbface!=0) + { + int* array=new int[nbface]; + int offset=0; + int nbtypes = (m_collection->getMesh())[idomain]->getNumberOfTypesWithPoly(MED_EN::MED_FACE); + MED_EN::medGeometryElement* types =(m_collection->getMesh())[idomain]->getTypesWithPoly(MED_EN::MED_FACE); + + for (int itype=0; itype< nbtypes; itype++) + { + MED_EN::medGeometryElement type=types[itype]; + if (!m_collection->isDimensionOK(type,m_collection->getMeshDimension()-1)) continue; + + int ntype = (m_collection->getMesh())[idomain]->getNumberOfElementsWithPoly(MED_EN::MED_FACE,type); + if (ntype==0) continue; + med_2_3::MEDglobalNumLire(fid,meshname, array+offset, ntype, + med_2_3::MED_FACE, (med_2_3::med_geometrie_element)type); + offset+=ntype; + } + faceglobal[idomain]=array; + delete[] types; + } + med_2_3::MEDfermer(fid); + + // if (nbface!=0) delete[]array; + END_OF("MEDSPLITTER::MESHCollectionDriver::readSubdomain()"); + } + + void MESHCollectionDriver::writeSubdomain(int idomain, int nbdomains, char* distfilename) + { + //build connect zones +// if (nbdomains>1) +// m_collection->buildConnectZones(idomain); + + MESSAGE(" Number of connect zones "<<(m_collection->getCZ()).size()); + + //writing connect zones in joints + + med_2_3::med_idt fid = med_2_3::MEDouvrir(distfilename,med_2_3::MED_LECTURE_ECRITURE); + + int index_joint=0; + + for (int icz=0; icz<(m_collection->getCZ()).size(); icz++) + { + if ((m_collection->getCZ())[icz]->getLocalDomainNumber()==idomain) + { + med_2_3::med_err error; + int idistant=(m_collection->getCZ())[icz]->getDistantDomainNumber(); + char joint_name[MED_TAILLE_NOM]; + sprintf(joint_name,"joint_%i",idistant+1); + char desc[MED_TAILLE_DESC]; + sprintf(desc,"connect_zone_%d",icz+1); + + char distant_name[MED_TAILLE_NOM]; + //sprintf(distant_name,"domain_%i",(m_collection->getCZ())[icz]->getDistantDomainNumber()); + + sprintf(distant_name,(m_collection->getMesh())[idistant]->getName().c_str()); + char mesh_name[MED_TAILLE_NOM]; + + strcpy (mesh_name, m_collection->getMesh(idomain)->getName().c_str()); + SCRUTE(m_collection->getMesh(idomain)->getName()); + error = med_2_3::MEDjointCr(fid,mesh_name, joint_name, desc, + idistant, distant_name); + if (error==-1) cout << "erreur creation de joint "<<endl; + + ///////////////////////////////////////// + //writing node/node correspondency + ///////////////////////////////////////// + int nbnodes=(m_collection->getCZ())[icz]->getNodeNumber(); + int* node_corresp=const_cast<int*>((m_collection->getCZ())[icz]->getNodeCorrespValue()); + + /* Nodes are reordered so that the ordering on the local and the distant domain + correspond. The chosen order is the natural ordering on the domain + with lowest proc id*/ + if (m_collection->getSubdomainBoundaryCreates()) + if (idomain<idistant) + jointSort(node_corresp, nbnodes, true); + else + jointSort(node_corresp, nbnodes, false); + + error= + med_2_3::MEDjointEcr(fid, mesh_name, joint_name, node_corresp, nbnodes, + med_2_3::MED_NOEUD, med_2_3::MED_POINT1,med_2_3::MED_NOEUD, med_2_3::MED_POINT1); + if (error==-1) cout << "erreur creation de joint "<<endl; + + //writing cell/cell joint + writeElementJoint(MED_EN::MED_CELL, icz, idomain, idistant, mesh_name,joint_name,fid); + //writing face/face joint + if (m_collection->getSubdomainBoundaryCreates()) + { + MED_EN::medEntityMesh constituent_entity = + (m_collection->getMeshDimension()==3)?MED_EN::MED_FACE:MED_EN::MED_EDGE; + writeElementJoint(constituent_entity, icz, idomain, idistant, mesh_name,joint_name,fid); + } + index_joint++; + } + } + + // Writing cell global numbering + // + int ncell=m_collection->getTopology()->getCellNumber(idomain); + int * array=new int[ncell]; + m_collection->getTopology()->getCellList(idomain,array); + int offset=0; + + MED_EN::MESH_ENTITIES::const_iterator currentEntity; + list<MED_EN::medGeometryElement>::const_iterator iter; + currentEntity = MED_EN::meshEntities.find(MED_EN::MED_CELL); + char meshchar[MED_TAILLE_NOM]; + strcpy(meshchar,(m_collection->getMesh())[idomain]->getName().c_str()); + int nbtypes = (m_collection->getMesh())[idomain]->getNumberOfTypesWithPoly(MED_EN::MED_CELL); + MED_EN::medGeometryElement* types =(m_collection->getMesh())[idomain]->getTypesWithPoly(MED_EN::MED_CELL); + for (int itype=0; itype<nbtypes;itype++) + { + MED_EN::medGeometryElement type=types[itype]; + if (!m_collection->isDimensionOK(type,m_collection->getMeshDimension())) continue; + int ntype = (m_collection->getMesh())[idomain]->getNumberOfElementsWithPoly(MED_EN::MED_CELL,type); + if (ntype==0) continue; + med_2_3::MEDglobalNumEcr(fid,meshchar, array+offset, ntype, + med_2_3::MED_MAILLE, (med_2_3::med_geometrie_element)type); + offset+=ntype; + + } + delete[] types; + delete[] array; + + MED_EN::medEntityMesh constituent_entity; + if (m_collection->getMeshDimension()==3) + constituent_entity=MED_EN::MED_FACE; + else if (m_collection->getMeshDimension()==2) + constituent_entity=MED_EN::MED_EDGE; + else throw MEDEXCEPTION("Wrong dimension"); + + + //writing face global numbering + + offset=0; + int nface= m_collection->getTopology()->getFaceNumber(idomain); + if (nface >0) + array=new int[nface]; + m_collection->getTopology()->getFaceList(idomain,array); + strcpy(meshchar,(m_collection->getMesh())[idomain]->getName().c_str()); + int nbfacetypes = (m_collection->getMesh())[idomain]->getNumberOfTypesWithPoly(constituent_entity); + MED_EN::medGeometryElement* facetypes; + if (nbfacetypes>0) + facetypes =(m_collection->getMesh())[idomain]->getTypesWithPoly(constituent_entity); + + for (int itype=0; itype<nbfacetypes;itype++) + { + MED_EN::medGeometryElement type=facetypes[itype]; + if (!m_collection->isDimensionOK(type,m_collection->getMeshDimension()-1)) continue; + + int ntype = (m_collection->getMesh())[idomain]->getNumberOfElementsWithPoly(constituent_entity,type); + if (ntype==0) continue; + med_2_3::MEDglobalNumEcr(fid,meshchar, array+offset, ntype, + med_2_3::MED_MAILLE, (med_2_3::med_geometrie_element)type); + offset+=ntype; + } + if (nface>0) delete[] array; + if (nbfacetypes>0) delete[] facetypes; + + //writing node global numbering + + int nnode= m_collection->getTopology()->getNodeNumber(idomain); + array=new int[nnode]; + m_collection->getTopology()->getNodeList(idomain,array); + med_2_3::MEDglobalNumEcr(fid,meshchar, array, nnode, + med_2_3::MED_NOEUD, med_2_3::MED_POINT1); + + delete[] array; + med_2_3::MEDfermer(fid); + MESSAGE("End of writing"); + +} + +void MESHCollectionDriver::writeElementJoint(medEntityMesh entity , + int icz, + int idomain, + int idistant, + char* mesh_name, + char* joint_name, + med_2_3::med_idt fid ) +{ + ////////////////////////////////////////// + //writing cell/cell correspondency + ////////////////////////////////////////// + int nbcells=(m_collection->getCZ())[icz]->getEntityCorrespNumber(entity,entity); + const int* index = (m_collection->getCZ())[icz]->getEntityCorrespIndex(entity,entity); + const int* value = (m_collection->getCZ())[icz]->getEntityCorrespValue(entity,entity); + + map <pair <MED_EN::medGeometryElement, MED_EN::medGeometryElement> , vector<int> > cellmap; + map <MED_EN::medGeometryElement, int> local_offset; + map <MED_EN::medGeometryElement, int> distant_offset; + + //definition of the local offsets for the types present on local + //and distant domains + // for a mesh containing 2 triangles and 3 quads + //local_offset[TRIA3]=0 + //local_offset[QUAD4]=2 + + int nb_types_local=(m_collection->getMesh())[idomain]-> getNumberOfTypes(entity); + const MED_EN::medGeometryElement* local_types = (m_collection->getMesh())[idomain]->getTypes(entity); + const int* local_gni = (m_collection->getMesh())[idomain]-> getGlobalNumberingIndex(entity); + for (int i=0; i< nb_types_local; i++) + { + local_offset[local_types[i]]=local_gni[i]-1; + } + + int nb_types_distant=(m_collection->getMesh())[idistant]-> getNumberOfTypes(entity); + const MED_EN::medGeometryElement* distant_types = (m_collection->getMesh())[idistant]->getTypes(entity); + const int* distant_gni = (m_collection->getMesh())[idistant]-> getGlobalNumberingIndex(entity); + for (int i=0; i< nb_types_distant; i++) + { + distant_offset[distant_types[i]]=distant_gni[i]-1; + } + + //classifying all thje cell/cell relationships into geomtype/geomtype relationships + //there exists a vector for each geomtype/geomtype pair + // the vectors are stored in cellmap, a std::map with a pair<geomtype,geomtype> key + + for (int i=0; i<nbcells; i++) + for (int icol = index[i]-1; icol<index[i+1]-1; icol++) + { + MED_EN::medGeometryElement local_type = (m_collection->getMesh())[idomain]->getElementType(entity,i+1); + MED_EN::medGeometryElement distant_type = (m_collection->getMesh())[idistant]->getElementType(entity,value[icol]); + + cellmap[make_pair(local_type, distant_type)].push_back(i+1-local_offset[local_type]); + cellmap[make_pair(local_type, distant_type)].push_back(value[icol]-distant_offset[distant_type]); + } + map <pair <MED_EN::medGeometryElement, MED_EN::medGeometryElement> , vector<int> >::const_iterator iter; + + //going through all the (geom,geom) pairs and writing the joints + for (iter= cellmap.begin(); iter != cellmap.end(); iter++) + { + int size= iter->second.size(); + int *corresp = new int[size]; + for (int ind=0; ind < size; ind++) + corresp[ind]=(iter->second)[ind]; + med_2_3::med_geometrie_element local_geo_elem=(med_2_3::med_geometrie_element)iter->first.first; + med_2_3::med_geometrie_element distant_geo_elem=(med_2_3::med_geometrie_element)iter->first.second; + int size_joint=size/2; + //med_2_3::med_err error = + med_2_3::MEDjointEcr(fid, mesh_name, joint_name, corresp, size_joint, med_2_3::MED_MAILLE, + local_geo_elem,med_2_3::MED_MAILLE, distant_geo_elem); + + // MED v 2.3.1 returns an error code when + // writing a joint that is already present in the file. + // Also, it returns an error code if a joint + // concerns 3D elements. + // Until these two items are not + // changed, the following line must be commented out + + //if (error==-1) throw MEDEXCEPTION("Error filling joint"); + + delete[]corresp; + } +} + +void MESHCollectionDriver::jointSort(int* elems, int nbelems, bool is_first) +{ + //filling an ordered structure with the elem ids + map <int,int> nodemap; + if (is_first) + for (int i=0; i<nbelems; i++) + nodemap.insert(make_pair(elems[2*i],elems[2*i+1])); + + else + for (int i=0; i<nbelems; i++) + nodemap.insert(make_pair(elems[2*i+1],elems[2*i])); + + int* ptr_elems=elems; + + //filling the vector in appropriate order + for (map<int,int>::const_iterator iter=nodemap.begin(); iter!=nodemap.end(); iter++) + { + if (is_first) + { + *ptr_elems++=iter->first; + *ptr_elems++=iter->second; + } + else + { + *ptr_elems++=iter->second; + *ptr_elems++=iter->first; + } + } + +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.hxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.hxx new file mode 100644 index 000000000..ef1d5698a --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionDriver.hxx @@ -0,0 +1,60 @@ +#ifndef MESHCOLLECTIONDRIVER_HXX_ +#define MESHCOLLECTIONDRIVER_HXX_ + +#include "MEDSPLITTER.hxx" + +namespace MEDSPLITTER{ + +class MESHCollection; + +class MEDSPLITTER_EXPORT MESHCollectionDriver +{ +public: + + MESHCollectionDriver(MESHCollection*); + virtual ~MESHCollectionDriver(){} + + virtual int read(char*)=0; + int readSeq(char*,char*); + + virtual void write(char*)=0; + virtual void readFields (vector <MEDMEM::FIELD<int> *>& filenames, char* fieldname, + int itnumber, int ordernumber) =0; + virtual void readFields (vector <MEDMEM::FIELD<double> *>& filenames, char* fieldname, + int itnumber, int ordernumber) =0; + virtual void writeFields(vector <MEDMEM::FIELD<int> *>& filenames, char* fieldname)=0; + virtual void writeFields(vector <MEDMEM::FIELD<double> *>& filenames, char* fieldname)=0; + + void readFileStruct(vector <string>& field_names,vector<int>& iternumber,vector <int>& ordernumber,vector <int> & types); + + int getFieldType(const std::string& fieldname); + // void exportFamily(vector<int*>,MED_EN::medEntityMesh, const string& name); + +protected: + + void readSubdomain(const string& meshname, vector<int*>& cellglobal, +vector<int*>& faceglobal, +vector<int*>& nodeglobal, int idomain); + void writeSubdomain(int idomain,int nbdomain, char*filename); + +void writeElementJoint(medEntityMesh entity , + int icz, + int idomain, + int idistant, + char* mesh_name, + char* joint_name, + med_2_3::med_idt fid ); +void jointSort(int* elems, int nbelems, bool is_first); + + + + MESHCollection* m_collection; + + std::vector <std::string> m_filename; + +}; + +} + + +#endif /*MESHCOLLECTIONDRIVER_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.H b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.H new file mode 100644 index 000000000..b78f52bbe --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.H @@ -0,0 +1,48 @@ +#ifndef MEDSPLITTER_MESHCOLLECTIONMEDASCIIDRIVER_H +#define MEDSPLITTER_MESHCOLLECTIONMEDASCIIDRIVER_H + + +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +/*!reads a distributed field + * + * \param fields vector of fields (one field per subdomain) + * \param fieldname name of the field + * \param itnumber number of iteration + * \param ordernumber internal number inside the iteration + * */ +template <class T> +void MESHCollectionMedAsciiDriver::_readFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname, int itnumber, int ordernumber) +{ + for (int i=0; i<m_collection->getMesh().size(); i++) + { + char filename[256]; + strcpy(filename,m_filename[i].c_str()); + cout << "maillage : " << filename << " champ : " << fieldname << endl; + // MEDMEM::FIELD<T>* field = new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber); + fields.push_back (new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber)); + } +} + + +/*!writes a distributed field + * + * \param fields vector of fields (one field per subdomain) + * \param fieldname name of the field + * */ +template <class T> +void MESHCollectionMedAsciiDriver::_writeFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname) +{ + for (int i=0; i<m_collection->getMesh().size(); i++) + { + char filename[256]; + strcpy(filename,m_filename[i].c_str()); + int driverid = fields[i]->addDriver(MEDMEM::MED_DRIVER, filename, fieldname); + fields[i]->write(driverid); + } +} + +#endif diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.cxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.cxx new file mode 100644 index 000000000..4b019f8a9 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.cxx @@ -0,0 +1,193 @@ + +#include <vector> +#include <string> +#include <map> +#include <set> + +#include <iostream> +#include <fstream> + +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +#include <sys/time.h> +//Debug macros +#include "MEDMEM_Utilities.hxx" + +//MEDMEM includes +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_ConnectZone.hxx" + +//MEDSPLITTER includes +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" +#include "MEDSPLITTER_MESHCollectionDriver.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx" + +using namespace MEDSPLITTER; + +//template inclusion +#include "MEDSPLITTER_MESHCollectionMedAsciiDriver.H" + + +MESHCollectionMedAsciiDriver::MESHCollectionMedAsciiDriver(MESHCollection* collection):MESHCollectionDriver(collection) +{ +} + +/*!reads a MED File v>=2.3 + * and mounts the corresponding meshes in memory + * the connect zones are created from the joints + * + *\param filename ascii file containing the list of MED v2.3 files + * */ + +int MESHCollectionMedAsciiDriver::read(char* filename) +{ + + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::read()") + + //ditributed meshes + vector<int*> cellglobal; + vector<int*> nodeglobal; + vector<int*> faceglobal; + + int nbdomain; + + // reading ascii master file + try{ + MESSAGE("Start reading"); + ifstream asciiinput(filename); + + if (!asciiinput) + throw MEDEXCEPTION("MEDSPLITTER read - Master File does not exist"); + + char charbuffer[512]; + asciiinput.getline(charbuffer,512); + + while (charbuffer[0]=='#') + { + asciiinput.getline(charbuffer,512); + } + + //reading number of domains + nbdomain=atoi(charbuffer); + cout << "nb domain"<<nbdomain<<endl; + // asciiinput>>nbdomain; + m_filename.resize(nbdomain); + (m_collection->getMesh()).resize(nbdomain); + cellglobal.resize(nbdomain); + nodeglobal.resize(nbdomain); + faceglobal.resize(nbdomain); + + if (nbdomain == 0) + throw MEDEXCEPTION("Empty ASCII master file"); + for (int i=0; i<nbdomain;i++) + { + + //reading information about the domain + string mesh; + int idomain; + string host; + string meshstring; + cellglobal[i]=0; + faceglobal[i]=0; + nodeglobal[i]=0; + + asciiinput >> mesh >> idomain >> meshstring >> host >> m_filename[i]; + + //Setting the name of the global mesh (which is the same + //for all the subdomains) + if (i==0) + m_collection->setName(mesh); + + if (idomain!=i+1) + { + cerr<<"Error : domain must be written from 1 to N in asciifile descriptor"<<endl; + return 1; + } + readSubdomain(meshstring, cellglobal,faceglobal,nodeglobal, i); + + + }//loop on domains + MESSAGE("end of read"); + }//of try + catch(...) + { + cerr << "I/O error reading parallel MED file"<<endl; + throw; + } + + //creation of topology from mesh and connect zones + ParallelTopology* aPT = new ParallelTopology + ((m_collection->getMesh()), (m_collection->getCZ()), cellglobal, nodeglobal, faceglobal); + m_collection->setTopology(aPT); + + for (int i=0; i<nbdomain; i++) + { + if (cellglobal[i]!=0) delete[] cellglobal[i]; + if (nodeglobal[i]!=0) delete[] nodeglobal[i]; + if (faceglobal[i]!=0) delete[] faceglobal[i]; + } + + END_OF("MEDSPLITTER::MESHCollectionDriver::read()") + return 0; +} + + +/*! writes the collection of meshes in a + * MED v2.3 file + * with the connect zones being written as joints + * \param filename name of the ascii file containing the meshes description + */ +void MESHCollectionMedAsciiDriver::write(char* filename) +{ + + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::write()") + + ofstream file(filename); + + file <<"#MED Fichier V 2.3"<<" "<<endl; + file <<"#"<<" "<<endl; + file<<m_collection->getMesh().size()<<" "<<endl; + + int nbdomains= m_collection->getMesh().size(); + m_filename.resize(nbdomains); + + //loop on the domains + for (int idomain=0; idomain<nbdomains;idomain++) + { + char distfilename[256]; + + ostringstream suffix; + suffix << filename<< idomain+1 <<".med"; + + strcpy(distfilename,suffix.str().c_str()); + + m_filename[idomain]=string(distfilename); + + MESSAGE("File name "<<string(distfilename)); + + int id=(m_collection->getMesh())[idomain]->addDriver(MEDMEM::MED_DRIVER,distfilename,(m_collection->getMesh())[idomain]->getName(),MED_EN::MED_CREATE); + + MESSAGE("Start writing"); + (m_collection->getMesh())[idomain]->write(id); + + //updating the ascii description file + file << m_collection->getName() <<" "<< idomain+1 << " "<< (m_collection->getMesh())[idomain]->getName() << " localhost " << distfilename << " "<<endl; + + writeSubdomain(idomain, nbdomains, distfilename); + } + + END_OF("MEDSPLITTER::MESHCollectionDriver::write()"); + +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx new file mode 100644 index 000000000..ea2de13a3 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx @@ -0,0 +1,58 @@ +#ifndef MESHCOLLECTIONMEDASCIIDRIVER_HXX_ +#define MESHCOLLECTIONMEDASCIIDRIVER_HXX_ + +#include "MEDSPLITTER_MESHCollectionDriver.hxx" + +namespace MEDSPLITTER{ + +class MESHCollection; + + class MESHCollectionMedAsciiDriver:public MESHCollectionDriver +{ +public: + + MESHCollectionMedAsciiDriver(MESHCollection*); + virtual ~MESHCollectionMedAsciiDriver(){} + + int read(char*); + + void write(char*); + + void readFields(vector <MEDMEM::FIELD<int> *>& filenames, char* fieldname, + int itnumber, int ordernumber) + { + _readFields(filenames,fieldname,itnumber,ordernumber); + } + void readFields(vector <MEDMEM::FIELD<double> *>& filenames, char* fieldname, + int itnumber, int ordernumber) + { + _readFields(filenames,fieldname,itnumber,ordernumber); + } + + void writeFields(vector <MEDMEM::FIELD<int> *>& filenames, char* fieldname) + { + _writeFields( filenames, fieldname); + } + + void writeFields(vector <MEDMEM::FIELD<double> *>& filenames, char* fieldname) + { + _writeFields( filenames, fieldname); + } + + +private : + template <class T> void _readFields(vector <MEDMEM::FIELD<T> *>& filenames, char* fieldname, + int itnumber, int ordernumber); + + template <class T> + void _writeFields(vector <MEDMEM::FIELD<T> *>& filenames, char* fieldname); + + + + std::string m_master_filename; +}; + +} + + +#endif /*MESHCOLLECTIONDRIVER_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.H b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.H new file mode 100644 index 000000000..a69896abc --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.H @@ -0,0 +1,104 @@ +#ifndef MEDSPLITTER_MESHCOLLECTIONMEDXMLDRIVER_H +#define MEDSPLITTER_MESHCOLLECTIONMEDXMLDRIVER_H + + +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + + + +/*!reads a distributed field + * + * \param fields vector of fields (one field per subdomain) + * \param fieldname name of the field + * \param itnumber number of iteration + * \param ordernumber internal number inside the iteration + * */ +template <class T> +void MESHCollectionMedXMLDriver::_readFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname, int itnumber, int ordernumber) +{ + for (int i=0; i<m_collection->getMesh().size(); i++) + { + char filename[256]; + strcpy(filename,m_filename[i].c_str()); + cout << "maillage : " << filename << " champ : " << fieldname << endl; + // MEDMEM::FIELD<T>* field = new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber); + fields.push_back (new MEDMEM::FIELD<T>(MEDMEM::MED_DRIVER,filename,fieldname,itnumber,ordernumber)); + } +} + + +/*!writes a distributed field + * + * \param fields vector of fields (one field per subdomain) + * \param fieldname name of the field + * */ +template <class T> +void MESHCollectionMedXMLDriver::_writeFields(vector<MEDMEM::FIELD<T>* >& fields,char* fieldname) +{ + xmlDocPtr master_doc=xmlParseFile(m_master_filename.c_str()); + + if (!master_doc) + throw MEDEXCEPTION("MEDSPLITTER writeFields - Master File does not exist"); + + //number of domains + + xmlXPathContextPtr xpathCtx = xmlXPathNewContext(master_doc); + xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(BAD_CAST "//mapping/mesh", xpathCtx); + //assuming there is only one mesh in the XML file + xmlNodePtr mesh_node= xpathObj->nodesetval->nodeTab[0]; + + //adds the field to the master file if necessary + bool exist_field =false; + xpathObj = xmlXPathEvalExpression(BAD_CAST "//mapping/mesh/field", xpathCtx); + //assuming there is only one mesh in the XML file + int field_nr = xpathObj->nodesetval->nodeNr; + for (int i=0; i<field_nr; i++) + { + //field node has only one property + if ( strcmp((const char*)xpathObj->nodesetval->nodeTab[i]->properties->children->content, fieldname)==0) + exist_field = true; + } + + xmlNodePtr field_node; + if (!exist_field) + { + field_node = xmlNewChild(mesh_node, 0, BAD_CAST "field",0); + xmlNewProp(field_node,BAD_CAST "name",BAD_CAST fieldname); + } + + + for (int i=0; i<m_collection->getMesh().size(); i++) + { + char filename[256]; + strcpy(filename,m_filename[i].c_str()); + int driverid = fields[i]->addDriver(MEDMEM::MED_DRIVER, filename, fieldname); + fields[i]->write(driverid); + + //adds the partition to the master file if the field had not been + //added already + if (!exist_field) + { + xmlNodePtr chunk_node= xmlNewChild(field_node,0,BAD_CAST "chunk",0); + char id[8]; + sprintf(id,"%d",i+1); + xmlNewProp(chunk_node,BAD_CAST "subdomain",BAD_CAST id); + //xmlNewProp(chunk_node,BAD_CAST "name", BAD_CAST fieldname); + //xmlNodePtr fieldname_node= + xmlNewChild(chunk_node,0,BAD_CAST "name", BAD_CAST fieldname); + } + } + //Writing file + xmlKeepBlanksDefault(0); + xmlSaveFormatFileEnc(m_master_filename.c_str(), master_doc, "UTF-8", 1); + + //Clean up + xmlXPathFreeContext(xpathCtx); + xmlFreeDoc(master_doc); + xmlCleanupParser(); + +} + +#endif diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.cxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.cxx new file mode 100644 index 000000000..173b27c30 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.cxx @@ -0,0 +1,346 @@ + +#include <vector> +#include <string> +#include <map> +#include <set> + +#include <iostream> +#include <fstream> + +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> + +#include <sys/time.h> +//Debug macros +#include "MEDMEM_Utilities.hxx" + +//MEDMEM includes +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Med.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_ConnectZone.hxx" + +//MEDSPLITTER includes +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" +#include "MEDSPLITTER_MESHCollectionDriver.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_MESHCollectionMedXMLDriver.hxx" + +using namespace MEDSPLITTER; + +//template inclusion +#include "MEDSPLITTER_MESHCollectionMedXMLDriver.H" + +/*!\class MESHCollectionMedXMLDriver + * + *\brief Driver for MED 3.2 files having XML master files + * + * Driver for reading and writing distributed files + * for which the master file is written in an XML format compliant with + * the MED 3.2 specification. + * The reading and writing of the meshes and fields are apart : + * the meshes must always be written/read before the fields. Reading/Writing fields + * is optional and is done field after field. API for reading/writing fields + * is written with a template so that MEDMEM::FIELD<int> and MEDMEM::FIELD<double> + * can be conveniently handled. +*/ + +MESHCollectionMedXMLDriver::MESHCollectionMedXMLDriver(MESHCollection* collection):MESHCollectionDriver(collection) +{ +} + +/*!reads a MED File XML Master File v>=2.3 + * and mounts the corresponding meshes in memory + * the connect zones are created from the joints + * + *\param filename XML file containing the list of MED v2.3 files + * */ + +int MESHCollectionMedXMLDriver::read(char* filename) +{ + + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::read()"); + + //ditributed meshes + vector<int*> cellglobal; + vector<int*> nodeglobal; + vector<int*> faceglobal; + + int nbdomain; + + m_master_filename=filename; + + // reading ascii master file + try{ + MESSAGE("Start reading"); + + // Setting up the XML tree corresponding to filename + xmlDocPtr master_doc=xmlParseFile(filename); + + if (!master_doc) + throw MEDEXCEPTION("MEDSPLITTER XML read - Master File does not exist o r is not compliant with XML scheme"); + + //////////////////// + //number of domains + //////////////////// + xmlXPathContextPtr xpathCtx = xmlXPathNewContext(master_doc); + xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(BAD_CAST "//splitting/subdomain", xpathCtx); + if (xpathObj==0 || xpathObj->nodesetval->nodeNr ==0) + throw MEDEXCEPTION("MEDSPLITTER read - XML Master File does not contain /MED/splitting/subdomain node"); + + /* as subdomain has only one property which is "number" + * it suffices to take the content of its first child */ + const char* mystring = (const char*)xpathObj->nodesetval->nodeTab[0]->properties->children->content; + sscanf(mystring, "%d", &nbdomain); + + ////////////////// + //mesh name + ////////////////// + xpathObj = xmlXPathEvalExpression(BAD_CAST "//content/mesh", xpathCtx); + if (xpathObj==0 || xpathObj->nodesetval->nodeNr ==0) + throw MEDEXCEPTION("MEDSPLITTER read - XML Master File does not contain /MED/content/mesh node"); + m_collection->setName( (const char*)xpathObj->nodesetval->nodeTab[0]->properties->children->content); + + cout << "nb domain" << nbdomain << endl; + m_filename.resize(nbdomain); + (m_collection->getMesh()).resize(nbdomain); + cellglobal.resize(nbdomain); + nodeglobal.resize(nbdomain); + faceglobal.resize(nbdomain); + + + // retrieving the node which contains the file names + const char filechar[]="//files/subfile"; + xpathObj = xmlXPathEvalExpression(BAD_CAST filechar, xpathCtx); + if (xpathObj==0 || xpathObj->nodesetval->nodeNr ==0) + throw MEDEXCEPTION("MEDSPLITTER read - XML Master File does not contain /MED/files/subfile nodes"); + int nbfiles = xpathObj->nodesetval ->nodeNr; + + for (int i=0; i<nbfiles;i++) + { + //reading information about the domain + + string host; + string meshname; + //char meshname[MED_TAILLE_NOM]; + + cellglobal[i]=0; + faceglobal[i]=0; + nodeglobal[i]=0; + + //////////////////////////// + //reading file names + //////////////////////////// + ostringstream name_search_string; + name_search_string<<"//files/subfile[@id=\""<<i+1<<"\"]/name"; + cout <<name_search_string.str()<<endl; + xmlXPathObjectPtr xpathObjfilename = + xmlXPathEvalExpression(BAD_CAST name_search_string.str().c_str(),xpathCtx); + if (xpathObjfilename->nodesetval ==0) + throw MEDEXCEPTION("MED XML reader : Error retrieving file name "); + //ostringstream filename(m_filename[i]); + m_filename[i]=(const char*)xpathObjfilename->nodesetval->nodeTab[0]->children->content; + //filename.flush(); + //cout<<m_filename[i]<<endl; +// xmlNodePtr current = xpathObj->nodesetval->nodeTab[i]; +// xmlAttrPtr properties = current->properties; +// +// +// //browsing XML attributes of subfile node until "id" attribute is found +// while(strcmp((const char*)(properties->name),"id")!=0) +// properties=properties->next; +// sscanf((const char*)properties->children->content,"%d",&idomain); +// properties = current->properties; +// +// //browsing XML attributes of subfile node until "name" attribute is found +// while(strcmp((const char*)(properties->name),"name")!=0) +// properties=properties->next; +// m_filename[i]=(const char*)properties->children->content; + + //////////////////////////////// + //reading the local mesh names + //////////////////////////////// + ostringstream mesh_search_string; + mesh_search_string<<"//mapping/mesh/chunk[@subdomain=\""<<i+1<<"\"]/name"; + + xmlXPathObjectPtr xpathMeshObj = xmlXPathEvalExpression(BAD_CAST mesh_search_string.str().c_str(),xpathCtx); + if (xpathMeshObj->nodesetval ==0) + throw MEDEXCEPTION("MED XML reader : Error retrieving mesh name "); + meshname=(const char*)xpathMeshObj->nodesetval->nodeTab[0]->children->content; + + +// +// xmlXPathObjectPtr xpathMeshObj = xmlXPathEvalExpression(BAD_CAST "//mesh/chunk" , xpathCtx); +// int nbchunks = xpathMeshObj->nodesetval ->nodeNr; +// for (int ichunk=0; ichunk<nbchunks; ichunk++) +// { +// xmlNodePtr currentchunk = xpathMeshObj->nodesetval->nodeTab[ichunk]; +// xmlAttrPtr propertieschunk = currentchunk->properties; +// int id; +// sscanf((const char*)propertieschunk->children->content, "%d",&id); +// if (strcmp((const char*)propertieschunk->name, "subdomain")==0 && id==idomain) +// { +// propertieschunk=propertieschunk->next; +// meshstring=(const char*)propertieschunk->children->content; +// } +// } + +// if (idomain!=i+1) +// { +// cerr<<"Error : domain must be written from 1 to N in master file descriptor"<<endl; +// return 1; +// } + readSubdomain(meshname, cellglobal, faceglobal, nodeglobal, i); + xmlXPathFreeObject(xpathObjfilename); + + xmlXPathFreeObject(xpathMeshObj); + }//loop on domains + + // LIBXML cleanup + xmlXPathFreeObject(xpathObj); + xmlXPathFreeContext(xpathCtx); + xmlFreeDoc(master_doc); + + MESSAGE("end of read"); + }//of try + catch(...) + { + throw MEDEXCEPTION("I/O error reading parallel MED file"); + } + + //creation of topology from mesh and connect zones + ParallelTopology* aPT = new ParallelTopology + ((m_collection->getMesh()), (m_collection->getCZ()), cellglobal, nodeglobal, faceglobal); + m_collection->setTopology(aPT); + + for (int i=0; i<nbdomain; i++) + { + if (cellglobal[i]!=0) delete[] cellglobal[i]; + if (nodeglobal[i]!=0) delete[] nodeglobal[i]; + if (faceglobal[i]!=0) delete[] faceglobal[i]; + } + + END_OF("MEDSPLITTER::MESHCollectionDriver::read()") + return 0; +} + + +/*! writes the collection of meshes in a + * MED v2.3 XML file + * with the connect zones being written as joints + * \param filename name of the XML file containing the meshes description + */ +void MESHCollectionMedXMLDriver::write(char* filename) +{ + + BEGIN_OF("MEDSPLITTER::MESHCollectionDriver::writeXML()"); + + xmlDocPtr master_doc = 0; + xmlNodePtr root_node = 0, node, node2; + // xmlDTDPtr dtd = 0; + + char buff[256]; + + //Creating the XML document + + master_doc = xmlNewDoc(BAD_CAST "1.0"); + root_node = xmlNewNode(0, BAD_CAST "root"); + xmlDocSetRootElement(master_doc,root_node); + + //Creating child nodes + + // Version tag + node = xmlNewChild(root_node, 0, BAD_CAST "version",0); + xmlNewProp(node, BAD_CAST "maj", BAD_CAST "2"); + xmlNewProp(node, BAD_CAST "min", BAD_CAST "3"); + xmlNewProp(node, BAD_CAST "ver", BAD_CAST "1"); + + //Description tag + + time_t present; + time( &present); + struct tm *time_asc = localtime(&present); + char date[6]; + sprintf(date,"%02d%02d%02d",time_asc->tm_year + ,time_asc->tm_mon+1 + ,time_asc->tm_mday); + + node = xmlNewChild(root_node,0, BAD_CAST "description",0); + + xmlNewProp(node, BAD_CAST "what", BAD_CAST m_collection->getDescription().c_str()); + xmlNewProp(node, BAD_CAST "when", BAD_CAST date); + + //Content tag + node =xmlNewChild(root_node,0, BAD_CAST "content",0); + node2 = xmlNewChild(node, 0, BAD_CAST "mesh",0); + xmlNewProp(node2, BAD_CAST "name", BAD_CAST m_collection->getName().c_str()); + + //Splitting tag + node=xmlNewChild(root_node,0,BAD_CAST "splitting",0); + node2=xmlNewChild(node,0,BAD_CAST "subdomain",0); + sprintf(buff, "%d", m_collection->getMesh().size()); + xmlNewProp(node2, BAD_CAST "number", BAD_CAST buff); + node2=xmlNewChild(node,0,BAD_CAST "global_numbering",0); + xmlNewProp(node2, BAD_CAST "present", BAD_CAST "yes"); + + //Files tag + xmlNodePtr file_node=xmlNewChild(root_node,0,BAD_CAST "files",0); + + //Mapping tag + node = xmlNewChild(root_node,0,BAD_CAST "mapping",0); + xmlNodePtr mesh_node = xmlNewChild(node, 0, BAD_CAST "mesh",0); + xmlNewProp(mesh_node, BAD_CAST "name", BAD_CAST m_collection->getName().c_str()); + + int nbdomains= m_collection->getMesh().size(); + m_filename.resize(nbdomains); + + //loop on the domains + for (int idomain=0; idomain<nbdomains;idomain++) + { + char distfilename[256]; + + ostringstream suffix; + suffix << filename<< idomain+1 <<".med"; + + strcpy(distfilename,suffix.str().c_str()); + + m_filename[idomain]=string(distfilename); + + MESSAGE("File name "<<string(distfilename)); + + int id=(m_collection->getMesh())[idomain]->addDriver(MEDMEM::MED_DRIVER,distfilename,(m_collection->getMesh())[idomain]->getName(),MED_EN::MED_CREATE); + + MESSAGE("Start writing"); + (m_collection->getMesh())[idomain]->write(id); + + //updating the ascii description file + node = xmlNewChild(file_node, 0, BAD_CAST "subfile",0); + sprintf (buff,"%d",idomain+1); + xmlNewProp(node, BAD_CAST "id", BAD_CAST buff); + xmlNewChild(node,0,BAD_CAST "name",BAD_CAST distfilename); + xmlNewChild(node,0,BAD_CAST "machine",BAD_CAST "localhost"); + + node = xmlNewChild(mesh_node,0, BAD_CAST "chunk",0); + xmlNewProp(node, BAD_CAST "subdomain", BAD_CAST buff); + xmlNewChild(node,0,BAD_CAST "name", BAD_CAST (m_collection->getMesh())[idomain]->getName().c_str()); + + writeSubdomain(idomain, nbdomains, distfilename); + + } + strcat(filename,".xml"); + m_master_filename=filename; + xmlSaveFormatFileEnc(filename, master_doc, "UTF-8", 1); + xmlFreeDoc(master_doc); + xmlCleanupParser(); + + END_OF("MEDSPLITTER::MESHCollectionDriver::writeXML()"); + +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.hxx b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.hxx new file mode 100644 index 000000000..da93ab540 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_MESHCollectionMedXMLDriver.hxx @@ -0,0 +1,58 @@ +#ifndef MESHCOLLECTIONMEDXMLDRIVER_HXX_ +#define MESHCOLLECTIONMEDXMLDRIVER_HXX_ + +#include "MEDSPLITTER_MESHCollectionDriver.hxx" + +namespace MEDSPLITTER{ + + class MESHCollection; + + class MESHCollectionMedXMLDriver:public MESHCollectionDriver + { + public: + + MESHCollectionMedXMLDriver(MESHCollection*); + virtual ~MESHCollectionMedXMLDriver(){} + + + int read(char*); + + void write(char*); + + void readFields(vector <MEDMEM::FIELD<int> *>& filenames, char* fieldname, + int itnumber, int ordernumber) + { + _readFields(filenames,fieldname,itnumber,ordernumber); + } + void readFields(vector <MEDMEM::FIELD<double> *>& filenames, char* fieldname, + int itnumber, int ordernumber) + { + _readFields(filenames,fieldname,itnumber,ordernumber); + } + + void writeFields(vector <MEDMEM::FIELD<double> *>& filenames, char* fieldname) + { + _writeFields( filenames, fieldname); + } + void writeFields(vector <MEDMEM::FIELD<int> *>& filenames, char* fieldname) + { + _writeFields( filenames, fieldname); + } + + + + private : + + template <class T> void _readFields(vector <MEDMEM::FIELD<T> *>& filenames, char* fieldname, + int itnumber, int ordernumber); + + template <class T> + void _writeFields(vector <MEDMEM::FIELD<T> *>& filenames, char* fieldname); + + std::string m_master_filename; + }; + +} + + +#endif /*MESHCOLLECTIONDRIVER_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_METISGraph.cxx b/src/MEDSPLITTER/MEDSPLITTER_METISGraph.cxx new file mode 100644 index 000000000..c4a22a9c2 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_METISGraph.cxx @@ -0,0 +1,78 @@ +extern "C" { +#include "metis.h" +} +#include"MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_METISGraph.hxx" + +using namespace MEDSPLITTER; + +METISGraph::METISGraph():Graph() +{ +} + +METISGraph::METISGraph(const MEDMEM::MEDSKYLINEARRAY* graph, int* edgeweight) + :Graph(graph,edgeweight) +{ +} + +METISGraph::~METISGraph() +{ + if (m_partition!=0) {delete m_partition; m_partition=0;} + if (m_graph!=0) {delete m_graph; m_graph=0;} +} + +void METISGraph::partGraph(int ndomain, const string& options_string) +{ + // number of graph vertices + int n = m_graph->getNumberOf(); + + //graph + int * xadj=const_cast<int*>(m_graph->getIndex()); + int * adjncy = const_cast<int*>(m_graph->getValue()); + //constraints + int * vwgt=m_cellweight; + int * adjwgt=m_edgeweight; + int wgtflag=(m_edgeweight!=0)?1:0+(m_cellweight!=0)?2:0; + + //base 0 or 1 + int base=1; + + //ndomain + int nparts = ndomain; + + //options + int options[5]={0,0,0,0,0}; + + // output parameters + int edgecut; + int* partition = new int[n+1]; + + if (nparts >1) + { + if (options_string != "k") + METIS_PartGraphRecursive(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag, + &base, &nparts, options, &edgecut, partition); + else + METIS_PartGraphKway(&n, xadj, adjncy, vwgt, adjwgt, &wgtflag, + &base, &nparts, options, &edgecut, partition); + } + else + { + for (int i=0; i<n+1; i++) + partition[i]=1; + } + + int* index=new int [n+1]; + index[0]=1; + for (int i=0; i<n; i++) + { + index[i+1]=index[i]+1; + partition[i]--; + } + + //creating a skylinearray with no copy of the index and partition array + // the fifth argument true specifies that only the pointers are passed + //to the object + m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, true); +} + diff --git a/src/MEDSPLITTER/MEDSPLITTER_METISGraph.hxx b/src/MEDSPLITTER/MEDSPLITTER_METISGraph.hxx new file mode 100644 index 000000000..5e0c50afc --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_METISGraph.hxx @@ -0,0 +1,18 @@ +#ifndef METISGRAPH_HXX_ +#define METISGRAPH_HXX_ + +#include "MEDSPLITTER.hxx" + +namespace MEDSPLITTER { +class MEDSPLITTER_EXPORT METISGraph:public Graph +{ +public: + METISGraph(); + METISGraph(const MEDMEM::MEDSKYLINEARRAY*, int* edgeweight=0); + virtual ~METISGraph(); + void partGraph(int ndomain, const string& options_string=""); +//private: +// const MEDMEM::MEDSKYLINEARRAY* m_graph; +}; +} +#endif /*METISGRAPH_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_ParallelTopology.cxx b/src/MEDSPLITTER/MEDSPLITTER_ParallelTopology.cxx new file mode 100644 index 000000000..9012b3bd3 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_ParallelTopology.cxx @@ -0,0 +1,1047 @@ +#include <set> +#include <map> +#include <vector> +#ifndef WNT +# include <ext/hash_map> +#else +# include <hash_map> +#endif + +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_ConnectZone.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Exception.hxx" +#include "MEDMEM_Utilities.hxx" + +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" + +#ifndef WNT +using namespace __gnu_cxx; +#else +using namespace std; +#endif + +using namespace MEDSPLITTER; + +//empty constructor +ParallelTopology::ParallelTopology():m_nb_domain(0),m_mesh_dimension(0) +{} + +//!constructing topology according to mesh collection +ParallelTopology::ParallelTopology(vector<MEDMEM::MESH*> meshes, + vector<MEDMEM::CONNECTZONE*> cz, + vector<int*>& cellglobal, + vector<int*>& nodeglobal, + vector<int*>& faceglobal):m_nb_domain(meshes.size()),m_mesh_dimension(meshes[0]->getMeshDimension()) +{ + + int index_global=0; + int index_node_global=0; + int index_face_global=0; + + m_nb_cells.resize(m_nb_domain); + m_nb_nodes.resize(m_nb_domain); + m_nb_faces.resize(m_nb_domain); + + m_loc_to_glob.resize(m_nb_domain); + m_node_loc_to_glob.resize(m_nb_domain); + m_face_loc_to_glob.resize(m_nb_domain); + + MED_EN::medEntityMesh constituent_entity; + switch (m_mesh_dimension) + { case 3: + constituent_entity = MED_EN::MED_FACE; + break; + case 2: + constituent_entity = MED_EN::MED_EDGE; + break; + } + + + for (int idomain=0; idomain<m_nb_domain; idomain++) + { + //creating cell maps + m_nb_cells[idomain]=meshes[idomain]->getNumberOfElementsWithPoly(MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + // cout << "Nb cells (domain "<<idomain<<") = "<<m_nb_cells[idomain]; + m_loc_to_glob[idomain].resize(m_nb_cells[idomain]); + + if (cellglobal[idomain]==0) + { + MESSAGE("Creating global numbering"); + //creating global numbering from scratch + for (int i=0; i<m_nb_cells[idomain]; i++) + { + index_global++; + m_glob_to_loc[index_global]=make_pair(idomain,i+1); + //m_loc_to_glob[make_pair(idomain,i+1)]=index_global; + m_loc_to_glob[idomain][i]=index_global; + // cout<<"glob:"<<index_global<<" --> ("<<idomain<<","<<i+1<<")"<<endl; + } + } + //using global numbering coming from a previous numbering + else + { + MESSAGE("Using former global numbering"); + for (int i=0; i<m_nb_cells[idomain]; i++) + { + int global=cellglobal[idomain][i]; + m_glob_to_loc[global]=make_pair(idomain,i+1); + //m_loc_to_glob[make_pair(idomain,i+1)]=global; + m_loc_to_glob[idomain][i]=global; + index_global++; + // cout<<"glob:"<<global<<" --> ("<<idomain<<","<<i+1<<")"<<endl; + } + } + + //cas sequentiel + if (m_nb_domain==1) + { + m_nb_total_cells=index_global; + m_nb_cells[0]=index_global; + m_node_loc_to_glob[idomain].resize(meshes[idomain]->getNumberOfNodes()); + for (int i=0; i<meshes[idomain]->getNumberOfNodes(); i++) + { + m_node_glob_to_loc.insert(make_pair(i+1,make_pair(0,i+1))); + //m_node_loc_to_glob.insert(make_pair(make_pair(0,i+1), i+1)); + m_node_loc_to_glob[0][i]=i+1; + } + m_nb_total_nodes=meshes[idomain]->getNumberOfNodes(); + m_nb_nodes[0]=m_nb_total_nodes; + + // meshes[idomain]->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + int nbfaces=meshes[idomain]->getNumberOfElementsWithPoly(constituent_entity,MED_EN::MED_ALL_ELEMENTS); + m_face_loc_to_glob[idomain].resize(nbfaces); + for (int i=0; i<nbfaces; i++) + { + m_face_glob_to_loc.insert(make_pair(i+1,make_pair(0,i+1))); + //m_face_loc_to_glob.insert(make_pair(make_pair(0,i+1), i+1)); + m_face_loc_to_glob[0][i]=i+1; + } + m_nb_total_faces=nbfaces; + m_nb_faces[0]=nbfaces; + MESSAGE ("nb total cells "<< m_nb_total_cells); + MESSAGE("nb total nodes "<< m_nb_total_nodes); + MESSAGE("nb total faces "<< m_nb_total_faces); + return; + } + + //creating node maps + m_nb_nodes[idomain]=meshes[idomain]->getNumberOfNodes(); + hash_map <int,pair<int,int> > local2distant; + m_node_loc_to_glob[idomain].resize(m_nb_nodes[idomain]); + for (int icz=0; icz<cz.size(); icz++) + { + if (cz[icz]->getLocalDomainNumber() == idomain && + cz[icz]->getLocalDomainNumber()>cz[icz]->getDistantDomainNumber()) + { + int nb_node= cz[icz]->getNodeNumber(); + const int* node_corresp=cz[icz]->getNodeCorrespValue(); + int distant_ip = cz[icz]->getDistantDomainNumber(); + for (int i=0; i< nb_node; i++) + { + int local= node_corresp[i*2]; + int distant = node_corresp[i*2+1]; + local2distant.insert(make_pair(local, make_pair(distant_ip,distant))); + } + } + } + // setting mappings for all nodes + if (nodeglobal[idomain]==0) + { + for (int inode=0; inode<m_nb_nodes[idomain]; inode++) + { + if (local2distant.find(inode+1)==local2distant.end()) + { + index_node_global++; + m_node_glob_to_loc.insert(make_pair(index_node_global,make_pair(idomain,inode+1))); + //m_node_loc_to_glob[make_pair(idomain,inode+1)]=index_node_global; + m_node_loc_to_glob[idomain][inode]=index_node_global; + } + else + { + int ip = (local2distant.find(inode+1)->second).first; + int distant = (local2distant.find(inode+1)->second).second; + //int global_number=m_loc_to_glob[make_pair(ip,distant)]; + int global_number=m_loc_to_glob[ip][distant-1]; + m_node_glob_to_loc.insert(make_pair(global_number,make_pair(idomain,inode+1))); + //m_node_loc_to_glob[make_pair(idomain,inode+1)]=global_number; + m_node_loc_to_glob[idomain][inode]=global_number; + } + } + } + //using former node numbering + else + {// cout << "("<<idomain<<","<<i+1<<")->"<<i+1<<endl; + for (int inode=0; inode<m_nb_nodes[idomain]; inode++) + { + int global_number=nodeglobal[idomain][inode]; + // cout << "global_number "<<global_number<<endl; + m_node_glob_to_loc.insert(make_pair(global_number,make_pair(idomain,inode+1))); + //m_node_loc_to_glob[make_pair(idomain,inode+1)]=global_number; + m_node_loc_to_glob[idomain][inode]=global_number; + } + } + + + //creating dimension d-1 component mappings + + // meshes[idomain]->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_EN::MED_DESCENDING, MED_EN::MED_CELL, MED_EN::MED_ALL_ELEMENTS); + m_nb_faces[idomain]=meshes[idomain]->getNumberOfElementsWithPoly(constituent_entity,MED_EN::MED_ALL_ELEMENTS); + MESSAGE ("Nb faces domain " << idomain<<m_nb_faces[idomain]); + m_face_loc_to_glob[idomain].resize(m_nb_faces[idomain]); + local2distant.clear(); + for (int icz=0; icz<cz.size(); icz++) + { + if (cz[icz]->getLocalDomainNumber() == idomain && + cz[icz]->getLocalDomainNumber()>cz[icz]->getDistantDomainNumber()) + { + int nb_face= cz[icz]->getFaceNumber(); + const int* face_corresp=cz[icz]->getFaceCorrespValue(); + int distant_ip = cz[icz]->getDistantDomainNumber(); + for (int i=0; i< nb_face; i++) + { + int local= face_corresp[i*2]; + int distant = face_corresp[i*2+1]; + local2distant.insert(make_pair(local, make_pair(distant_ip,distant))); + } + } + } + // setting mappings for all faces + if (faceglobal[idomain]==0) + { + for (int iface=0; iface<m_nb_faces[idomain]; iface++) + { + if (local2distant.find(iface+1)==local2distant.end()) + { + index_face_global++; + m_face_glob_to_loc.insert(make_pair(index_face_global,make_pair(idomain,iface+1))); + //m_face_loc_to_glob[make_pair(idomain,iface+1)]=index_face_global; + m_face_loc_to_glob[idomain][iface]=index_face_global; + } + else + { + int ip = (local2distant.find(iface+1)->second).first; + int distant = (local2distant.find(iface+1)->second).second; + //int global_number=m_loc_to_glob[make_pair(ip,distant)]; + int global_number=m_loc_to_glob[ip][distant-1]; + m_face_glob_to_loc.insert(make_pair(global_number,make_pair(idomain,iface+1))); + //m_face_loc_to_glob[make_pair(idomain,iface+1)]=global_number; + m_face_loc_to_glob[idomain][iface]=global_number; + } + } + } + //using former face numbering + else + {// cout << "("<<idomain<<","<<i+1<<")->"<<i+1<<endl; + for (int iface=0; iface<m_nb_faces[idomain]; iface++) + { + + int global_number=faceglobal[idomain][iface]; + //SCRUTE(global_number); + m_face_glob_to_loc.insert(make_pair(global_number,make_pair(idomain,iface+1))); + //m_face_loc_to_glob[make_pair(idomain,iface+1)]=global_number; + m_face_loc_to_glob[idomain][iface]=global_number; + } + } + } + + m_nb_total_cells=index_global; + m_nb_total_nodes=index_node_global; + m_nb_total_faces=index_face_global; + SCRUTE(m_nb_total_cells); + SCRUTE(m_nb_total_faces); + SCRUTE(m_nb_total_nodes); + +} + + +//!constructing ParallelTopology from an old topology and a graph +ParallelTopology::ParallelTopology(boost::shared_ptr<Graph> graph, int nb_domain, int mesh_dimension): + m_nb_domain(nb_domain), + m_nb_cells(graph->nbVertices()), + m_mesh_dimension(mesh_dimension), + m_graph(graph) +{ + m_nb_cells.resize(m_nb_domain); + m_nb_nodes.resize(m_nb_domain); + m_nb_faces.resize(m_nb_domain); + + m_loc_to_glob.resize(m_nb_domain); + m_node_loc_to_glob.resize(m_nb_domain); + m_face_loc_to_glob.resize(m_nb_domain); + + for (int i=0; i<m_nb_domain; i++) + m_nb_cells[i]=0; + + const int* part = graph-> getPart(); + m_nb_total_cells= graph->nbVertices(); + + for (int icell=0; icell<m_nb_total_cells; icell++) + { + int idomain = part[icell]; + m_nb_cells[idomain]++; + //m_loc_to_glob[make_pair(idomain,m_nb_cells[idomain])]=icell+1; + m_loc_to_glob[idomain].push_back(icell+1); + m_glob_to_loc[icell+1]=make_pair(idomain,m_nb_cells[idomain]); + + } + for (int idomain=0; idomain<m_nb_domain; idomain++) + MESSAGE("Nombre de cellules dans le domaine "<< idomain <<" : "<<m_nb_cells[idomain]); + + SCRUTE(m_nb_total_cells); + +} + +ParallelTopology::~ParallelTopology() +{ + +} + +/*!Converts a list of global node numbers + * to a distributed array with local cell numbers. + * + * If a node in the list is represented on several domains, + * only the first value is returned + * */ +void ParallelTopology::convertGlobalNodeList(const int* node_list, int nbnode, int* local, int* ip) +{ + if (m_node_glob_to_loc.empty()) + throw MEDMEM::MEDEXCEPTION("convertGlobalNodeList - Node mapping has not yet been built"); + for (int i=0; i< nbnode; i++) + { + pair<int,int> local_node = m_node_glob_to_loc.find(node_list[i])->second; + ip[i]=local_node.first; + local[i]=local_node.second; + } +} + +/*!Converts a list of global node numbers on domain ip + * to a distributed array with local cell numbers. + * + * If a node in the list is represented on several domains, + * only the value with domain ip is returned + * + * */ +void ParallelTopology::convertGlobalNodeList(const int* node_list, int nbnode, int* local, int ip) +{ + if (m_node_glob_to_loc.empty()) + throw MEDMEM::MEDEXCEPTION("convertGlobalNodeList - Node mapping has not yet been built"); + + for (int i=0; i< nbnode; i++) + { + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_node_glob_to_loc.equal_range(node_list[i]); + for (mmiter it=range.first; it !=range.second; it++) + { + int ipfound=(it->second).first; + if (ipfound==ip) + local[i]=(it->second).second; + } + } +} + +/*!Converts a list of global node numbers + * to a distributed array with local cell numbers. + * + * If a node in the list is represented on several domains, + * all the values are put in the array + * */ +void ParallelTopology::convertGlobalNodeListWithTwins(const int* node_list, int nbnode, int*& local, int*& ip,int*& full_array, int& size) +{ + if (m_node_glob_to_loc.empty()) + throw MEDMEM::MEDEXCEPTION("convertGlobalNodeList - Node mapping has not yet been built"); + + size=0; + for (int i=0; i< nbnode; i++) + { + int count= m_node_glob_to_loc.count(node_list[i]); + // if (count > 1) + // cout << "noeud " << node_list[i]<< " doublon d'ordre " << count<<endl; + size+=count; + } + int index=0; + ip=new int[size]; + local=new int[size]; + full_array=new int[size]; + for (int i=0; i< nbnode; i++) + { + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_node_glob_to_loc.equal_range(node_list[i]); + for (mmiter it=range.first; it !=range.second; it++) + { + ip[index]=(it->second).first; + local[index]=(it->second).second; + full_array [index]=node_list[i]; + index++; + } + + } +} + +/*!Converts a list of global face numbers + * to a distributed array with local face numbers. + * + * If a face in the list is represented on several domains, + * all the values are put in the array + * */ +void ParallelTopology::convertGlobalFaceListWithTwins(const int* face_list, int nbface, int*& local, int*& ip, int*& full_array,int& size) +{ + size=0; + for (int i=0; i< nbface; i++) + { + //int count = m_face_glob_to_loc.count(face_list[i]); + //if (count >1) MESSAGE("face en doublon "<<face_list[i]); + size+= m_face_glob_to_loc.count(face_list[i]); + } + int index=0; + ip=new int[size]; + local=new int[size]; + full_array=new int[size]; + for (int i=0; i< nbface; i++) + { + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_face_glob_to_loc.equal_range(face_list[i]); + for (mmiter it=range.first; it !=range.second; it++) + { + ip[index]=(it->second).first; + local[index]=(it->second).second; + full_array[index]=face_list[i]; + index++; + } + + } +} + +//!converts a list of global cell numbers +//!to a distributed array with local cell numbers +void ParallelTopology::convertGlobalCellList(const int* cell_list, int nbcell, int* local, int* ip) +{ + for (int i=0; i< nbcell; i++) + { + hash_map<int, pair<int,int> >::const_iterator iter = m_glob_to_loc.find(cell_list[i]); + ip[i]=(iter->second).first; + local[i]=(iter->second).second; + } +} + +/*!Converts a list of global face numbers + * to a distributed array with local face numbers + */ +void ParallelTopology::convertGlobalFaceList(const int* face_list, int nbface, int* local, int* ip) +{ + for (int i=0; i< nbface; i++) + { + hash_map<int, pair<int,int> >::const_iterator iter = m_face_glob_to_loc.find(face_list[i]); + if (iter == m_face_glob_to_loc.end()) + { + throw MEDMEM::MED_EXCEPTION("convertGlobalFaceList - Face not found"); + } + ip[i]=(iter->second).first; + local[i]=(iter->second).second; + // cout << " in convertGlobalFAceList face global "<<face_list[i]<<" -> ("<<ip[i]<<","<<local[i]<<")"<<endl; + } +} + +/*!Converts a list of global node numbers on domain ip + * to a distributed array with local cell numbers. + * + * If a node in the list is represented on several domains, + * only the value with domain ip is returned + * + * */ +void ParallelTopology::convertGlobalFaceList(const int* face_list, int nbface, int* local, int ip) +{ + for (int i=0; i< nbface; i++) + { + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_face_glob_to_loc.equal_range(face_list[i]); + for (mmiter it=range.first; it !=range.second; it++) + { + int ipfound=(it->second).first; + if (ipfound==ip) + local[i]=(it->second).second; + + } + } +} + + +////creating node mapping +void ParallelTopology::createNodeMapping(map<MED_EN::medGeometryElement,int*>& type_connectivity, + map<MED_EN::medGeometryElement,int>& present_type_numbers, + vector<int>& polygon_conn, + vector<int>& polygon_conn_index, + vector<int>& polyhedron_conn, + vector<int>& polyhedron_conn_index, + vector<int>& polyhedron_face_index, + int idomain) +{ + set<int> local_numbers; + int local_index=0; + + map<MED_EN::medGeometryElement,int>::const_iterator iter; + for (iter = present_type_numbers.begin(); iter!=present_type_numbers.end();iter++) + { + int type=iter->first; + int nodes_per_type= type%100; + + if (!((type/100==m_mesh_dimension) + ||(type==MED_EN::MED_POLYGON && m_mesh_dimension==2) + ||(type==MED_EN::MED_POLYHEDRA && m_mesh_dimension==3))) continue; + + if (type != MED_EN::MED_POLYGON && type != MED_EN::MED_POLYHEDRA) + { + for (int icell=0; icell<present_type_numbers[type]; icell++) + { + for (int inode=0; inode<nodes_per_type; inode++) + { + int global=type_connectivity[type][icell*nodes_per_type+inode]; + if(local_numbers.find(global)==local_numbers.end()) + { + local_index++; + local_numbers.insert(global); + //m_node_loc_to_glob.insert(make_pair(make_pair(idomain,local_index),global)); + m_node_loc_to_glob[idomain].push_back(global); + m_node_glob_to_loc.insert(make_pair(global,make_pair(idomain,local_index))); + // cout << "node : global ="<<global<<" local =("<<idomain<<","<<local_index<<")"<<endl; + } + } + + } + } + else if (type== MED_EN::MED_POLYGON) + { + for (int icell=0; icell<polygon_conn_index.size()-1; icell++) + { + for (int inode=polygon_conn_index[icell]; inode<polygon_conn_index[icell+1]; inode++) + { + int global=polygon_conn[inode-1]; + if(local_numbers.find(global)==local_numbers.end()) + { + local_index++; + local_numbers.insert(global); + //m_node_loc_to_glob.insert(make_pair(make_pair(idomain,local_index),global)); + m_node_loc_to_glob[idomain].push_back(global); + m_node_glob_to_loc.insert(make_pair(global,make_pair(idomain,local_index))); + // cout << "node : global ="<<global<<" local =("<<idomain<<","<<local_index<<")"<<endl; + } + } + + } + } + else if (type==MED_EN::MED_POLYHEDRA) + { + for (int icell=0; icell<polyhedron_conn_index.size()-1; icell++) + { + for (int iface = polyhedron_conn_index[icell]; + iface < polyhedron_conn_index[icell+1]; + iface++) + for (int inode=polyhedron_face_index[iface-1]; + inode<polyhedron_face_index[iface]; inode++) + { + int global=polyhedron_conn[inode-1]; + if(local_numbers.find(global)==local_numbers.end()) + { + local_index++; + local_numbers.insert(global); + //m_node_loc_to_glob.insert(make_pair(make_pair(idomain,local_index),global)); + m_node_loc_to_glob[idomain].push_back(global); + m_node_glob_to_loc.insert(make_pair(global,make_pair(idomain,local_index))); + // cout << "node : global ="<<global<<" local =("<<idomain<<","<<local_index<<")"<<endl; + } + } + + + } + } + + } + m_nb_nodes[idomain]=local_index; +} + +////creating face mapping +void ParallelTopology::createFaceMapping(const MESHCollection& initial_collection) +// map<MED_EN::medGeometryElement,int*>& type_list, +// map<MED_EN::medGeometryElement,int>& present_type_numbers, +// int idomain + +{ + // containers for the new topology + vector<int> new_counts(m_nb_domain,0); + vector<int> domain_counts(m_nb_domain,0); + const Topology* old_topology=initial_collection.getTopology(); + int nb_domain_old=old_topology->nbDomain(); + int global_index=old_topology->getFaceNumber(); + set <pair<int, pair<int,int> > > global_treated; + + //definition of the d-1 constituent for the considered mesh dimension + MED_EN::medEntityMesh constituent_entity; + switch (m_mesh_dimension) + { + case 3: + constituent_entity= MED_EN::MED_FACE; + break; + case 2: + constituent_entity = MED_EN::MED_EDGE; + break; + } + + for (int iold=0; iold<nb_domain_old;iold++) + { + int nbplainface = initial_collection.getMesh(iold)->getNumberOfElements(constituent_entity,MED_EN::MED_ALL_ELEMENTS); + int nbtotalface = initial_collection.getMesh(iold)->getNumberOfElementsWithPoly(constituent_entity,MED_EN::MED_ALL_ELEMENTS); + SCRUTE(nbplainface); + SCRUTE(nbtotalface); + const int* face_conn; + const int* face_offset; + const int* poly_conn; + const int* poly_index; + if (nbtotalface >0) + { + if (nbplainface >0) + { + face_conn = initial_collection.getMesh(iold)->getConnectivity(MED_EN::MED_FULL_INTERLACE, + MED_EN::MED_NODAL,constituent_entity,MED_EN::MED_ALL_ELEMENTS); + face_offset = initial_collection.getMesh(iold)->getConnectivityIndex(MED_EN::MED_NODAL,constituent_entity); + } + if (nbtotalface > nbplainface) + { + poly_conn = initial_collection.getMesh(iold)->getPolygonsConnectivity(MED_EN::MED_NODAL,constituent_entity); + poly_index = initial_collection.getMesh(iold)->getPolygonsConnectivityIndex(MED_EN::MED_NODAL,constituent_entity); + } + + } + else + { + face_conn=0; + face_offset=0; + } + for (int iface=0;iface<nbtotalface; iface++) + { + int global_face_number = old_topology->convertFaceToGlobal(iold,iface+1); + + // int inode = face_offset[iface]; + for (int i=0; i<m_nb_domain; i++) domain_counts[i]=0; + set <int> nodes; + int nbnodes; + if (iface<nbplainface) + { + nbnodes=face_offset[iface+1]-face_offset[iface]; + for (int inode= face_offset[iface];inode < face_offset[iface+1]; inode++) + { + int node=face_conn[inode-1]; + + int global = old_topology->convertNodeToGlobal(iold,node); + // cout << "global node "<<global<<"ip "<<iold<< "noeud"<<node<<endl; + nodes.insert(global); + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_node_glob_to_loc.equal_range(global); + + int ip; + for (mmiter it=range.first; it !=range.second; it++) + { + ip=(it->second).first; + domain_counts[ip]++; + } + } + } + else + { + nbnodes =poly_index[iface-nbplainface+1]- poly_index[iface-nbplainface]; + for (int inode= poly_index[iface-nbplainface];inode < poly_index[iface-nbplainface+1]; inode++) + { + int node=poly_conn[inode-1]; + // SCRUTE(node); + int global = old_topology->convertNodeToGlobal(iold,node); + // cout << "global node "<<global<<"ip "<<iold<< "noeud"<<node<<endl; + // SCRUTE(global); + nodes.insert(global); + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_node_glob_to_loc.equal_range(global); + + int ip; + for (mmiter it=range.first; it !=range.second; it++) + { + ip=(it->second).first; + domain_counts[ip]++; + } + } + } + set<int>::const_iterator iter_node = nodes.begin(); + int numbers[3]; + for (int i=0; i<3; i++) + { + numbers[i]=*iter_node; + iter_node++; + } + set <pair<int, pair<int,int> > > ::iterator iter_triplets; + pair<int, pair<int,int> > triplet = make_pair(numbers[0],make_pair(numbers[1],numbers[2])); + iter_triplets=global_treated.find(triplet); + if (iter_triplets==global_treated.end()) + { + global_treated.insert(triplet); + // int nbnodes=face_offset[iface+1]-face_offset[iface]; + if (global_face_number == -1) + { + global_index++; + global_face_number=global_index; + + } + // SCRUTE(nbnodes); + + for (int inew=0;inew<m_nb_domain;inew++) + { + // SCRUTE(domain_counts[inew]); + if(domain_counts[inew]==nbnodes) + { + new_counts[inew]++; + m_face_glob_to_loc.insert(make_pair(global_face_number,make_pair(inew,new_counts[inew]))); + //m_face_loc_to_glob.insert(make_pair(make_pair(inew,new_counts[inew]),global_face_number)); + m_face_loc_to_glob[inew].push_back(global_face_number); + } + } + } + } + } + + for (int inew=0;inew<m_nb_domain;inew++) + { + m_nb_faces[inew]=new_counts[inew]; + MESSAGE(" Nb faces ["<<inew<<"]="<<m_nb_faces[inew]); + } + MESSAGE(" total number of faces"<<getFaceNumber()); +} + +////creating node mapping +void ParallelTopology::createFaceMapping2ndversion(const MESHCollection& initial_collection) + +{ + // containers for the new topology + vector<int> new_counts(m_nb_domain,0); + vector<int> domain_counts(m_nb_domain,0); + const Topology* old_topology=initial_collection.getTopology(); + int nb_domain_old=old_topology->nbDomain(); + //int global_index=old_topology->getFaceNumber(); + // set <pair<int, pair<int,int> > > global_treated; + + //definition of the d-1 constituent for the considered mesh dimension + MED_EN::medEntityMesh constituent_entity; + switch (m_mesh_dimension) + { + case 3: + constituent_entity= MED_EN::MED_FACE; + break; + case 2: + constituent_entity = MED_EN::MED_EDGE; + break; + } + + for (int iold=0; iold<nb_domain_old;iold++) + { + int nbcell=old_topology->getCellNumber(iold); + + const int* face_conn = initial_collection.getMesh(iold)-> + getConnectivity(MED_EN::MED_FULL_INTERLACE, + MED_EN::MED_DESCENDING,MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + const int* face_offset = initial_collection.getMesh(iold)-> + getConnectivityIndex(MED_EN::MED_DESCENDING,MED_EN::MED_CELL); + MESSAGE("end of connectivity calculation"); + set<int> global_treated; + for (int icell=0; icell<nbcell; icell++) + { + int global_cell_number=old_topology->convertCellToGlobal(iold,icell+1); + int inew = getCellDomainNumber(global_cell_number); + + for (int iface = face_offset[icell]; iface < face_offset[icell+1]; iface++) + { + int global_face_number=old_topology->convertFaceToGlobal(iold,abs(face_conn[iface-1])); + if (global_treated.find (global_face_number)==global_treated.end()) + { + new_counts[inew]++; + m_face_glob_to_loc.insert(make_pair(global_face_number,make_pair(inew,new_counts[inew]))); + + //m_face_loc_to_glob.insert(make_pair(make_pair(inew,new_counts[inew]),global_face_number)); + m_face_loc_to_glob[inew].push_back(global_face_number); + global_treated.insert(global_face_number); + + } + } + } + } + + + for (int inew=0;inew<m_nb_domain;inew++) + { + m_nb_faces[inew]=new_counts[inew]; + // cout << " Nb faces ["<<inew<<"]="<<m_nb_faces[inew]<<endl; + } + MESSAGE(" total number of faces"<<getFaceNumber()); +} + + +//replacing a table of global numbering with a table with local numberings +// type_connectivity contains global connectivity for each type in input +// type_connectivity contains local connectivity for each type in output +void ParallelTopology::convertToLocal(map<MED_EN::medGeometryElement,int*>& type_connectivity, + map<MED_EN::medGeometryElement,int>& present_type_numbers, + int idomain, + MED_EN::medEntityMesh entity) +{ + int dimension; + switch (entity) + { + case MED_EN::MED_CELL: + dimension=m_mesh_dimension; + break; + case MED_EN::MED_FACE: + dimension=2; + break; + case MED_EN::MED_EDGE: + dimension=1; + break; + } + + MED_EN::MESH_ENTITIES::const_iterator currentEntity; + list<MED_EN::medGeometryElement>::const_iterator iter; + currentEntity = MED_EN::meshEntities.find(MED_EN::MED_CELL); + + for (iter = (*currentEntity).second.begin();iter != (*currentEntity).second.end(); iter++) + { + MED_EN::medGeometryElement type = (*iter); + if (type/100 != dimension) continue; + for (int inode=0; inode<present_type_numbers[type]*(type%100); inode++) + { + // cout <<" inode :"<<inode<< " global = "<<type_connectivity[type][inode]; + int global = type_connectivity[type][inode]; + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_node_glob_to_loc.equal_range(global); + for (mmiter it=range.first; it !=range.second; it++) + { + if ((it->second).first==idomain) + type_connectivity[type][inode]=(it->second).second; + } + // cout << " local = " <<type_connectivity[type][inode]<<endl; + } + + } +} + +//replacing a table of global numbering with a table with local numberings +// type_connectivity contains global connectivity for each type in input +// type_connectivity contains local connectivity for each type in output +void ParallelTopology::convertToLocal2ndVersion(int* nodes, int nbnodes, int idomain) +{ + for (int inode=0; inode<nbnodes; inode++) + { + // cout <<" inode :"<<inode<< " global = "<<type_connectivity[type][inode]; + int global = nodes[inode]; + typedef hash_multimap<int,pair<int,int> >::iterator mmiter; + pair<mmiter,mmiter> range=m_node_glob_to_loc.equal_range(global); + for (mmiter it=range.first; it !=range.second; it++) + { + if ((it->second).first==idomain) + nodes[inode]=(it->second).second; + } + } + } + + +//! computing arrays with node/node correspondencies +void ParallelTopology::computeNodeNodeCorrespondencies(int idomain, vector<MEDMEM::MEDSKYLINEARRAY*>& corr) const +{ + vector <int> sizes (m_nb_domain,0); + vector <int*> values (m_nb_domain); + for (int i=0; i<m_nb_domain; i++) + { + values[i]=0; + } + + for (int inode=0; inode<m_nb_nodes[idomain]; inode++) + { + //int global = (m_node_loc_to_glob.find(make_pair(idomain,inode+1)))->second; + int global = m_node_loc_to_glob[idomain][inode]; + typedef hash_multimap<int,pair<int,int> >::const_iterator mm; + pair<mm,mm> range = m_node_glob_to_loc.equal_range(global); + for (mm it=range.first; it !=range.second; it++) + { + int id = (it->second).first; + if (id !=idomain) + { + sizes[id]++; + } + } + } + + for (int ip=0; ip<m_nb_domain; ip++) + { + if (sizes[ip]>0) + values[ip]=new int[2*sizes[ip]]; + sizes[ip]=0; + } + + + for (int inode=0; inode<m_nb_nodes[idomain]; inode++) + { + //int global = (m_node_loc_to_glob.find(make_pair(idomain,inode+1)))->second; + int global = m_node_loc_to_glob[idomain][inode]; + typedef hash_multimap<int,pair<int,int> >::const_iterator mm; + pair<mm,mm> range = m_node_glob_to_loc.equal_range(global); + for (mm it=range.first; it !=range.second; it++) + { + int id = (it->second).first; + if (id !=idomain) + { + values[id][sizes[id]*2]=inode+1; + values[id][sizes[id]*2+1]=(it->second).second; + sizes[id]++; + } + } + } + + for (int i=0; i< m_nb_domain; i++) + { + if (sizes[i]!=0) + { + int* index = new int[sizes[i]+1]; + for (int j=0; j<sizes[i]+1; j++) + index[j]=j+1; + corr[i]=new MEDMEM::MEDSKYLINEARRAY(sizes[i],2*sizes[i],index,values[i]); + delete[] index; + delete[] values[i]; + } + } +} + +//! computing arrays with cell/cell correspondencies +void ParallelTopology::computeCellCellCorrespondencies(int idomain, vector<MEDMEM::MEDSKYLINEARRAY*>& corr, const Graph* graph) const +{ + vector <int> sizes (m_nb_domain,0); + vector <int*> values (m_nb_domain); + for (int i=0; i<m_nb_domain; i++) + { + values[i]=0; + } + + vector <hash_multimap<int,int> > cell_corresp; + //TODO : remplacer int* par une map <int,int> + vector<int* > number_of_connections(m_nb_domain); + + cell_corresp.resize(m_nb_domain); + number_of_connections.resize(m_nb_domain); + for (int i=0; i<m_nb_domain; i++) + { + // cell_corresp[i]=new multimap<int,int>; + if (m_nb_cells[i] >0) + { + number_of_connections[i]=new int[m_nb_cells[idomain]]; + for (int j=0; j<m_nb_cells[idomain]; j++) + number_of_connections[i][j]=0; + } + } + + const MEDMEM::MEDSKYLINEARRAY* skylinegraph = graph->getGraph(); + + const int* index=skylinegraph->getIndex(); + const int* value=skylinegraph->getValue(); + + for (int icell=0; icell<m_nb_cells[idomain]; icell++) + { + //int global = m_loc_to_glob.find(make_pair(idomain,icell+1))->second; + int global= m_loc_to_glob[idomain][icell]; + for (int ii=index[global-1]-1; ii<index[global]-1; ii++) + { + int distant_global=value[ii]; + + // Integrity check commented out for performance + + // if ( m_glob_to_loc.find(global) == m_glob_to_loc.end()) + // { + // throw MED_EXCEPTION(" Erreur dans le mapping glob -> loc"); + // } + pair<int,int> local = m_glob_to_loc.find(distant_global)->second; + + if (local.first != idomain) + { + cell_corresp[local.first].insert(make_pair(icell+1,local.second)); + number_of_connections[local.first][icell]++; + + } + } + } + + for (int inew=0; inew<m_nb_domain; inew++) + { + if (inew==idomain) continue; + + int* new_index=new int[m_nb_cells[idomain]+1]; + new_index[0]=1; + for (int i=0; i<m_nb_cells[idomain]; i++) + { + new_index[i+1]=new_index[i]+number_of_connections[inew][i]; + } + int* new_value; + if (new_index[m_nb_cells[idomain]]-1 > 0) + new_value=new int[new_index[m_nb_cells[idomain]]-1]; + else + new_value=0; + + int value_i=0; + + for (int i=0; i<m_nb_cells[idomain]; i++) + { + typedef hash_multimap<int,int>::iterator mmiter; + pair<mmiter,mmiter> range=cell_corresp[inew].equal_range(i+1); + for (mmiter it=range.first; it!=range.second; it++) + { + new_value[value_i]=it->second; + value_i++; + } + } + if (value_i>0) + { + corr[inew] = new MEDMEM::MEDSKYLINEARRAY(m_nb_cells[idomain], new_index[m_nb_cells[idomain]]-1, new_index,new_value,true); + } + else + { + corr[inew]=0; + if (new_value !=0) delete[]new_value; + delete[]new_index; + } + + } + + for (int inew=0; inew<m_nb_domain; inew++) + if (m_nb_cells[inew]>0) + delete[] number_of_connections[inew]; + +} + +void ParallelTopology::recreateFaceMapping(vector<map<MED_EN::medGeometryElement, vector<MEDSPLITTER_FaceModel*> > > face_map) +{ + m_face_glob_to_loc.clear(); + for (int i=0; i<m_nb_domain;i++) + m_face_loc_to_glob[i].clear(); + + for (int idomain=0; idomain<m_nb_domain; idomain++) + { + int ilocal=1; + map<MED_EN::medGeometryElement, vector<MEDSPLITTER_FaceModel*> >::const_iterator iter = face_map[idomain].begin(); + for (; iter != face_map[idomain].end(); iter++) + { + for (int i=0; i< (iter->second).size(); i++) + { + MEDSPLITTER_FaceModel* face = (iter->second)[i]; + //cout << "global :"<<face->getGlobal()<<" - "<<ilocal<<endl; + m_face_glob_to_loc.insert(make_pair(face->getGlobal(),make_pair(idomain,ilocal))); + m_face_loc_to_glob[idomain].push_back(face->getGlobal()); + ilocal++; + } + } + m_nb_faces[idomain] =ilocal-1; + } +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_ParallelTopology.hxx b/src/MEDSPLITTER/MEDSPLITTER_ParallelTopology.hxx new file mode 100644 index 000000000..d337a9fba --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_ParallelTopology.hxx @@ -0,0 +1,342 @@ +#ifndef PARALLELTOPOLOGY_HXX_ +#define PARALLELTOPOLOGY_HXX_ + +#include <set> +#include <ext/hash_map> +#include "boost/shared_ptr.hpp" + +#include "MEDSPLITTER_Topology.hxx" + +namespace __gnu_cxx +{ + template<> struct hash< pair<int,int> > + { + size_t operator()( const pair<int,int>& x ) const + { + return hash< int >()( x.first*1000000+x.second ); + } + }; +} + +namespace MEDSPLITTER { + + class Graph; + class MESHCollection; + class MEDSPLITTER_FaceModel; + + class ParallelTopology:public Topology + { + + public: + + ParallelTopology(); + + ParallelTopology(vector<MEDMEM::MESH*>, vector<MEDMEM::CONNECTZONE*>,vector<int*>&, vector<int*>&, vector<int*>&); + + ParallelTopology(boost::shared_ptr<Graph> graph, int nbdomain, int mesh_dimension); + + ~ParallelTopology(); + //!converts a list of global cell numbers + //!to a distributed array with local cell numbers + void convertGlobalNodeList(const int*, int,int*,int*); + void convertGlobalNodeList(const int*, int,int*,int); + void convertGlobalNodeListWithTwins(const int* face_list, int nbnode, int*& local, int*& ip, int*& full_array, int& size); + + //!converts a list of global node numbers + //!to a distributed array with local cell numbers + void convertGlobalCellList(const int*, int , int*, int *); + + //!converts a list of global face numbers + //!to a distributed array with local face numbers + void convertGlobalFaceList(const int*, int , int*, int *); + void convertGlobalFaceList(const int*, int , int*, int); + void convertGlobalFaceListWithTwins(const int* face_list, int nbface, int*& local, int*& ip, int*& full_array,int& size); + + //!creating node mapping + + void createNodeMapping(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + std::vector<int>& conn, + std::vector<int>& conn_index, + std::vector<int>& polyhedron_conn, + std::vector<int>& polyhedron_conn_index, + std::vector<int>& polyhedron_face_index, + int idomain); + + // void createFaceMapping(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + // std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + // int idomain); + + void createFaceMapping(const MESHCollection &); + void createFaceMapping2ndversion(const MESHCollection &); + + //!converting node global numberings to local numberings + void convertToLocal(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + int idomain, + MED_EN::medEntityMesh entity); + void convertToLocal2ndVersion(int* nodes, int nbnodes, int idomain); + + + + //! computing arrays with node/node correspondencies + void computeNodeNodeCorrespondencies(int nbdomain,vector<MEDMEM::MEDSKYLINEARRAY*>& ) const; + + //! computing arrays with node/node correspondencies + void computeCellCellCorrespondencies(int nbdomain,vector<MEDMEM::MEDSKYLINEARRAY*>&, const Graph* ) const; + + //! retrieving Graph + // boost::shared_ptr<Graph> getGraph() const; + + + //!converting node local numbering to global + inline int convertNodeToGlobal(int ip,int icell) const + { + //return m_node_loc_to_glob.find(make_pair(ip,icell))->second; + return m_node_loc_to_glob[ip][icell-1]; + } + + //!converting face local numbering to global + inline int convertFaceToGlobal(int ip,int iface) const + { + // if (m_face_loc_to_glob.find(make_pair(ip,icell))==m_face_loc_to_glob.end()) + // return -1; + // else + //return m_face_loc_to_glob.find(make_pair(ip,icell))->second; + return m_face_loc_to_glob[ip][iface-1]; + } + + //converting cell global numbering to local + inline int convertCellToGlobal(int ip,int icell) const + { + // if (m_loc_to_glob.find(make_pair(ip,icell))==m_loc_to_glob.end()) + // return -1; + // else + //return m_loc_to_glob.find(make_pair(ip,icell))->second; + return m_loc_to_glob[ip][icell-1]; + } + + inline void convertNodeToGlobal(int ip, const int* local, int n, int* global)const + { + for (int i=0; i<n; i++) + global[i]=m_node_loc_to_glob[ip][local[i]-1]; + //global[i]=m_node_loc_to_glob.find(make_pair(ip,local[i]))->second; + } + + inline void convertCellToGlobal(int ip, const int* local, int n, int* global)const + { + for (int i=0; i<n; i++) + global[i]=m_loc_to_glob[ip][local[i]-1]; + //global[i]=m_loc_to_glob.find(make_pair(ip,local[i]))->second; + } + + inline void convertFaceToGlobal(int ip, const int* local, int n, int* global)const + { + for (int i=0; i<n; i++) + { + global[i]=m_face_loc_to_glob[ip][local[i]-1]; +// if (m_face_loc_to_glob.find(make_pair(ip,local[i]))==m_face_loc_to_glob.end()) +// { +// cout << "problem : face # "<< local[i] << " of processor "<< ip<< " was not found in mapping loc2glob"<<endl; +// global[i]=-1; +// } +// else +// global[i]=m_face_loc_to_glob.find(make_pair(ip,local[i]))->second; + } + } + + inline int nbDomain() const + { + return m_nb_domain; + } + + int nbCells() const + { + return m_nb_total_cells; + } + + + inline int nbCells( int idomain) const + { + return m_nb_cells[idomain]; + } + + + + + //!retrieving number of nodes + inline int getNodeNumber(int idomain) const + { + return m_nb_nodes[idomain]; + } + + inline int getNodeNumber() const + { + if (m_node_glob_to_loc.empty()) return 0; + set <int> keys; + for (__gnu_cxx::hash_multimap<int, pair<int,int> >::const_iterator iter= m_node_glob_to_loc.begin(); + iter!=m_node_glob_to_loc.end(); + iter++) { + keys.insert(iter->first); + } + return keys.size(); + } + + //!retrieving list of nodes in global numbers + inline void getNodeList(int idomain, int* list) const + { + for (int i=0; i<m_nb_nodes[idomain];i++) + { + list[i]=m_node_loc_to_glob[idomain][i]; + //list[i]=(m_node_loc_to_glob.find(make_pair(idomain,i+1)))->second; + } + } + + + + //!retrieving number of nodes + inline int getCellNumber(int idomain) const + { + return m_nb_cells[idomain]; + } + + inline int getCellDomainNumber(int global) const + { + return (m_glob_to_loc.find(global)->second).first; + } + + //!retrieving list of nodes in global numbers + inline void getCellList(int idomain, int* list) const + { + for (int i=0; i<m_nb_cells[idomain];i++) + { + list[i]=m_loc_to_glob[idomain][i]; + //list[i]=(m_loc_to_glob.find(make_pair(idomain,i+1)))->second; + } + + } + + inline int getFaceNumber(int idomain) const + { + return m_nb_faces[idomain]; + } + + inline int getFaceNumber() const + { + if (m_face_glob_to_loc.empty()) return 0; + set <int> keys; + for (__gnu_cxx::hash_multimap<int, pair<int,int> >::const_iterator iter= m_face_glob_to_loc.begin(); + iter!=m_face_glob_to_loc.end(); + iter++) { + keys.insert(iter->first); + } + return keys.size(); + } + + + //!retrieving list of faces in global numbers + inline void getFaceList(int idomain, int* list) const + { + for (int i=0; i<m_nb_faces[idomain];i++) + { + list[i]=m_face_loc_to_glob[idomain][i]; + //list[i]=(m_face_loc_to_glob.find(make_pair(idomain,i+1)))->second; + } + + } + + inline int convertGlobalFace(int iglobal, int idomain) + { + typedef __gnu_cxx::hash_multimap<int, pair<int,int> >::const_iterator MMiter; + pair<MMiter,MMiter> eq = m_face_glob_to_loc.equal_range(iglobal); + for (MMiter it=eq.first; it != eq.second; it++) + { + SCRUTE (it->second.first); + SCRUTE (idomain); + if (it->second.first == idomain) return it->second.second; + + } + return -1; + } + + inline int convertGlobalNode(int iglobal, int idomain) + { + typedef __gnu_cxx::hash_multimap<int, pair<int,int> >::const_iterator MMiter; + pair<MMiter,MMiter> eq = m_node_glob_to_loc.equal_range(iglobal); + for (MMiter it=eq.first; it != eq.second; it++) + { + if (it->second.first == idomain) return it->second.second; + } + return -1; + } + //!adding a face to the topology + inline void appendFace(int idomain, int ilocal, int iglobal) + { + m_face_loc_to_glob[idomain].push_back(iglobal); + m_face_glob_to_loc.insert(make_pair(iglobal,make_pair(idomain,ilocal))); + } + + boost::shared_ptr<Graph> getGraph() const + { + return m_graph; + } + +//!recreating a face mapping from scratch + void recreateFaceMapping(vector<map<MED_EN::medGeometryElement, vector<MEDSPLITTER_FaceModel*> > >); + + + + + private: + //!mapping global -> local + __gnu_cxx::hash_map<int,pair<int,int> > m_glob_to_loc; + + // bool is_equal_pair (pair<int,int> a, pair<int,int> b){ + // return (a.first==b.first && a.second==b.second); + // } + //!mapping local -> global + //map<pair<int,int>,int> m_loc_to_glob; + + // + //__gnu_cxx::hash_map<pair<int,int>,int, __gnu_cxx::hash<pair<int,int> > > m_loc_to_glob; + vector<vector<int> > m_loc_to_glob; + //!mapping global -> local + __gnu_cxx::hash_multimap<int,pair<int,int> > m_node_glob_to_loc; + + //!mapping local -> global + // map<pair<int,int>,int> m_node_loc_to_glob; + //__gnu_cxx::hash_map<pair<int,int>,int, __gnu_cxx::hash<pair<int,int> > > m_node_loc_to_glob; + vector<vector <int> > m_node_loc_to_glob; + + + //!mapping global -> local + __gnu_cxx::hash_multimap<int,pair<int,int> > m_face_glob_to_loc; + + //!mapping local -> global + //__gnu_cxx::hash_map<pair<int,int>,int, __gnu_cxx::hash<pair<int,int> > > m_face_loc_to_glob; + vector<vector <int> > m_face_loc_to_glob; + + //map<pair<int,int>,int> m_face_loc_to_glob; + + vector<int> m_nb_cells; + + vector<int> m_nb_nodes; + + vector<int> m_nb_faces; + + int m_nb_total_cells; + + int m_nb_total_nodes; + + int m_nb_total_faces; + + int m_nb_domain; + + int m_mesh_dimension; + + boost::shared_ptr<Graph> m_graph; + }; + + +} +#endif /*PARALLELTOPOLOGY_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_SCOTCHGraph.cxx b/src/MEDSPLITTER/MEDSPLITTER_SCOTCHGraph.cxx new file mode 100644 index 000000000..6fc19f150 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_SCOTCHGraph.cxx @@ -0,0 +1,85 @@ +#include <cstdio> +extern "C" { +#define restrict +#include "bin/scotch.h" +} +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_SCOTCHGraph.hxx" + +using namespace MEDSPLITTER; + +SCOTCHGraph::SCOTCHGraph():Graph() +{ +} + +SCOTCHGraph::SCOTCHGraph(const MEDMEM::MEDSKYLINEARRAY* graph, int* edgeweight):Graph(graph,edgeweight) +{ +} + +SCOTCHGraph::~SCOTCHGraph() +{ + if (m_partition!=0) {delete m_partition; m_partition=0;} + if (m_graph!=0) {delete m_graph; m_graph=0;} +} + +void SCOTCHGraph::partGraph(int ndomain, const string& options_string) +{ + // number of graph vertices + int n = m_graph->getNumberOf(); + + //graph + int * xadj=const_cast<int*>(m_graph->getIndex()); + int * adjncy = const_cast<int*>(m_graph->getValue()); + + //ndomain + int nparts = ndomain; + + // output parameters + int* partition = new int[n+1]; + + SCOTCH_Graph scotch_graph; + + SCOTCH_graphInit(&scotch_graph); + + + SCOTCH_graphBuild(&scotch_graph, + 1, //premier indice 1 + n, // nb of graph nodes + xadj, + 0, + m_cellweight, //graph vertices loads + 0, + xadj[n], // number of edges + adjncy, + m_edgeweight); + + SCOTCH_Strat scotch_strategy; + SCOTCH_stratInit(&scotch_strategy); + + //!user-defined options for the strategy + if (options_string!="") + SCOTCH_stratGraphMap(&scotch_strategy,options_string.c_str()); + + + if (nparts>1) + SCOTCH_graphPart(&scotch_graph,nparts,&scotch_strategy,partition); + else + // partition for 1 subdomain + for (int i=0; i<n+1; i++) + partition[i]=1; + + SCOTCH_stratExit(&scotch_strategy); + SCOTCH_graphExit(&scotch_graph); + + int* index=new int [n+1]; + index[0]=1; + for (int i=0; i<n; i++) + { + index[i+1]=index[i]+1; + } + + //creating a skylinearray with no copy of the index and partition array + // the fifth argument true specifies that only the pointers are passed + //to the object + m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, true); +} diff --git a/src/MEDSPLITTER/MEDSPLITTER_SCOTCHGraph.hxx b/src/MEDSPLITTER/MEDSPLITTER_SCOTCHGraph.hxx new file mode 100644 index 000000000..3abbb71ab --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_SCOTCHGraph.hxx @@ -0,0 +1,18 @@ +#ifndef SCOTCHGRAPH_HXX_ +#define SCOTCHGRAPH_HXX_ + +#include "MEDSPLITTER.hxx" + +namespace MEDSPLITTER { +class MEDSPLITTER_EXPORT SCOTCHGraph:public Graph +{ +public: + SCOTCHGraph(); + SCOTCHGraph(const MEDMEM::MEDSKYLINEARRAY*, int* edgeweight=0); + virtual ~SCOTCHGraph(); + void partGraph(int ndomain, const string& options_string=""); +//private: +// const MEDMEM::MEDSKYLINEARRAY* m_graph; +}; +} +#endif /*SCOTCHGRAPH_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_SequentialTopology.cxx b/src/MEDSPLITTER/MEDSPLITTER_SequentialTopology.cxx new file mode 100644 index 000000000..bd8f73ce4 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_SequentialTopology.cxx @@ -0,0 +1,67 @@ +#include "MEDMEM_SkyLineArray.hxx" +#include "MEDMEM_ConnectZone.hxx" +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Exception.hxx" + +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" + +using namespace MEDSPLITTER; + +SequentialTopology::SequentialTopology(){throw MEDEXCEPTION("SequentialTopology - not implemented yet");} + +SequentialTopology::SequentialTopology(std::vector<MEDMEM::MESH*>, std::vector<MEDMEM::CONNECTZONE*>){throw MEDEXCEPTION("SequentialTopology - not implemented yet");} + +//!converts a list of global cell numbers +//!to a distributed array with local cell numbers +void SequentialTopology::convertGlobalNodeList(const int*, int,int*,int*){} + +//!converts a list of global node numbers +//!to a distributed array with local cell numbers +void SequentialTopology::convertGlobalCellList(const int*, int , int*, int *){} + +//number of doamins +int SequentialTopology::nbDomain() const +{ + return 0; +} + +//number of cells +int SequentialTopology::nbCells() const +{ + return 0; +} + +//number of cells on a specific domain +int SequentialTopology::nbCells(int idomain) const +{ + return 0; +} + +//!creating node mapping +void SequentialTopology::createNodeMapping(vector<int*> type_connectivity,int* present_type_numbers, int idomain){} + +//!converting node global numberings to local numberings +void SequentialTopology::convertToLocal(vector<int*> type_connectivity,int* present_type_numbers){} + +//!retrieving number of nodes +int SequentialTopology::getNodeNumber(int idomain) const +{ + return 0; +} + +//!retrieving list of nodes +void SequentialTopology::getNodeList(int idomain, int* list) const{} + +//!retrieving number of cells +int SequentialTopology::getCellNumber(int idomain) const +{ + return 0; +} + +//!retrieving list of cells +void SequentialTopology::getCellList(int idomain, int* list) const{} + + + diff --git a/src/MEDSPLITTER/MEDSPLITTER_SequentialTopology.hxx b/src/MEDSPLITTER/MEDSPLITTER_SequentialTopology.hxx new file mode 100644 index 000000000..68b5cdc2b --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_SequentialTopology.hxx @@ -0,0 +1,72 @@ +#ifndef SequentialTOPOLOGY_HXX_ +#define SequentialTOPOLOGY_HXX_ + +#include "MEDSPLITTER.hxx" + +namespace MEDSPLITTER { + class SequentialTopology:public Topology + { + + public: + + SequentialTopology(); + SequentialTopology(std::vector<MEDMEM::MESH*>, std::vector<MEDMEM::CONNECTZONE*>); + + //!converts a list of global cell numbers + //!to a distributed array with local cell numbers + void convertGlobalNodeList(const int*, int,int*,int*); + + //!converts a list of global node numbers + //!to a distributed array with local cell numbers + void convertGlobalCellList(const int*, int , int*, int *); + + //number of doamins + int nbDomain() const; + + //number of cells + int nbCells() const; + + //number of cells on a specific domain + int nbCells(int idomain) const; + + //!creating node mapping + void createNodeMapping(vector<int*> type_connectivity,int* present_type_numbers, int idomain); + + //!converting node global numberings to local numberings + void convertToLocal(vector<int*> type_connectivity,int* present_type_numbers); + + //!retrieving number of nodes + int getNodeNumber(int idomain) const ; + + //!retrieving list of nodes + void getNodeList(int idomain, int* list) const; + + //!retrieving number of cells + int getCellNumber(int idomain) const ; + + //!retrieving list of cells + void getCellList(int idomain, int* list) const; + + private: + //!mapping global -> local + map<int,pair<int,int> > m_glob_to_loc; + + //!mapping local -> global + map<pair<int,int>,int> m_loc_to_glob; + + //!mapping global -> local + multimap<int,pair<int,int> > m_node_glob_to_loc; + + //!mapping local -> global + map<pair<int,int>,int> m_node_loc_to_glob; + + vector<int> m_nb_cells; + + vector<int> m_nb_nodes; + + int m_nb_total_cells; + + int m_nb_total_nodes; + }; +} +#endif /*SequentialTOPOLOGY_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_Topology.hxx b/src/MEDSPLITTER/MEDSPLITTER_Topology.hxx new file mode 100644 index 000000000..218fac388 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_Topology.hxx @@ -0,0 +1,124 @@ +#ifndef TOPOLOGY_HXX_ +#define TOPOLOGY_HXX_ + +#include "boost/shared_ptr.hpp" + +namespace MEDMEM +{ + class CONNECTZONE; +} + +namespace MEDSPLITTER { + + class Graph; + class MESHCollection; + class MEDSPLITTER_FaceModel; + + class Topology + { + public: + Topology(){} + Topology(std::vector<MEDMEM::MESH*>, std::vector<MEDMEM::CONNECTZONE*>){} + + virtual ~Topology(){} + + //!converts a list of global cell numbers + //!to a distributed array with local cell numbers + virtual void convertGlobalNodeList(const int* list, int nb, int* local, int*ip)=0; + virtual void convertGlobalNodeList(const int* list, int nb, int* local, int ip)=0; + //!converts a list of global node numbers + //!to a distributed array with local cell numbers + virtual void convertGlobalCellList(const int*list , int nb, int* local, int*ip)=0; + + //!converts a list of global face numbers + //!to a distributed array with local face numbers + virtual void convertGlobalFaceList(const int*list , int nb, int* local, int*ip)=0; + virtual void convertGlobalFaceList(const int*list , int nb, int* local, int ip)=0; + virtual void convertGlobalFaceListWithTwins(const int* face_list, int nbface, int*& local, int*& ip, int*& full_array, int& size)=0; + virtual void convertGlobalNodeListWithTwins(const int* face_list, int nbnode, int*& local, int*& ip, int*& full_array, int& size)=0; + + + //number of doamins + virtual int nbDomain() const =0; + + //number of cells + virtual int nbCells() const=0; + + + //number of cells on a specific domain + virtual int nbCells(int idomain) const=0; + + ////creating node mapping + virtual void createNodeMapping(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + std::vector<int>& polygon_conn, + std::vector<int>& polygon_conn_index, + std::vector<int>& polyhedron_conn, + std::vector<int>& polyhedron_conn_index, + std::vector<int>& polyhedron_face_index, + int domain)=0; + + ////creating face mapping + // virtual void createFaceMapping(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + // std::map<MED_EN::medGeometryElement,int>& present_type_numbers,int domain)=0; + // + virtual void createFaceMapping(const MESHCollection&)=0; + + //converting node global numberings to local numberings + virtual void convertToLocal(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + int idomain, + MED_EN::medEntityMesh entity)=0; + //converting node global numberings to local numberings + virtual void convertToLocal2ndVersion(int*,int,int)=0; + + virtual int convertNodeToGlobal(int ip,int icell)const=0; + virtual int convertFaceToGlobal(int ip,int icell)const=0; + virtual int convertCellToGlobal(int ip,int icell)const=0; + + virtual void convertNodeToGlobal(int ip,const int* local, int n, int* global)const=0 ; + virtual void convertCellToGlobal(int ip,const int* local, int n, int* global)const=0 ; + virtual void convertFaceToGlobal(int ip,const int* local, int n, int* global)const=0 ; + + //retrieving number of nodes + virtual int getNodeNumber(int idomain) const =0; + virtual int getNodeNumber() const=0; + //retrieving list of nodes + virtual void getNodeList(int idomain, int* list) const =0; + + //retrieving number of nodes + virtual int getCellNumber(int idomain) const =0; + + //retrieving list of nodes + virtual void getCellList(int idomain, int* list) const =0; + + //retrieving number of faces + virtual int getFaceNumber(int idomain) const =0; + virtual int getFaceNumber()const =0; + + //retrieving list of nodes + virtual void getFaceList(int idomain, int* list) const =0; + + //adding a face to the mapping + virtual void appendFace(int idomain, int ilocal, int iglobal)=0; + + //converting a global face number to a local representation + virtual int convertGlobalFace(int iglobal, int idomain)=0; + + //converting a global node number to a local representation + virtual int convertGlobalNode(int iglobal, int idomain)=0; + + //! computing arrays with node/node correspondencies + virtual void computeNodeNodeCorrespondencies(int nbdomain, vector<MEDMEM::MEDSKYLINEARRAY*>&) const =0; + + //! computing arrays with cell/cell correspondencies + virtual void computeCellCellCorrespondencies(int nbdomain, vector<MEDMEM::MEDSKYLINEARRAY*>&, const Graph*) const =0; + + //! retrieving graph + virtual boost::shared_ptr<Graph> getGraph() const=0; + + //!recreating a face mapping from scratch + virtual void recreateFaceMapping(std::vector<std::map<MED_EN::medGeometryElement, std::vector<MEDSPLITTER_FaceModel*> > >) =0; + }; +} +#endif /*TOPOLOGY_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_UserGraph.cxx b/src/MEDSPLITTER/MEDSPLITTER_UserGraph.cxx new file mode 100644 index 000000000..d65032066 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_UserGraph.cxx @@ -0,0 +1,40 @@ +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_UserGraph.hxx" + + +using namespace MEDSPLITTER; + +/*! constructor that allows to specify the desired partition + * \param partition as table giving the domain number for each cell + * (domain numbers range from 0 to ndomain-1 + * \param n number of cells in the mesh + */ +UserGraph::UserGraph(MEDMEM::MEDSKYLINEARRAY* array, const int* partition, int n):Graph(array,0) +{ + + int* index=new int [n+1]; + index[0]=1; + for (int i=0; i<n; i++) + { + index[i+1]=index[i]+1; + } + + //creating a skylinearray with copy of the index and partition array + // the fifth argument false specifies that the values are passed + //to the object + //m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, true); + m_partition = new MEDMEM::MEDSKYLINEARRAY(n,n, index, partition, false); + delete[] index; +} + +UserGraph::~UserGraph() +{ + if (m_partition!=0) {delete m_partition; m_partition=0;} + if (m_graph!=0) {delete m_graph; m_graph=0;} +} + +void UserGraph::partGraph(int ndomain, const string& options) +{ + cerr<<"MEDSPLITTER::UserGraph::partGraph() should not have to be used"<<endl; +} + diff --git a/src/MEDSPLITTER/MEDSPLITTER_UserGraph.hxx b/src/MEDSPLITTER/MEDSPLITTER_UserGraph.hxx new file mode 100644 index 000000000..a210ee24a --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_UserGraph.hxx @@ -0,0 +1,17 @@ +#ifndef MEDSPLITTER_USERGRAPH_HXX_ +#define MEDSPLITTER_USERGRAPH_HXX_ + +#include "MEDSPLITTER.hxx" + +namespace MEDSPLITTER +{ + class MEDSPLITTER_EXPORT UserGraph : public Graph + { + public: + UserGraph(MEDMEM::MEDSKYLINEARRAY*, const int*, int); + virtual ~UserGraph(); + void partGraph(int, const string& options=""); + }; +} + +#endif /*MEDSPLITTER_USERGRAPH_HXX_*/ diff --git a/src/MEDSPLITTER/MEDSPLITTER_utils.hxx b/src/MEDSPLITTER/MEDSPLITTER_utils.hxx new file mode 100644 index 000000000..dd4832fb7 --- /dev/null +++ b/src/MEDSPLITTER/MEDSPLITTER_utils.hxx @@ -0,0 +1,14 @@ +#ifndef MEDSPLITTER_UTILS_HXX_ +#define MEDSPLITTER_UTILS_HXX_ + +#include <string> + +namespace MEDSPLITTER { + std::string trim(std::string& s,const std::string& drop = " ") + { + std::string r=s.erase(s.find_last_not_of(drop)+1); + return r.erase(0,r.find_first_not_of(drop)); + } + +} +#endif /*MEDSPLITTER_UTILS_HXX_*/ diff --git a/src/MEDSPLITTER/Makefile.am b/src/MEDSPLITTER/Makefile.am new file mode 100644 index 000000000..4c3846fef --- /dev/null +++ b/src/MEDSPLITTER/Makefile.am @@ -0,0 +1,98 @@ +# MED MEDMEM : MED files in memory +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# this directory must be recompiled before Test folder + +if CPPUNIT_IS_OK + SUBDIRS=. Test +endif + +lib_LTLIBRARIES= libmedsplitter.la + +salomeinclude_HEADERS= \ +MEDSPLITTER_Topology.hxx \ +MEDSPLITTER_MESHCollection.hxx \ +MEDSPLITTER_MESHCollectionDriver.hxx \ +MEDSPLITTER_MESHCollectionMedXMLDriver.hxx \ +MEDSPLITTER_MESHCollectionMedAsciiDriver.hxx \ +MEDSPLITTER_ParallelTopology.hxx \ +MEDSPLITTER_FaceModel.hxx \ +MEDSPLITTER_Graph.hxx\ +MEDSPLITTER_UserGraph.hxx\ +MEDSPLITTER_API.hxx \ +MEDSPLITTER.hxx + +if MED_ENABLE_METIS + salomeinclude_HEADERS+= MEDSPLITTER_METISGraph.hxx +endif +if MED_ENABLE_SCOTCH + salomeinclude_HEADERS+= MEDSPLITTER_SCOTCHGraph.hxx +endif + +dist_libmedsplitter_la_SOURCES= \ +MEDSPLITTER_MESHCollection.cxx \ +MEDSPLITTER_MESHCollectionDriver.cxx \ +MEDSPLITTER_MESHCollectionMedXMLDriver.cxx \ +MEDSPLITTER_MESHCollectionMedAsciiDriver.cxx \ +MEDSPLITTER_ParallelTopology.cxx \ +MEDSPLITTER_Graph.cxx\ +MEDSPLITTER_UserGraph.cxx\ +MEDSPLITTER_API.cxx + +if MED_ENABLE_METIS + dist_libmedsplitter_la_SOURCES+= MEDSPLITTER_METISGraph.cxx +endif +if MED_ENABLE_SCOTCH + dist_libmedsplitter_la_SOURCES+= MEDSPLITTER_SCOTCHGraph.cxx +endif + +libmedsplitter_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ + $(BOOST_CPPFLAGS) $(LIBXML_CPPFLAGS) \ + -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core +libmedsplitter_la_LDFLAGS= $(MED2_LIBS) $(HDF5_LIBS) $(STDLIB) $(LIBXML_LIBS) \ + ../MEDMEM/libmedmem.la ../MEDWrapper/V2_1/Core/libmed_V2_1.la + +if MED_ENABLE_KERNEL + libmedsplitter_la_CPPFLAGS+= ${KERNEL_CXXFLAGS} + libmedsplitter_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace +endif +if MED_ENABLE_METIS + libmedsplitter_la_CPPFLAGS+= $(METIS_CPPFLAGS) + libmedsplitter_la_LDFLAGS+= $(METIS_LIBS) +endif +if MED_ENABLE_SCOTCH + libmedsplitter_la_CPPFLAGS+= $(SCOTCH_CPPFLAGS) + libmedsplitter_la_LDFLAGS+= $(SCOTCH_LIBS) +endif + +# Executables targets +bin_PROGRAMS= medsplitter + +dist_medsplitter_SOURCES= medsplitter.cxx + +medsplitter_CPPFLAGS= $(libmedsplitter_la_CPPFLAGS) +medsplitter_LDADD= $(libmedsplitter_la_LDFLAGS) -lm $(BOOST_LIBS) libmedsplitter.la +if MED_ENABLE_KERNEL + medsplitter_LDADD+= -lSALOMEBasics +endif diff --git a/src/MEDSPLITTER/Test/MEDSPLITTERTest.cxx b/src/MEDSPLITTER/Test/MEDSPLITTERTest.cxx new file mode 100644 index 000000000..33322ebc0 --- /dev/null +++ b/src/MEDSPLITTER/Test/MEDSPLITTERTest.cxx @@ -0,0 +1,79 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDSPLITTERTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_STRING.hxx" + +#include <sstream> +#include <cmath> + +using namespace std; + +// ============================================================================ +/*! + * Set up the environment + */ +// ============================================================================ +void MEDSPLITTERTest::setUp() +{ +} + +// ============================================================================ +/*! + * - delete + */ +// ============================================================================ +void MEDSPLITTERTest::tearDown() +{ +} + +// #1: MEDSPLITTER_MESHCollection.hxx } MEDSPLITTERTest_MESHCollection.cxx +// #2: MEDSPLITTER_MESHCollectionDriver.hxx } MEDSPLITTERTest_MESHCollectionDriver.cxx +// #3: MEDSPLITTER_Topology.hxx (-) } MEDSPLITTERTest_Topology.cxx +// #4: MEDSPLITTER_ParallelTopology.hxx } MEDSPLITTERTest_ParallelTopology.cxx +// #5: MEDSPLITTER_SequentialTopology.hxx } MEDSPLITTERTest_SequentialTopology.cxx +// #6: MEDSPLITTER_API.hxx } MEDSPLITTERTest_API.cxx +// #7: MEDSPLITTER_Graph.hxx } MEDSPLITTERTest_Graph.cxx +// #8: MEDSPLITTER_METISGraph.hxx } MEDSPLITTERTest_METISGraph.cxx +// #9: MEDSPLITTER_SCOTCHGraph.hxx } MEDSPLITTERTest_SCOTCHGraph.cxx +// #10: MEDSPLITTER_UserGraph.hxx } MEDSPLITTERTest_UserGraph.cxx (-) + + +/*! + * Tool to remove temporary files. + * Allows automatique removal of temporary files in case of test failure. + */ +MEDSPLITTERTest_TmpFilesRemover::~MEDSPLITTERTest_TmpFilesRemover() +{ + set<string>::iterator it = myTmpFiles.begin(); + for (; it != myTmpFiles.end(); it++) { + if (access((*it).data(), F_OK) == 0) + remove((*it).data()); + } + myTmpFiles.clear(); + //cout << "~MEDSPLITTERTest_TmpFilesRemover()" << endl; +} + +bool MEDSPLITTERTest_TmpFilesRemover::Register(const string theTmpFile) +{ + return (myTmpFiles.insert(theTmpFile)).second; +} diff --git a/src/MEDSPLITTER/Test/MEDSPLITTERTest.hxx b/src/MEDSPLITTER/Test/MEDSPLITTERTest.hxx new file mode 100644 index 000000000..e2b32b0b6 --- /dev/null +++ b/src/MEDSPLITTER/Test/MEDSPLITTERTest.hxx @@ -0,0 +1,99 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _MEDSPLITTERTEST_HXX_ +#define _MEDSPLITTERTEST_HXX_ + +#include <cppunit/extensions/HelperMacros.h> + +#include <set> +#include <string> +#include <iostream> + +namespace MEDSPLITTER { + class MESH; +}; + +class MEDSPLITTERTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( MEDSPLITTERTest ); + CPPUNIT_TEST( testMESHCollection_constructor ); + CPPUNIT_TEST( testMESHCollection_read_seq); + CPPUNIT_TEST( testMESHCollection_read_para); + CPPUNIT_TEST( testMESHCollection_square); + CPPUNIT_TEST( testMESHCollection_square_with_faces); + CPPUNIT_TEST( testMESHCollection_indivisible); + CPPUNIT_TEST( testMESHCollection_user_partition); + CPPUNIT_TEST( testParallelTopology_graph_constructor); + CPPUNIT_TEST( testMESHCollection_complete_sequence); + CPPUNIT_TEST( testMESHCollection_complete_sequence_with_polygon); + CPPUNIT_TEST( testMESHCollection_families); +// CPPUNIT_TEST( testMESHCollection_complete_sequence_with_polyhedra); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp(); + void tearDown(); + + void testMESHCollection_constructor(); + void testMESHCollection_read_seq(); + void testMESHCollection_read_para(); + void testMESHCollection_square(); + void testMESHCollection_square_with_faces(); + void testMESHCollection_indivisible(); + void testMESHCollection_user_partition(); + void testMESHCollection_complete_sequence(); + void testMESHCollection_complete_sequence_with_polygon(); + void testMESHCollection_complete_sequence_with_polyhedra(); + void testMESHCollection_families(); + void testParallelTopology_graph_constructor(); + + }; + +// to automatically remove temporary files from disk +class MEDSPLITTERTest_TmpFilesRemover +{ +public: + MEDSPLITTERTest_TmpFilesRemover() {} + ~MEDSPLITTERTest_TmpFilesRemover(); + bool Register(const std::string theTmpFile); + +private: + std::set<std::string> myTmpFiles; +}; + +/*! + * Tool to print array to stream. + */ +template<class T> +void MEDSPLITTERTest_DumpArray (std::ostream & stream, const T* array, const int length, const std::string text) +{ + stream << text << ": {"; + if (length > 0) { + stream << array[0]; + for (int i = 1; i < length; i++) { + stream << ", " << array[i]; + } + } + stream << "}" << std::endl; +}; + +#endif diff --git a/src/MEDSPLITTER/Test/MEDSPLITTERTest_MESHCollection.cxx b/src/MEDSPLITTER/Test/MEDSPLITTERTest_MESHCollection.cxx new file mode 100644 index 000000000..8b42659eb --- /dev/null +++ b/src/MEDSPLITTER/Test/MEDSPLITTERTest_MESHCollection.cxx @@ -0,0 +1,1196 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDSPLITTERTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_ConnectZone.hxx" +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_GaussLocalization.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_Group.hxx" + +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" +//#include "MEDSPLITTER_METISGraph.hxx" +//#include "MEDSPLITTER_SCOTCHGraph.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_MESHCollectionDriver.hxx" + +#include "MEDMEM_Exception.hxx" + +#include <string> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + + +using namespace std; +using namespace MEDSPLITTER; +using namespace MEDMEM; +/*! + * Check methods (33), defined in MEDSPLITTER_MESHCollection.hxx: + * (-) MESHCollection(); + * (-) MESHCollection(const MESHCollection&, Topology*); + * (+) MESHCollection(const std::string& filename); + * (+) MESHCollection(const std::string& filename, const std::string& meshname); + * (-) ~MESHCollection(); + * (+) void write(const std::string& filename); + * (-) MESHCollectionDriver* retrieveDriver(); + * (-) MESHCollectionDriver* getDriver() const; + * (-) void buildCellGraph(MEDMEM::MEDSKYLINEARRAY* & array,int *& edgeweights ); + * (-) void buildCellGraph2ndversion(MEDMEM::MEDSKYLINEARRAY* & array,int *& edgeweights ); + * (+) Topology* createPartition(int nbdomain, Graph::splitter_type type = Graph::METIS, + const string& ="", int* edgeweights=0, int* verticesweights=0); + * (-) Topology* createPartition(const int* partition); + * (-) void getTypeList(int* cell_list,int nb_cells,MED_EN::medEntityMesh entity, + MED_EN::medGeometryElement* type_list) const ; + * (-) void getCoordinates(int* node_list,int nb_nodes, double* coordinates) const ; + * (-) void getNodeConnectivity( const int* cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ; + * (-) void getFaceConnectivity( const int* cell_list,int nb_cells,MED_EN::medEntityMesh,MED_EN::medGeometryElement type, int* type_connectivity) const ; + * (+) int getMeshDimension() const ; + * (+) int getSpaceDimension() const ; + * (+) std::string getSystem() const; + * (-) std::string getMeshName() const; + * (-) std::vector<MEDMEM::MESH*>& getMesh() ; + * (-) MEDMEM::MESH* getMesh(int) const; + * (-) std::vector<MEDMEM::CONNECTZONE*>& getCZ(); + * (-) Topology* getTopology() const ; + * (-) void setTopology(Topology* topology); + * (+) string getName() const {return m_name;} + * (+) void setName(const string& name) {m_name=name;} + * (-) void castFamilies(const MESHCollection& old_collection); + * (-) void castSupport(const MESHCollection& old_collection, std::vector<const MEDMEM::SUPPORT*> old_support, std::vector<MEDMEM::SUPPORT*> new_support); + * (-) void castAllFields(const MESHCollection& old_collection); + * (-) void castField(const MESHCollection& old_collection, const string& fieldname, int itnumber, int ordernumber); + * (+) void setIndivisibleGroup(const string& a); + * (-) void buildConnectZones(int idomain); + */ + + +void MEDSPLITTERTest::testMESHCollection_constructor() +{ + string data_dir = getenv("DATA_DIR"); + string filename_rd = data_dir + "/MedFiles/carre_en_quad4_import22.med"; + string fileNotExist_rd = "notExist22.med"; + string emptyfilename = ""; + + + //--------------------------Test READ ONLY part------------------------------// + + ///////////////////////////////////////////////////////////// + // TEST1a: Open not existing sequential and parallel file // + ///////////////////////////////////////////////////////////// + string meshname="non_existent"; + + CPPUNIT_ASSERT_THROW(MESHCollection mc1(fileNotExist_rd, meshname), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(MESHCollection mc2(fileNotExist_rd), MEDEXCEPTION); + + CPPUNIT_ASSERT_THROW(MESHCollection mc3(filename_rd, meshname), MEDEXCEPTION); + + // ////////////////////////////////////////////// + // // TEST1b: Open file with empty file name /// + // ////////////////////////////////////////////// + // + CPPUNIT_ASSERT_THROW(MESHCollection mc4(emptyfilename, meshname), MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(MESHCollection mc5(emptyfilename), MEDEXCEPTION); + +} + + +//! Testing basic manipulation for a sequential file +void MEDSPLITTERTest::testMESHCollection_read_seq() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filename_seq_wr = tmp_dir + "/myWrField_seq_pointe22"; + string filename_seq_med = tmp_dir + "/myWrField_seq_pointe221.med"; + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_seq_wr); + aRemover.Register(filename_seq_med); + + //--------------------------Test READ ONLY part------------------------------// + + // ///////////////////////////////////////////// + // // TEST2: Manipulation of a single MED file + // ///////////////////////////////////////////// + string meshname="maa1"; + MESHCollection collection(filename_rd,meshname); + collection.setDriverType(MEDSPLITTER::MedAscii); + CPPUNIT_ASSERT_EQUAL(meshname,collection.getName()); + string newname = "New_name"; + collection.setName(newname); + CPPUNIT_ASSERT_EQUAL(newname,collection.getName()); + string systemname="CARTESIAN"; + CPPUNIT_ASSERT_EQUAL(systemname,collection.getSystem()); + CPPUNIT_ASSERT_EQUAL(3,collection.getMeshDimension()); + CPPUNIT_ASSERT_EQUAL(3,collection.getSpaceDimension()); + + collection.write(filename_seq_wr); + + //Reading from the master file + MESHCollection collection2(filename_seq_wr); + CPPUNIT_ASSERT_EQUAL(collection.getName(),collection2.getName()); + + //Reading from the med file + MESHCollection collection3(filename_seq_med,meshname); + CPPUNIT_ASSERT_EQUAL(meshname,collection3.getName()); + +} + +//! Testing basic manipulation for a parallel file + +void MEDSPLITTERTest::testMESHCollection_read_para() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filename_para_wr = tmp_dir + "/myWrField_para_pointe22_"; + string filename_xml = tmp_dir + "/myWrField_para_pointe22_.xml"; + string filename_para_med0 = tmp_dir + "/myWrField_para_pointe22_1.med"; + string filename_para_med1 = tmp_dir + "/myWrField_para_pointe22_2.med"; + + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_xml); + aRemover.Register(filename_para_med0); + aRemover.Register(filename_para_med1); + + string meshname="maa1"; + MESHCollection collection(filename_rd,meshname); + Topology* topo=0; + CPPUNIT_ASSERT_THROW(topo=collection.createPartition(0,Graph::METIS),MEDEXCEPTION); + if (topo!=0) delete topo; +#ifdef ENABLE_METIS + CPPUNIT_ASSERT_NO_THROW(topo=collection.createPartition(2,Graph::METIS)); +#else + CPPUNIT_ASSERT_THROW(topo=collection.createPartition(2,Graph::METIS), MEDEXCEPTION); + CPPUNIT_FAIL("METIS is not available, further test execution is not possible."); +#endif + MESHCollection new_collection(collection, topo); + new_collection.write(filename_para_wr); + + CPPUNIT_ASSERT_EQUAL(meshname,new_collection.getName()); + MESHCollection new_collection2(filename_xml); + CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName()); + + MESHCollection new_collection3(filename_para_med0,"maa1_1"); + CPPUNIT_ASSERT_EQUAL(collection.getName()+"_1",new_collection3.getName()); + delete topo; +} + +//!Testing a normal scheme + +/* + * test_SPLITTER_square + * + * computes a partitioning for the following geometry + * + * + * + * 7------------8------------9 + * | | | + * | | | + * | 3 | 4 | + * | | | + * | | | + * 4------------5------------6 + * | | | + * | | | + * | 1 | 2 | + * | | | + * | | | + * 1------------2------------3 + * + * Result of the 2 domain split : + * + * 5------------6 5------------6 + * | | | | + * | | | | + * | 2 | | 2 | + * | | | | + * | | | | + * 1------------2 1------------2 + * | | | | + * | | | | + * | 1 | | 1 | + * | | | | + * | | | | + * 4------------3 4------------3 + */ + + +void MEDSPLITTERTest::testMESHCollection_square() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/carre_en_quad4_import22.med"; + string filename_wr = tmp_dir+"/carre_split"; + string filename_wr_1 = tmp_dir+"/carre_split1.med"; + string filename_wr_2 = tmp_dir+"/carre_split2.med"; + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_wr_1); + aRemover.Register(filename_wr_2); + + char meshname[20] = "carre_en_quad4"; + char meshname1[20] = "carre_en_quad4_1"; + char meshname2[20] = "carre_en_quad4_2"; + + MESHCollection collection(filename_rd,meshname); + MEDSPLITTER::Topology* topo; +#ifdef ENABLE_METIS + CPPUNIT_ASSERT_NO_THROW(topo = collection.createPartition(2,Graph::METIS)); +#else + CPPUNIT_ASSERT_THROW(topo = collection.createPartition(2,Graph::METIS), MEDEXCEPTION); + CPPUNIT_FAIL("METIS is not available, further test execution is not possible."); +#endif + MESHCollection new_collection(collection, topo); + + //collection.write("/export/home/test_splitter"); + new_collection.write(filename_wr); + new_collection.castAllFields(collection); + + MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1); + MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2); + + // testing number of elements for each partition + int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + + CPPUNIT_ASSERT_EQUAL(nbelem1,2); + CPPUNIT_ASSERT_EQUAL(nbelem2,2); + + + //testing number of joints + med_2_3::med_idt fid1 = med_2_3::MEDouvrir(const_cast<char*> (filename_wr_1.c_str()),med_2_3::MED_LECTURE); + med_2_3::med_idt fid2 = med_2_3::MEDouvrir(const_cast<char*> (filename_wr_2.c_str()),med_2_3::MED_LECTURE); + int nj1= med_2_3::MEDnJoint(fid1, meshname1); + int nj2= med_2_3::MEDnJoint(fid2, meshname2); + CPPUNIT_ASSERT_EQUAL(nj1,1); + CPPUNIT_ASSERT_EQUAL(nj2,1); + + //testing distant domains + + char desc1[MED_TAILLE_DESC]; + char maa_dist1[MED_TAILLE_NOM], jn1[MED_TAILLE_NOM]; + char desc2[MED_TAILLE_DESC], maa_dist2[MED_TAILLE_NOM], jn2[MED_TAILLE_NOM]; + int dom1, dom2; + med_2_3::MEDjointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1); + med_2_3::MEDjointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2); + CPPUNIT_ASSERT(strcmp(jn1,"joint_2")==0); + CPPUNIT_ASSERT(strcmp(jn2,"joint_1")==0); + CPPUNIT_ASSERT_EQUAL(dom1,1); + CPPUNIT_ASSERT_EQUAL(dom2,0); + + // testing node-node correspondency + med_2_3::med_entite_maillage typ_ent_loc=med_2_3::MED_NOEUD; + med_2_3::med_entite_maillage typ_ent_dist=med_2_3::MED_NOEUD; + med_2_3::med_geometrie_element typ_geo_loc= med_2_3::MED_POINT1; + med_2_3::med_geometrie_element typ_geo_dist= med_2_3::MED_POINT1; + + int n1 = med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + med_2_3::med_int* tab = new med_2_3::med_int[2*n1]; + + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreference1[6] = {2,1,3,4,6,5}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreference1[i]); + + delete[] tab; + + int n2 =med_2_3::MEDjointnCorres(fid2,meshname2,jn2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + tab = new med_2_3::med_int[2*n2]; + + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreference2[] = {1,2,4,3,5,6}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreference2[i]); + delete[] tab; + + //testing nodes global numbering + med_2_3::med_int* num = new med_2_3::med_int[6]; + cout << "Reading global " << MEDglobalNumLire(fid1, meshname1, num, 6, typ_ent_loc, typ_geo_loc) << endl; + + med_2_3::med_int globnoderef1[] = {4,5,2,1,7,8}; + + for (int i=0; i<6; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globnoderef1[i]); + delete[] num; + + //testing nodes global numbering + num = new med_2_3::med_int[6]; + MEDglobalNumLire(fid2, meshname2, num, 6, typ_ent_loc, typ_geo_loc); + med_2_3::med_int globnoderef2[] = {5,6,3,2,8,9}; + for (int i=0; i<6; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globnoderef2[i]); + delete[] num; + + //testing cell-cell correspondency + typ_ent_loc=med_2_3::MED_MAILLE; + typ_ent_dist=med_2_3::MED_MAILLE; + typ_geo_loc= med_2_3::MED_QUAD4; + typ_geo_dist= med_2_3::MED_QUAD4; + //joint1 + n1=med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + CPPUNIT_ASSERT_EQUAL(n1,2); + tab = new med_2_3::med_int[2*n1]; + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell1[4] = {1,1,2,2}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell1[i]); + + n2=med_2_3::MEDjointnCorres(fid2,meshname2,jn2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + CPPUNIT_ASSERT_EQUAL(n2,2); + delete[] tab; + //joint2 + tab = new med_2_3::med_int[2*n2]; + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell2[4] = {1,1,2,2}; + for (int i=0; i<n2; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell2[i]); + + delete[]tab; + + //testing cells global numbering + num = new med_2_3::med_int[2]; + MEDglobalNumLire(fid1, meshname1, num, 2, typ_ent_loc, typ_geo_loc); + med_2_3::med_int* globcellref = new med_2_3::med_int[2]; + globcellref[0]=1; + globcellref[1]=3; + + for (int i=0; i<2; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]); + delete[] num; + + //testing cells global numbering + num = new med_2_3::med_int[2]; + MEDglobalNumLire(fid2, meshname2, num, 2, typ_ent_loc, typ_geo_loc); + globcellref[0]=2; + globcellref[1]=4; + for (int i=0; i<2; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]); + delete[] num; + delete[] globcellref; + delete topo; +} + + +void MEDSPLITTERTest::testMESHCollection_square_with_faces() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/carre_en_quad4_import22.med"; + string filename_wr = tmp_dir+"/carre_split_faces"; + string filename_wr_1 = tmp_dir+"/carre_split_faces1.med"; + string filename_wr_2 = tmp_dir+"/carre_split_faces2.med"; + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_wr_1); + aRemover.Register(filename_wr_2); + + char meshname[20] = "carre_en_quad4"; + char meshname1[20] = "carre_en_quad4_1"; + char meshname2[20] = "carre_en_quad4_2"; + + /* + MESHCollection collection(filename_rd,meshname); + MEDSPLITTER::Topology* topo = collection.createPartition(2,Graph::METIS); + MESHCollection new_collection(collection, topo); + new_collection.setSubdomainBoundaryCreates(true); + + //collection.write("/export/home/test_splitter"); + new_collection.write(filename_wr); + new_collection.castAllFields(collection); + */ + + MESHCollection* collection = new MESHCollection (filename_rd,meshname); + MEDSPLITTER::Topology* topo = collection->createPartition(2,Graph::METIS); + MESHCollection* new_collection = new MESHCollection (*collection, topo); + new_collection->setSubdomainBoundaryCreates(true); + + //collection.write("/export/home/test_splitter"); + new_collection->write(filename_wr); + new_collection->castAllFields(*collection); + + MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1); + MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2); + + // testing number of elements for each partition + int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + + CPPUNIT_ASSERT_EQUAL(nbelem1,2); + CPPUNIT_ASSERT_EQUAL(nbelem2,2); + + + //testing number of joints + med_2_3::med_idt fid1 = med_2_3::MEDouvrir(const_cast<char*> (filename_wr_1.c_str()),med_2_3::MED_LECTURE); + med_2_3::med_idt fid2 = med_2_3::MEDouvrir(const_cast<char*> (filename_wr_2.c_str()),med_2_3::MED_LECTURE); + int nj1= med_2_3::MEDnJoint(fid1, meshname1); + int nj2= med_2_3::MEDnJoint(fid2, meshname2); + CPPUNIT_ASSERT_EQUAL(nj1,1); + CPPUNIT_ASSERT_EQUAL(nj2,1); + + //testing distant domains + + char desc1[MED_TAILLE_DESC]; + char maa_dist1[MED_TAILLE_NOM], jn1[MED_TAILLE_NOM]; + char desc2[MED_TAILLE_DESC], maa_dist2[MED_TAILLE_NOM], jn2[MED_TAILLE_NOM]; + int dom1, dom2; + med_2_3::MEDjointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1); + med_2_3::MEDjointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2); + CPPUNIT_ASSERT_EQUAL(dom1,1); + CPPUNIT_ASSERT_EQUAL(dom2,0); + + // testing node-node correspondency + med_2_3::med_entite_maillage typ_ent_loc=med_2_3::MED_NOEUD; + med_2_3::med_entite_maillage typ_ent_dist=med_2_3::MED_NOEUD; + med_2_3::med_geometrie_element typ_geo_loc= med_2_3::MED_POINT1; + med_2_3::med_geometrie_element typ_geo_dist= med_2_3::MED_POINT1; + + int n1 =med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + med_2_3::med_int* tab = new med_2_3::med_int[2*n1]; + + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreference1[6] = {2,1,3,4,6,5}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreference1[i]); + + delete[] tab; + + int n2 = med_2_3::MEDjointnCorres(fid2,meshname2,jn2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + tab = new med_2_3::med_int[2*n2]; + + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreference2[]={1,2,4,3,5,6}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreference2[i]); + delete[] tab; + + //testing nodes global numbering + med_2_3::med_int* num = new med_2_3::med_int[6]; + cout << "Reading global " << MEDglobalNumLire(fid1, meshname1, num, 6, typ_ent_loc, typ_geo_loc) << endl; + + med_2_3::med_int globnoderef1[]={4,5,2,1,7,8}; + + for (int i=0; i<6; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globnoderef1[i]); + delete[] num; + + //testing nodes global numbering + num = new med_2_3::med_int[6]; + MEDglobalNumLire(fid2, meshname2, num, 6, typ_ent_loc, typ_geo_loc); + med_2_3::med_int globnoderef2[]={5,6,3,2,8,9}; + for (int i=0; i<6; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globnoderef2[i]); + delete[] num; + + //testing cell-cell correspondency + typ_ent_loc=med_2_3::MED_MAILLE; + typ_ent_dist=med_2_3::MED_MAILLE; + typ_geo_loc= med_2_3::MED_QUAD4; + typ_geo_dist= med_2_3::MED_QUAD4; + //joint1 + n1=med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + CPPUNIT_ASSERT_EQUAL(n1,2); + tab = new med_2_3::med_int[2*n1]; + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell1[4]={1,1,2,2}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell1[i]); + + n2=med_2_3::MEDjointnCorres(fid2,meshname2,jn2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + CPPUNIT_ASSERT_EQUAL(n2,2); + delete[] tab; + //joint2 + tab = new med_2_3::med_int[2*n2]; + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell2[4]={1,1,2,2}; + for (int i=0; i<n2; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell2[i]); + + delete[]tab; + + //testing cells global numbering + num = new med_2_3::med_int[2]; + MEDglobalNumLire(fid1, meshname1, num, 2, typ_ent_loc, typ_geo_loc); + med_2_3::med_int* globcellref = new int[2]; + globcellref[0]=1; + globcellref[1]=3; + + for (int i=0; i<2; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]); + delete[] num; + + //testing cells global numbering + num = new med_2_3::med_int[2]; + MEDglobalNumLire(fid2, meshname2, num, 2, typ_ent_loc, typ_geo_loc); + globcellref[0]=2; + globcellref[1]=4; + for (int i=0; i<2; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globcellref[i]); + delete[] num; + + //testing face/face/correspondency + typ_ent_loc=med_2_3::MED_MAILLE; + typ_ent_dist=med_2_3::MED_MAILLE; + typ_geo_loc= med_2_3::MED_SEG2; + typ_geo_dist= med_2_3::MED_SEG2; + //joint1 + n1=med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + CPPUNIT_ASSERT_EQUAL(n1,2); + tab = new med_2_3::med_int[2*n1]; + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell3[4]={1,1,2,2}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell3[i]); + + n2=med_2_3::MEDjointnCorres(fid2,meshname2,jn2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + CPPUNIT_ASSERT_EQUAL(n2,2); + delete[] tab; + //joint2 + tab = new med_2_3::med_int[2*n2]; + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell4[4]={1,1,2,2}; + for (int i=0; i<n2; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell4[i]); + + delete[]tab; + + delete[]globcellref; + delete topo; + + delete collection; + delete new_collection; +} + +/* + * testing indivisibility functionality + * + * computes a partitioning for the a geometry + * with 8 TRIA3 and 4 QUAD4. A group containing the quads + * is set to be indivisible. + * It is checked that on output, there is only one group + * containing quads. + * SCOTCH is used for this partitioning. + * */ + +void MEDSPLITTERTest::testMESHCollection_indivisible() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/maill.00.med"; + string filename_wr = tmp_dir + "/carre_indivisible"; + string filename_wr_1 = tmp_dir + "/carre_indivisible1.med"; + string filename_wr_2 = tmp_dir + "/carre_indivisible2.med"; + string filename_wr_3 = tmp_dir + "/carre_indivisible3.med"; + string filename_wr_4 = tmp_dir + "/carre_indivisible4.med"; + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_wr_1); + aRemover.Register(filename_wr_2); + aRemover.Register(filename_wr_3); + aRemover.Register(filename_wr_4); + + + char meshname[20] = "MAILTRQU"; + char family[MED_TAILLE_NOM]="QUAD"; + MESHCollection collection(filename_rd,meshname); + collection.setIndivisibleGroup(family); + Topology* topo; +#ifdef ENABLE_SCOTCH + CPPUNIT_ASSERT_NO_THROW(topo = collection.createPartition(4,Graph::SCOTCH)); +#else + CPPUNIT_ASSERT_THROW(topo = collection.createPartition(4,Graph::SCOTCH), MEDEXCEPTION); + CPPUNIT_FAIL("SCOTCH is not available, further test execution is not possible."); +#endif + MESHCollection new_collection(collection, topo); + new_collection.write(filename_wr); + + char meshname1[20]="MAILTRQU_1"; + char meshname2[20]="MAILTRQU_2"; + char meshname3[20]="MAILTRQU_3"; + char meshname4[20]="MAILTRQU_4"; + + MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1); + MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2); + MEDMEM::MESH mesh3(MEDMEM::MED_DRIVER, filename_wr_3, meshname3); + MEDMEM::MESH mesh4(MEDMEM::MED_DRIVER, filename_wr_4, meshname4); + + // testing number of quads for each partition + int nbquad1= mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4); + int nbquad2= mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4); + int nbquad3= mesh3.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4); + int nbquad4= mesh4.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_QUAD4); + int nb_domain_with_quad=(nbquad1?1:0)+(nbquad2?1:0)+(nbquad3?1:0)+(nbquad4?1:0); + + CPPUNIT_ASSERT_EQUAL(nb_domain_with_quad,1); + delete topo; +} + +/* + * test_SPLITTER_user_partition + * + * computes joints for the following geometry + * with user specified partition + * domain0: (1,4)/ domain1:(2,3) + * + * + * 7------------8------------9 + * | | | + * | | | + * | 3 | 4 | + * | | | + * | | | + * 4------------5------------6 + * | | | + * | | | + * | 1 | 2 | + * | | | + * | | | + * 1------------2------------3 + * + * Result of the 2 domain split : + * + * 5------------6 5------------6 + * | | | | + * | | | | + * | 2 | | 2 | + * | | | | + * | | | | + * 7------------1 2------------7 + * 1------------2 1------------2 + * | | | | + * | | | | + * | 1 | | 1 | + * | | | | + * | | | | + * 4------------3 4------------3 + */ + + +void MEDSPLITTERTest::testMESHCollection_user_partition() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/carre_en_quad4_import22.med"; + string filename_wr = tmp_dir+"/carre_split_user"; + string filename_wr_1 = tmp_dir+"/carre_split_user1.med"; + string filename_wr_2 = tmp_dir+"/carre_split_user2.med"; + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + aRemover.Register(filename_wr_1); + aRemover.Register(filename_wr_2); + + char meshname[20] = "carre_en_quad4"; + char meshname1[20] = "carre_en_quad4_1"; + char meshname2[20] = "carre_en_quad4_2"; + + //int partition[4]={0,1,1,0}; + int* partition=new int[4]; + partition[0]=0; + partition[1]=1; + partition[2]=1; + partition[3]=0; + // + /* + MESHCollection collection(filename_rd,meshname); + Topology* topo = collection.createPartition(partition); + MESHCollection new_collection(collection, topo); + + //collection.write("/export/home/test_splitter"); + new_collection.write(filename_wr); + new_collection.castAllFields(collection); + */ + + MESHCollection* collection = new MESHCollection (filename_rd, meshname); + Topology* topo = collection->createPartition(partition); + MESHCollection* new_collection = new MESHCollection (*collection, topo); + new_collection->write(filename_wr); + new_collection->castAllFields(*collection); + + MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1); + MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2); + + // testing number of elements for each partition + + int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + CPPUNIT_ASSERT_EQUAL(nbelem1,2); + CPPUNIT_ASSERT_EQUAL(nbelem2,2); + + //testing number of joints + med_2_3::med_idt fid1 = med_2_3::MEDouvrir(const_cast<char*>(filename_wr_1.c_str()),med_2_3::MED_LECTURE); + med_2_3::med_idt fid2 = med_2_3::MEDouvrir(const_cast<char*>(filename_wr_2.c_str()),med_2_3::MED_LECTURE); + + int nj1= med_2_3::MEDnJoint(fid1, meshname1); + int nj2= med_2_3::MEDnJoint(fid2, meshname2); + CPPUNIT_ASSERT_EQUAL(nj1,1); + CPPUNIT_ASSERT_EQUAL(nj2,1); + + //testing distant domains + + char desc1[MED_TAILLE_DESC]; + char maa_dist1[MED_TAILLE_NOM], jn1[MED_TAILLE_NOM]; + char desc2[MED_TAILLE_DESC]; + char maa_dist2[MED_TAILLE_NOM], jn2[MED_TAILLE_NOM]; + //int dom1, dom2; + med_2_3::med_int dom1, dom2; + med_2_3::MEDjointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1); + med_2_3::MEDjointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2); + CPPUNIT_ASSERT_EQUAL(dom1,1); + CPPUNIT_ASSERT_EQUAL(dom2,0); + + // testing node-node correspondency + med_2_3::med_entite_maillage typ_ent_loc=med_2_3::MED_NOEUD; + med_2_3::med_entite_maillage typ_ent_dist=med_2_3::MED_NOEUD; + med_2_3::med_geometrie_element typ_geo_loc= med_2_3::MED_POINT1; + med_2_3::med_geometrie_element typ_geo_dist= med_2_3::MED_POINT1; + + int n1 = med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + med_2_3::med_int* tab = new med_2_3::med_int[2*n1]; + + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreference1[10] = {1,7,2,1,3,4,5,6,7,2}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreference1[i]); + delete[] tab; + + int n2 = med_2_3::MEDjointnCorres(fid2,meshname2,jn2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + tab = new med_2_3::med_int[2*n2]; + + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreference2[10] = {1,2,2,7,4,3,6,5,7,1}; + for (int i=0; i<2*n2; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreference2[i]); + delete[] tab; + + //testing nodes global numbering + med_2_3::med_int* num = new med_2_3::med_int[7]; + cout << "Reading global " << MEDglobalNumLire(fid1, meshname1, num, 7, typ_ent_loc, typ_geo_loc) << endl; + med_2_3::med_int globnoderef1[7] = {4,5,2,1,8,9,6}; + + for (int i=0; i<7; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globnoderef1[i]); + + delete[] num; + + //testing nodes global numbering + num = new med_2_3::med_int[7]; + MEDglobalNumLire(fid2, meshname2, num, 7, typ_ent_loc, typ_geo_loc); + med_2_3::med_int globnoderef2[7] = {5,6,3,2,7,8,4}; + for (int i=0; i<7; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globnoderef2[i]); + delete[] num; + + //testing cell-cell correspondency + typ_ent_loc=med_2_3::MED_MAILLE; + typ_ent_dist=med_2_3::MED_MAILLE; + typ_geo_loc= med_2_3::MED_QUAD4; + typ_geo_dist= med_2_3::MED_QUAD4; + //joint1 + n1 = med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + tab = new med_2_3::med_int[2*n1]; + med_2_3::MEDjointLire(fid1,meshname1,jn1,tab,n1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell1[8] = {1,1,1,2,2,1,2,2}; + for (int i=0; i<2*n1; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell1[i]); + + n2 = med_2_3::MEDjointnCorres(fid1,meshname1,jn1,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + delete[] tab; + //joint2 + tab = new med_2_3::med_int[2*n2]; + med_2_3::MEDjointLire(fid2,meshname2,jn2,tab,n2,typ_ent_loc, typ_geo_loc,typ_ent_dist, typ_geo_dist); + + med_2_3::med_int tabreferencecell2[8] = {1,1,1,2,2,1,2,2}; + for (int i=0; i<n2; i++) + CPPUNIT_ASSERT_EQUAL(tab[i],tabreferencecell2[i]); + delete[] tab; + + //testing cells global numbering + num = new med_2_3::med_int[2]; + MEDglobalNumLire(fid1, meshname1, num, 2, typ_ent_loc, typ_geo_loc); + med_2_3::med_int globcellref1[2] = {1,4}; + for (int i=0; i<2; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globcellref1[i]); + delete[] num; + + //testing cells global numbering + num = new med_2_3::med_int[2]; + MEDglobalNumLire(fid2, meshname2, num, 2, typ_ent_loc, typ_geo_loc); + med_2_3::med_int globcellref2[2] = {2,3}; + for (int i=0; i<2; i++) + CPPUNIT_ASSERT_EQUAL(num[i],globcellref2[i]); + + delete[] num; + delete topo; + delete[] partition; + delete collection; + delete new_collection; +} + + +/*! Testing a complex scenario to involve several shared pointers + * on similar structures + */ + +void MEDSPLITTERTest::testMESHCollection_complete_sequence() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/pointe_import22.med"; + string filename_para_wr = tmp_dir + "/myWrField_para1_pointe22_"; + string filename_para_med1 = tmp_dir + "/myWrField_para1_pointe22_1.med"; + string filename_para_med2 = tmp_dir + "/myWrField_para1_pointe22_2.med"; + string filename_para2_wr = tmp_dir + "/myWrField_para2_pointe22_"; + string filename_para2_med1 = tmp_dir + "/myWrField_para2_pointe22_1.med"; + string filename_para2_med2 = tmp_dir + "/myWrField_para2_pointe22_2.med"; + string filename_para2_med3 = tmp_dir + "/myWrField_para2_pointe22_3.med"; + string filename_seq_wr = tmp_dir + "/myWrField_seq_pointe22_"; + string filename_seq_med = tmp_dir + "/myWrField_seq_pointe22_1.med"; + + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_para_wr); + aRemover.Register(filename_para_med1); + aRemover.Register(filename_para_med2); + aRemover.Register(filename_para2_wr); + aRemover.Register(filename_para2_med1); + aRemover.Register(filename_para2_med2); + aRemover.Register(filename_para2_med3); + aRemover.Register(filename_seq_wr); + aRemover.Register(filename_seq_med); + + + string meshname="maa1"; + MESHCollection collection(filename_rd,meshname); + Topology* topo2; +#ifdef ENABLE_METIS + CPPUNIT_ASSERT_NO_THROW(topo2 = collection.createPartition(2,Graph::METIS)); +#else + CPPUNIT_ASSERT_THROW(topo2 = collection.createPartition(2,Graph::METIS), MEDEXCEPTION); + CPPUNIT_FAIL("METIS is not available, further test execution is not possible."); +#endif + MESHCollection new_collection(collection, topo2); + new_collection.setDriverType(MEDSPLITTER::MedAscii); + new_collection.write(filename_para_wr); + + MESHCollection new_collection2(filename_para_wr); + CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName()); + Topology* topo3; +#ifdef ENABLE_SCOTCH + CPPUNIT_ASSERT_NO_THROW(topo3 = new_collection2.createPartition(3,Graph::SCOTCH)); +#else + CPPUNIT_ASSERT_THROW(topo3 = new_collection2.createPartition(3,Graph::SCOTCH), MEDEXCEPTION); + CPPUNIT_FAIL("SCOTCH is not available, further test execution is not possible."); +#endif + MESHCollection new_collection3(new_collection2,topo3); + CPPUNIT_ASSERT_EQUAL(topo3->nbCells(),topo2->nbCells()); + new_collection3.setDriverType(MEDSPLITTER::MedAscii); + new_collection3.write(filename_para2_wr); + + MESHCollection new_collection4(filename_para2_wr); + Topology* topo1=new_collection4.createPartition(1,Graph::METIS); + + MESHCollection new_collection_seq(new_collection4,topo1); + new_collection_seq.write(filename_seq_wr); + MEDMEM::MESH* mesh_after = new_collection_seq.getMesh(0); + MEDMEM::MESH* mesh_before = collection.getMesh(0); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfNodes(), mesh_after->getNumberOfNodes()); + delete topo2; + delete topo3; + delete topo1; +} + +/*! Testing a complex scenario to involve several shared pointers + * on similar structures + */ + +void MEDSPLITTERTest::testMESHCollection_complete_sequence_with_polygon() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/recoll_bord.med"; + string filename_para_wr = tmp_dir + "/myWrField_para_recoll_"; + string filename_para_med1 = tmp_dir + "/myWrField_para_recoll_1.med"; + string filename_para_med2 = tmp_dir + "/myWrField_para_recoll_2.med"; + string filename_para2_wr = tmp_dir + "/myWrField_para2_recoll_"; + string filename_para2_med1 = tmp_dir + "/myWrField_para2_recoll_1.med"; + string filename_para2_med2 = tmp_dir + "/myWrField_para2_recoll_2.med"; + string filename_para2_med3 = tmp_dir + "/myWrField_para2_recoll_3.med"; + string filename_seq_wr = tmp_dir + "/myWrField_seq_recoll_"; + string filename_seq_med = tmp_dir + "/myWrField_seq_recoll_1.med"; + + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_para_wr); + aRemover.Register(filename_para_med1); + aRemover.Register(filename_para_med2); + aRemover.Register(filename_para2_wr); + aRemover.Register(filename_para2_med1); + aRemover.Register(filename_para2_med2); + aRemover.Register(filename_para2_med3); + aRemover.Register(filename_seq_wr); + aRemover.Register(filename_seq_med); + + + string meshname="Bord"; + MESHCollection collection(filename_rd,meshname); + Topology* topo2=collection.createPartition(2,Graph::METIS); + MESHCollection new_collection(collection, topo2); + new_collection.setDriverType(MEDSPLITTER::MedAscii); + new_collection.write(filename_para_wr); + + MESHCollection new_collection2(filename_para_wr); + CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName()); + Topology* topo3=new_collection2.createPartition(3,Graph::SCOTCH); + MESHCollection new_collection3(new_collection2,topo3); + CPPUNIT_ASSERT_EQUAL(topo3->nbCells(),topo2->nbCells()); + new_collection3.setDriverType(MEDSPLITTER::MedAscii); + new_collection3.write(filename_para2_wr); + + MESHCollection new_collection4(filename_para2_wr); + Topology* topo1; +#ifdef ENABLE_METIS + CPPUNIT_ASSERT_NO_THROW(topo1 = new_collection4.createPartition(1,Graph::METIS)); +#else + CPPUNIT_ASSERT_THROW(topo1 = new_collection4.createPartition(1,Graph::METIS), MEDEXCEPTION); + CPPUNIT_FAIL("METIS is not available, further test execution is not possible."); +#endif + + MESHCollection new_collection_seq(new_collection4,topo1); + new_collection_seq.write(filename_seq_wr); + MEDMEM::MESH* mesh_after = new_collection_seq.getMesh(0); + MEDMEM::MESH* mesh_before = collection.getMesh(0); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS), + mesh_after->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS), + mesh_after->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS), + mesh_after->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfNodes(), mesh_after->getNumberOfNodes()); + delete topo2; + delete topo3; + delete topo1; +} + +/*! Testing a complex scenario to involve several shared pointers + * on similar structures + */ + +void MEDSPLITTERTest::testMESHCollection_complete_sequence_with_polyhedra() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/poly3D.med"; + //string filename_rd = "/tmp/polyedres.med" ; + string filename_para_wr = tmp_dir + "/myWrField_para_poly3D_"; + string filename_para_med1 = tmp_dir + "/myWrField_para_poly3D_1.med"; + string filename_para_med2 = tmp_dir + "/myWrField_para_poly3D_2.med"; + string filename_para2_wr = tmp_dir + "/myWrField_para2_poly3D_"; + string filename_para2_med1 = tmp_dir + "/myWrField_para2_poly3D_1.med"; + string filename_para2_med2 = tmp_dir + "/myWrField_para2_poly3D_2.med"; + string filename_para2_med3 = tmp_dir + "/myWrField_para2_poly3D_3.med"; + string filename_seq_wr = tmp_dir + "/myWrField_seq_poly3D_"; + string filename_seq_med = tmp_dir + "/myWrField_seq_poly3D_1.med"; + + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_para_wr); + aRemover.Register(filename_para_med1); + aRemover.Register(filename_para_med2); + aRemover.Register(filename_para2_wr); + aRemover.Register(filename_para2_med1); + aRemover.Register(filename_para2_med2); + aRemover.Register(filename_para2_med3); + aRemover.Register(filename_seq_wr); + aRemover.Register(filename_seq_med); + + + string meshname="poly3D"; + MESHCollection collection(filename_rd,meshname); + Topology* topo2=collection.createPartition(2,Graph::METIS); + MESHCollection new_collection(collection, topo2); + new_collection.setDriverType(MEDSPLITTER::MedAscii); + new_collection.write(filename_para_wr); + + MESHCollection new_collection2(filename_para_wr); + CPPUNIT_ASSERT_EQUAL(collection.getName(),new_collection2.getName()); + Topology* topo3=new_collection2.createPartition(3,Graph::SCOTCH); + MESHCollection new_collection3(new_collection2,topo3); + CPPUNIT_ASSERT_EQUAL(topo3->nbCells(),topo2->nbCells()); + new_collection3.setDriverType(MEDSPLITTER::MedAscii); + new_collection3.write(filename_para2_wr); + + MESHCollection new_collection4(filename_para2_wr); + Topology* topo1=new_collection4.createPartition(1,Graph::METIS); + + MESHCollection new_collection_seq(new_collection4,topo1); + new_collection_seq.write(filename_seq_wr); + MEDMEM::MESH* mesh_after = new_collection_seq.getMesh(0); + MEDMEM::MESH* mesh_before = collection.getMesh(0); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_FACE, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS), mesh_after->getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS)); + CPPUNIT_ASSERT_EQUAL(mesh_before->getNumberOfNodes(), mesh_after->getNumberOfNodes()); + delete topo2; + delete topo3; + delete topo1; +} + +/*! Testing a TRIO_U scenario with subzones defined as families + + + */ + +void MEDSPLITTERTest::testMESHCollection_families() +{ + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/trio_2D.med"; + string filename_wr = tmp_dir+"/trio_split_faces"; + string filename_wr_1 = tmp_dir+"/trio_split_faces1.med"; + string filename_wr_2 = tmp_dir+"/trio_split_faces2.med"; + + // To remove tmp files from disk + MEDSPLITTERTest_TmpFilesRemover aRemover; + aRemover.Register(filename_wr); + // aRemover.Register(filename_wr_1); + //aRemover.Register(filename_wr_2); + + char meshname[30] = "dom"; + char meshname1[30] = "dom_1"; + char meshname2[30] = "dom_2"; + + + MESHCollection* collection = new MESHCollection (filename_rd,meshname); + MEDSPLITTER::Topology* topo = collection->createPartition(2,Graph::METIS); + MESHCollection* new_collection = new MESHCollection (*collection, topo, true, true); + new_collection->setSubdomainBoundaryCreates(true); + //collection.write("/export/home/test_splitter"); + new_collection->write(filename_wr); + new_collection->castAllFields(*collection); + + + delete collection; + delete new_collection; + + MEDMEM::MESH mesh1(MEDMEM::MED_DRIVER, filename_wr_1, meshname1); + MEDMEM::MESH mesh2(MEDMEM::MED_DRIVER, filename_wr_2, meshname2); + + // testing number of elements for each partition + int nbelem1=mesh1.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + int nbelem2=mesh2.getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS); + + CPPUNIT_ASSERT_EQUAL(nbelem1+nbelem2,2020); + + + + //testing number of joints + med_2_3::med_idt fid1 = med_2_3::MEDouvrir(const_cast<char*> (filename_wr_1.c_str()),med_2_3::MED_LECTURE); + med_2_3::med_idt fid2 = med_2_3::MEDouvrir(const_cast<char*> (filename_wr_2.c_str()),med_2_3::MED_LECTURE); + int nj1= med_2_3::MEDnJoint(fid1, meshname1); + int nj2= med_2_3::MEDnJoint(fid2, meshname2); + CPPUNIT_ASSERT_EQUAL(nj1,1); + CPPUNIT_ASSERT_EQUAL(nj2,1); + + //testing distant domains + + char desc1[MED_TAILLE_DESC+1]; + char maa_dist1[MED_TAILLE_NOM+1], jn1[MED_TAILLE_NOM+1]; + char desc2[MED_TAILLE_DESC+1], maa_dist2[MED_TAILLE_NOM+1], jn2[MED_TAILLE_NOM+1]; + int dom1, dom2; + med_2_3::MEDjointInfo(fid1, meshname1, 1, jn1, desc1, &dom1, maa_dist1); + med_2_3::MEDjointInfo(fid2, meshname2, 1, jn2, desc2, &dom2, maa_dist2); + CPPUNIT_ASSERT_EQUAL(dom1,1); + CPPUNIT_ASSERT_EQUAL(dom2,0); + + + int nbEdgesFamilies1= med_2_3::MEDnFam(fid1, meshname1); + int nbEdgesFamilies2= med_2_3::MEDnFam(fid2, meshname2); + + CPPUNIT_ASSERT_EQUAL(nbEdgesFamilies1,7); // six initial families + a joint + CPPUNIT_ASSERT_EQUAL(nbEdgesFamilies2,7); // six initial families + a joint + + string fam_name = mesh1.getFamily(MED_EN::MED_EDGE,1)->getName(); + char test_name[MED_TAILLE_NOM]="Sortie"; + CPPUNIT_ASSERT(strcmp(fam_name.c_str(),test_name)==0); + +} diff --git a/src/MEDSPLITTER/Test/MEDSPLITTERTest_ParallelTopology.cxx b/src/MEDSPLITTER/Test/MEDSPLITTERTest_ParallelTopology.cxx new file mode 100644 index 000000000..eae90c611 --- /dev/null +++ b/src/MEDSPLITTER/Test/MEDSPLITTERTest_ParallelTopology.cxx @@ -0,0 +1,239 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +#include "MEDSPLITTERTest.hxx" +#include <cppunit/TestAssert.h> + +#include "MEDMEM_ConnectZone.hxx" +#include "MEDMEM_DriversDef.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Meshing.hxx" +#include "MEDMEM_GaussLocalization.hxx" +#include "MEDMEM_Field.hxx" +#include "MEDMEM_CellModel.hxx" +#include "MEDMEM_Group.hxx" + +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_Topology.hxx" +#include "MEDSPLITTER_ParallelTopology.hxx" +#include "MEDSPLITTER_SequentialTopology.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_MESHCollectionDriver.hxx" + +#ifdef ENABLE_METIS +#include "MEDSPLITTER_METISGraph.hxx" +#endif +//#include "MEDSPLITTER_SCOTCHGraph.hxx" + +#include "MEDMEM_Exception.hxx" + +#include <string> + +// use this define to enable lines, execution of which leads to Segmentation Fault +//#define ENABLE_FAULTS + +// use this define to enable CPPUNIT asserts and fails, showing bugs +#define ENABLE_FORCED_FAILURES + + +using namespace std; +using namespace MEDSPLITTER; +using namespace MEDMEM; + +/* + * Check methods defined in ParallelTopology.hxx + * + ParallelTopology(); + ParallelTopology(vector<MEDMEM::MESH*>, vector<MEDMEM::CONNECTZONE*>,vector<int*>&, vector<int*>&, vector<int*>&); + (+) ParallelTopology(boost::shared_ptr<Graph> graph, int nbdomain, int mesh_dimension); + ~ParallelTopology(); + (+) void convertGlobalNodeList(const int*, int,int*,int*); + (+) void convertGlobalNodeList(const int*, int,int*,int); + (+) void convertGlobalNodeListWithTwins(const int* face_list, int nbnode, int*& local, int*& ip, int*& full_array, int& size); + (+) void convertGlobalCellList(const int*, int , int*, int *); + void convertGlobalFaceList(const int*, int , int*, int *); + void convertGlobalFaceList(const int*, int , int*, int); + void convertGlobalFaceListWithTwins(const int* face_list, int nbface, int*& local, int*& ip, int*& full_array,int& size); + void createNodeMapping(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + int idomain); + void createFaceMapping(const MESHCollection &); + void createFaceMapping2ndversion(const MESHCollection &); + void convertToLocal(std::map<MED_EN::medGeometryElement,int*>& type_connectivity, + std::map<MED_EN::medGeometryElement,int>& present_type_numbers, + int idomain, + MED_EN::medEntityMesh entity); + void computeNodeNodeCorrespondencies(int nbdomain,vector<MEDMEM::MEDSKYLINEARRAY*>& ) const; + void computeCellCellCorrespondencies(int nbdomain,vector<MEDMEM::MEDSKYLINEARRAY*>&, const Graph* ) const; + inline int convertNodeToGlobal(int ip,int icell) const + inline int convertFaceToGlobal(int ip,int icell) const + inline int convertCellToGlobal(int ip,int icell) const + inline void convertNodeToGlobal(int ip, const int* local, int n, int* global)const + (+)inline void convertCellToGlobal(int ip, const int* local, int n, int* global)const + inline void convertFaceToGlobal(int ip, const int* local, int n, int* global)const + (+) inline int nbDomain() const + int nbCells() const + (+) inline int nbCells( int idomain) const + (+) inline int getNodeNumber(int idomain) const + inline int getNodeNumber() const + inline void getNodeList(int idomain, int* list) const + (+) inline int getCellNumber(int idomain) const + inline int getCellDomainNumber(int global) const + inline void getCellList(int idomain, int* list) const + inline int getFaceNumber(int idomain) const + inline int getFaceNumber() const + inline void getFaceList(int idomain, int* list) const + boost::shared_ptr<Graph> getGraph() const +*/ + +void MEDSPLITTERTest::testParallelTopology_graph_constructor() +{ +#ifndef ENABLE_METIS + CPPUNIT_FAIL("METIS is not available. Please, check your compilation."); +#else + string data_dir = getenv("DATA_DIR"); + string tmp_dir = getenv("TMP"); + if (tmp_dir == "") + tmp_dir = "/tmp"; + string filename_rd = data_dir + "/MedFiles/carre_en_quad4_import22.med"; + string filename_para_wr = tmp_dir + "/myWrField_seq_pointe22_"; + string filename_para_med0 = tmp_dir + "/myWrField_seq_pointe22_1.med"; + string filename_para_med1 = tmp_dir + "/myWrField_seq_pointe22_2.med"; + + string meshname="carre_en_quad4"; + MESHCollection collection(filename_rd,meshname); + + MEDMEM::MEDSKYLINEARRAY* array=0; + int* edgeweights=0; + + collection.buildCellGraph(array,edgeweights); + + boost::shared_ptr<Graph> cell_graph=boost::shared_ptr<Graph>(new METISGraph(array,edgeweights)); + + cell_graph->partGraph(2,""); + + //cell_graph is a shared pointer + Topology* topology = new ParallelTopology (cell_graph, 2, collection.getMeshDimension()); + + + /* + * test_SPLITTER_square + * + * computes a partitioning for the following geometry + * + * + * + * 7------------8------------9 + * | | | + * | | | + * | 3 | 4 | + * | | | + * | | | + * 4------------5------------6 + * | | | + * | | | + * | 1 | 2 | + * | | | + * | | | + * 1------------2------------3 + * + * Result of the 2 domain split : + * + * 5------------6 5------------6 + * | | | | + * | | | | + * | 2 | | 2 | + * | | | | + * | | | | + * 1------------2 1------------2 + * | | | | + * | | | | + * | 1 | | 1 | + * | | | | + * | | | | + * 4------------3 4------------3 + */ + + int iglobal[3]={1,2,3}; + int* iloc=new int[3]; + int* iproc=new int[3]; + int iloc_answer[3]={1,1,2}; + int iproc_answer[3]={0,1,0}; + topology->convertGlobalCellList(iglobal,3,iloc,iproc); + for(int i=0; i<3; i++) + { + CPPUNIT_ASSERT_EQUAL(iloc_answer[i], iloc[i]); + CPPUNIT_ASSERT_EQUAL(iproc_answer[i],iproc[i]); + } + int* global_2 = new int[3]; + topology->convertCellToGlobal(0,iloc,3,global_2); + int global_answer[3]={1,1,3}; + for (int i=0; i<3; i++) + { + CPPUNIT_ASSERT_EQUAL(global_answer[i],global_2[i]); + } + + CPPUNIT_ASSERT_EQUAL(topology->getCellNumber(0),2); + CPPUNIT_ASSERT_EQUAL(topology->getCellNumber(1),2); + + + CPPUNIT_ASSERT_EQUAL(topology->nbCells(0),2); + CPPUNIT_ASSERT_EQUAL(topology->nbCells(1),2); + + CPPUNIT_ASSERT_EQUAL(topology->nbDomain(),2); + //node and face lists have not yet been computed + CPPUNIT_ASSERT_THROW(topology->convertGlobalNodeList(iglobal,3,iloc,iproc),MEDEXCEPTION); + CPPUNIT_ASSERT_THROW(topology->convertGlobalFaceList(iglobal,3,iloc,iproc),MEDEXCEPTION); + + MESHCollection new_collection(collection, topology); + + CPPUNIT_ASSERT_EQUAL(topology->getNodeNumber(0),6); + CPPUNIT_ASSERT_EQUAL(topology->getNodeNumber(1),6); + + topology->convertGlobalNodeList(iglobal,3,iloc,iproc); + + int iloc_node_answer[3]={4,3,3}; + int iproc_node_answer[3]={0,0,1}; + for(int i=0; i<3; i++) + { + CPPUNIT_ASSERT_EQUAL(iloc_node_answer[i], iloc[i]); + CPPUNIT_ASSERT_EQUAL(iproc_node_answer[i],iproc[i]); + } + int* local_nodes; + int* ip_nodes; + int* full_array; + int size; + topology->convertGlobalNodeListWithTwins(iglobal, 3, local_nodes, ip_nodes, full_array, size); + CPPUNIT_ASSERT_EQUAL(size,4); + int iloc_node_wt_answer[4]={4,3,4,3}; + int iproc_node_wt_answer[4]={0,0,1,1}; + for(int i=0; i<4; i++) + { + CPPUNIT_ASSERT_EQUAL(iloc_node_wt_answer[i], local_nodes[i]); + CPPUNIT_ASSERT_EQUAL(iproc_node_wt_answer[i],ip_nodes[i]); + } + delete topology; + delete[] iloc; + delete[]iproc; + delete[] global_2; + delete[] local_nodes; + delete[] ip_nodes; + delete[] full_array; +#endif // ENABLE_METIS +} diff --git a/src/MEDSPLITTER/Test/Makefile.am b/src/MEDSPLITTER/Test/Makefile.am new file mode 100644 index 000000000..9b4fb93fd --- /dev/null +++ b/src/MEDSPLITTER/Test/Makefile.am @@ -0,0 +1,67 @@ +# SALOMELocalTrace : log on local machine +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES = libMEDSPLITTERTest.la + +dist_libMEDSPLITTERTest_la_SOURCES= \ + MEDSPLITTERTest.cxx \ + MEDSPLITTERTest_MESHCollection.cxx \ + MEDSPLITTERTest_ParallelTopology.cxx + +salomeinclude_HEADERS = MEDSPLITTERTest.hxx + +libMEDSPLITTERTest_la_CPPFLAGS= @CPPUNIT_INCLUDES@ $(MED2_INCLUDES) \ + $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ $(BOOST_CPPFLAGS) $(LIBXML_CXXFLAGS) \ + -I$(srcdir)/.. -I$(srcdir)/../../MEDWrapper/V2_1/Core -I$(srcdir)/../../MEDMEM \ + -I$(srcdir)/../../MEDMEM/Test +libMEDSPLITTERTest_la_LDFLAGS= $(MED2_LIBS) @CPPUNIT_LIBS@ + +if MED_ENABLE_KERNEL + libMEDSPLITTERTest_la_CPPFLAGS+= ${KERNEL_CXXFLAGS} + libMEDSPLITTERTest_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace +endif + +if MED_ENABLE_METIS + libMEDSPLITTERTest_la_CPPFLAGS+= $(METIS_CPPFLAGS) + libMEDSPLITTERTest_la_LDFLAGS+= $(METIS_LIBS) +endif +if MED_ENABLE_SCOTCH + libMEDSPLITTERTest_la_CPPFLAGS+= $(SCOTCH_CPPFLAGS) + libMEDSPLITTERTest_la_LDFLAGS+= $(SCOTCH_LIBS) +endif + +# Executables targets +bin_PROGRAMS= TestMEDSPLITTER + +TestMEDSPLITTER_SOURCES= TestMEDSPLITTER.cxx + +TestMEDSPLITTER_CPPFLAGS= $(libMEDSPLITTERTest_la_CPPFLAGS) +TestMEDSPLITTER_LDADD= $(MED2_LIBS) $(libMEDSPLITTERTest_la_LDFLAGS) -lm \ + libMEDSPLITTERTest.la ../../MEDWrapper/V2_1/Core/libmed_V2_1.la \ + ../../MEDMEM/libmedmem.la ../libmedsplitter.la +if MED_ENABLE_KERNEL + TestMEDSPLITTER_LDADD+= -lSALOMEBasics +endif + +salomescript_DATA = testMEDSPLITTER.py +UNIT_TEST_PROG = TestMEDSPLITTER diff --git a/src/MEDSPLITTER/Test/TestMEDSPLITTER.cxx b/src/MEDSPLITTER/Test/TestMEDSPLITTER.cxx new file mode 100644 index 000000000..b58602cad --- /dev/null +++ b/src/MEDSPLITTER/Test/TestMEDSPLITTER.cxx @@ -0,0 +1,31 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// --- include all MEDMEM Test + +#include "MEDSPLITTERTest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( MEDSPLITTERTest ); + +// --- generic Main program from KERNEL_SRC/src/Basics/Test + +#include "BasicMainTest.hxx" diff --git a/src/MEDSPLITTER/Test/testMEDSPLITTER.py b/src/MEDSPLITTER/Test/testMEDSPLITTER.py new file mode 100644 index 000000000..e3b224781 --- /dev/null +++ b/src/MEDSPLITTER/Test/testMEDSPLITTER.py @@ -0,0 +1,31 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import os + +# execute Unit Test + +command = ['TestMEDSPLITTER'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +print "MEDSPLITTER General testing done." +#print "Run cases, which leads to Segmentation Fault ..." +# +#command = ['MEDMEMTest_Array_fault'] +#ret = os.spawnvp(os.P_WAIT, command[0], command) diff --git a/src/MEDSPLITTER/medsplitter.cxx b/src/MEDSPLITTER/medsplitter.cxx new file mode 100644 index 000000000..a9c080c83 --- /dev/null +++ b/src/MEDSPLITTER/medsplitter.cxx @@ -0,0 +1,312 @@ +// MED medsplitter : tool to split n MED files into p separate +// MED files with a partitioning specified +// by an external tool +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : medsplitter.cxx +// Author : Vincent BERGEAUD (CEA-DEN/DANS/DM2S/SFME/LGLS) +// Module : MED + +#ifdef BOOST_PROGRAM_OPTIONS_LIB +#include <boost/program_options.hpp> +namespace po=boost::program_options; +#endif + +#include <string> +#include <fstream> + +#include "MEDMEM_define.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_Topology.hxx" + +using namespace std; + + + +int main(int argc, char** argv) +{ +#ifndef ENABLE_METIS +#ifndef ENABLE_SCOTCH + cout << "Sorry, no one split method is available. Please, compile with METIS or SCOTCH."<<endl; + return 1; +#endif +#endif + + // Defining options + // by parsing the command line + bool mesh_only = false; + bool is_sequential = true; + bool xml_output_master=true; + bool creates_boundary_faces=false; + bool split_families=false; + bool empty_groups=false; + + string input; + string output; + string meshname; + string library; + int ndomains; + +#ifdef BOOST_PROGRAM_OPTIONS_LIB + + // Use boost::program_options for command-line options parsing + + po::options_description desc("Available options"); + desc.add_options() + ("help","produces this help message") + ("mesh-only","prevents the splitter from creating the fields contained in the original file(s)") + ("distributed","specifies that the input file is distributed") + ("input-file",po::value<string>(),"name of the input MED file") + ("output-file",po::value<string>(),"name of the resulting file") + ("meshname",po::value<string>(),"name of the input mesh") +#ifdef ENABLE_METIS +#ifdef ENABLE_SCOTCH + ("split-method",po::value<string>(&library)->default_value("metis"),"name of the splitting library (metis,scotch)") +#endif +#endif + ("ndomains",po::value<int>(&ndomains)->default_value(1),"number of subdomains in the output file") + ("plain-master","creates a plain masterfile instead of an XML file") + ("creates-boundary-faces","creates the necessary faces so that faces joints are created in the output files") + ("family-splitting","preserves the family names instead of focusing on the groups") + ("empty-groups","creates empty groups in zones that do not contain a group from the original domain"); + + po::variables_map vm; + po::store(po::parse_command_line(argc,argv,desc),vm); + po::notify(vm); + + if (vm.count("help")) + { + cout<<desc<<"\n"; + return 1; + } + + if (!vm.count("ndomains")) + { + cout << "ndomains must be specified !"<<endl; + return 1; + } + + ndomains = vm["ndomains"].as<int>(); + if (!vm.count("input-file") || !vm.count("output-file")) + { + cout << "input-file and output-file names must be specified"<<endl; + return 1; + } + + if (!vm.count("distributed") && !vm.count("meshname") ) + { + cout << "MEDSPLITTER : for a serial MED file, mesh name must be selected with --meshname=..."<<endl; + return 1; + } + + input = vm["input-file"].as<string>(); + output = vm["output-file"].as<string>(); + + if (vm.count("mesh-only")) + mesh_only=true; + + if (vm.count("distributed")) + is_sequential=false; + + if (is_sequential) + meshname = vm["meshname"].as<string>(); + + if (vm.count("plain-master")) + xml_output_master=false; + + if (vm.count("creates-boundary-faces")) + creates_boundary_faces=true; + + if (vm.count("split-families")) + split_families=true; + + if (vm.count("empty-groups")) + empty_groups=true; + +#else // BOOST_PROGRAM_OPTIONS_LIB + + // Primitive parsing of command-line options + + string desc ("Available options:\n" + "\t--help : produces this help message\n" + "\t--mesh-only : do not create the fields contained in the original file(s)\n" + "\t--distributed : specifies that the input file is distributed\n" + "\t--input-file=<string> : name of the input MED file\n" + "\t--output-file=<string> : name of the resulting file\n" + "\t--meshname=<string> : name of the input mesh (not used with --distributed option)\n" + "\t--ndomains=<number> : number of subdomains in the output file, default is 1\n" +#ifdef ENABLE_METIS +#ifdef ENABLE_SCOTCH + "\t--split-method=<string>: name of the splitting library (metis/scotch), default is metis\n" +#endif +#endif + "\t--plain-master : creates a plain masterfile instead of an XML file\n" + "\t--creates-boundary-faces: creates the necessary faces so that faces joints are created in the output files\n" + "\t--family-splitting : preserves the family names instead of focusing on the groups\n" + ); + + if (argc < 4) { + cout << desc.c_str() << endl; + return 1; + } + + for (int i = 1; i < argc; i++) { + if (strlen(argv[i]) < 3) { + cout << desc.c_str() << endl; + return 1; + } + + if (strncmp(argv[i],"--m",3) == 0) { + if (strcmp(argv[i],"--mesh-only") == 0) { + mesh_only = true; + cout << "\tmesh-only = " << mesh_only << endl; // tmp + } + else if (strlen(argv[i]) > 11) { // "--meshname=" + meshname = (argv[i] + 11); + cout << "\tmeshname = " << meshname << endl; // tmp + } + } + else if (strncmp(argv[i],"--d",3) == 0) { + is_sequential = false; + cout << "\tis_sequential = " << is_sequential << endl; // tmp + } + else if (strncmp(argv[i],"--i",3) == 0) { + if (strlen(argv[i]) > 13) { // "--input-file=" + input = (argv[i] + 13); + cout << "\tinput-file = " << input << endl; // tmp + } + } + else if (strncmp(argv[i],"--o",3) == 0) { + if (strlen(argv[i]) > 14) { // "--output-file=" + output = (argv[i] + 14); + cout << "\toutput-file = " << output << endl; // tmp + } + } + else if (strncmp(argv[i],"--s",3) == 0) { + if (strlen(argv[i]) > 15) { // "--split-method=" + library = (argv[i] + 15); + cout << "\tsplit-method = " << library << endl; // tmp + } + } + else if (strncmp(argv[i],"--f",3) == 0) { //"--family-splitting" + split_families=true; + cout << "\tfamily-splitting true" << endl; // tmp + } + else if (strncmp(argv[i],"--n",3) == 0) { + if (strlen(argv[i]) > 11) { // "--ndomains=" + ndomains = atoi(argv[i] + 11); + cout << "\tndomains = " << ndomains << endl; // tmp + } + } + else if (strncmp(argv[i],"--p",3) == 0) { // "--plain-master" + xml_output_master = false; + cout << "\txml_output_master = " << xml_output_master << endl; // tmp + } + else if (strncmp(argv[i],"--c",3) == 0) { // "--creates-boundary-faces" + creates_boundary_faces = true; + cout << "\tcreates_boundary_faces = " << creates_boundary_faces << endl; // tmp + } + else if (strncmp(argv[i],"--e",3) == 0) { // "--empty-groups" + empty_groups = true; + cout << "\tempty_groups = true" << endl; // tmp + } + else { + cout << desc.c_str() << endl; + return 1; + } + } + + if (is_sequential && meshname.empty()) { + cout << "Mesh name must be given for sequential(not distributed) input file." << endl; + cout << desc << endl; + return 1; + } + +#endif // BOOST_PROGRAM_OPTIONS_LIB + + + //testing whether it is possible to write a file at the specified location + string outputtest = output + ".testioms."; + ofstream testfile (outputtest.c_str()); + if (testfile.fail()) + { + cout << "MEDSPLITTER : output-file directory does not exist or is in read-only access" << endl; + return 1; + }; + //deletes test file + remove(outputtest.c_str()); + + // Beginning of the computation + + // Loading the mesh collection + MEDSPLITTER::MESHCollection* collection; + cout << "MEDSPLITTER - reading input files "<<endl; + if (is_sequential) + collection = new MEDSPLITTER::MESHCollection(input,meshname); + else + collection = new MEDSPLITTER::MESHCollection(input); + + cout << "MEDSPLITTER - computing partition "<<endl; + + // Creating the graph and partitioning it +#ifdef ENABLE_METIS +#ifndef ENABLE_SCOTCH + library = "metis"; +#endif +#else + library = "scotch"; +#endif + cout << "\tsplit-method = " << library << endl; // tmp + + MEDSPLITTER::Topology* new_topo; + if (library == "metis") + new_topo = collection->createPartition(ndomains,MEDSPLITTER::Graph::METIS); + else + new_topo = collection->createPartition(ndomains,MEDSPLITTER::Graph::SCOTCH); + + cout << "MEDSPLITTER - creating new meshes"<<endl; + + // Creating a new mesh collection from the partitioning + MEDSPLITTER::MESHCollection new_collection(*collection, new_topo, split_families, empty_groups); + if (!xml_output_master) + new_collection.setDriverType(MEDSPLITTER::MedAscii); + + new_collection.setSubdomainBoundaryCreates(creates_boundary_faces); + + cout << "MEDSPLITTER - writing output files "<<endl; + new_collection.write(output); + + // Casting the fields on the new collection + if (!mesh_only) + new_collection.castAllFields(*collection); + + + // Cleaning memory + delete collection; + delete new_topo; + + return 0; +} diff --git a/src/MEDSPLITTER/test_HighLevelAPI.cxx b/src/MEDSPLITTER/test_HighLevelAPI.cxx new file mode 100644 index 000000000..e9265c033 --- /dev/null +++ b/src/MEDSPLITTER/test_HighLevelAPI.cxx @@ -0,0 +1,24 @@ +#include "MEDSPLITTER_API.hxx" +#include <string> + +using namespace std; +int main() +{ + string testname="MEDSPLITTER - test #3 -"; + + char filename[100] = "../../share/salome/resources/med/carre_en_quad4_import22.med"; + char meshname[20] = "carre_en_quad4"; + char output[100]="./tests/API_test"; + int is_distributed=0; + int nprocs=4; + int meshonly=0; + int method=0; + return medsplitter(filename, + meshname, + output, + is_distributed, + nprocs, + method, + meshonly); +} + diff --git a/src/MEDWrapper/Base/MED_Algorithm.cxx b/src/MEDWrapper/Base/MED_Algorithm.cxx index 3b110be71..2ecf0ca18 100644 --- a/src/MEDWrapper/Base/MED_Algorithm.cxx +++ b/src/MEDWrapper/Base/MED_Algorithm.cxx @@ -198,7 +198,7 @@ namespace MED MSG(MYDEBUG,"GetFamiliesByEntity(...)"); TEntity2FamilySet anEntity2FamilySet; - typedef map<TInt,PFamilyInfo> TId2Family; + typedef std::map<TInt,PFamilyInfo> TId2Family; TId2Family anId2Family; TFamilyInfoSet::const_iterator anIter = theFamilyInfoSet.begin(); for(; anIter != theFamilyInfoSet.end(); anIter++){ @@ -208,7 +208,7 @@ namespace MED if(!anId2Family.empty()){ typedef std::map<TInt,TInt> TFamilyID2Size; - typedef map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID; + typedef std::map<EEntiteMaillage,TFamilyID2Size> TEntity2FamilyID; TEntity2FamilyID anEntity2FamilyID; if(!theEntity2TGeom2ElemInfo.empty()){ @@ -262,7 +262,7 @@ namespace MED TErr* theErr, EModeSwitch theMode) { - INITMSG(MYDEBUG,"GetKey2Gauss - theMode = "<<theMode<<endl); + INITMSG(MYDEBUG,"GetKey2Gauss - theMode = "<<theMode<<std::endl); TKey2Gauss aKey2Gauss; TInt aNbGauss = theWrapper->GetNbGauss(theErr); for(TInt anId = 1; anId <= aNbGauss; anId++){ @@ -278,7 +278,7 @@ namespace MED INITMSG(MYDEBUG, "- aGeom = "<<aGeom<< "; aName = '"<<aName<<"'"<< - endl); + std::endl); #endif } @@ -311,7 +311,7 @@ namespace MED TErr* theErr, EModeProfil theMode) { - INITMSG(MYDEBUG,"GetMKey2Profile - theMode = "<<theMode<<endl); + INITMSG(MYDEBUG,"GetMKey2Profile - theMode = "<<theMode<<std::endl); TKey2Profile aKey2Profile; TInt aNbProfiles = theWrapper->GetNbProfiles(theErr); for(TInt anId = 1; anId <= aNbProfiles; anId++){ @@ -324,16 +324,44 @@ namespace MED INITMSG(MYDEBUG, "- aName = '"<<aName<<"'"<< " : "<< - endl); - TInt aNbElem = anInfo->myElemNum.size(); + std::endl); + TInt aNbElem = anInfo->GetSize(); for(TInt iElem = 0; iElem < aNbElem; iElem++){ ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", "); } - ADDMSG(MYVALUEDEBUG,endl); + ADDMSG(MYVALUEDEBUG, std::endl); #endif } return TMKey2Profile(theMode,aKey2Profile); } + //--------------------------------------------------------------- + EEntiteMaillage + GetEntityByFamilyId(PGrilleInfo& theInfo,TInt theId){ + TElemNum::iterator aNodeFamIter = (theInfo->myFamNumNode).begin(); + for(;aNodeFamIter != (theInfo->myFamNumNode).end(); aNodeFamIter++){ + if(theId == *aNodeFamIter) + return eNOEUD; + } + TElemNum::iterator aCellFamIter = (theInfo->myFamNum).begin(); + for(;aCellFamIter != (theInfo->myFamNum).end(); aCellFamIter++){ + if(theId == *aCellFamIter) + return eMAILLE; + } + EXCEPTION(std::runtime_error, "GetEntityByFamilyId - fails"); + return EEntiteMaillage(-1); + } + + TFamilyID2NbCells + GetFamilyID2NbCells(PGrilleInfo& theInfo){ + TFamilyID2NbCells aFamily2NbCells; + TInt aNbNodes = theInfo->myFamNumNode.size(); + TInt aNbCells = theInfo->myFamNum.size(); + for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] = 0; + for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] = 0; + for(TInt i=0; i<aNbNodes; i++) aFamily2NbCells[theInfo->GetFamNumNode(i)] += 1; + for(TInt i=0; i<aNbCells; i++) aFamily2NbCells[theInfo->GetFamNum(i)] += 1; + return aFamily2NbCells; + } } diff --git a/src/MEDWrapper/Base/MED_Algorithm.hxx b/src/MEDWrapper/Base/MED_Algorithm.hxx index 278a6562e..3e6e44ac9 100644 --- a/src/MEDWrapper/Base/MED_Algorithm.hxx +++ b/src/MEDWrapper/Base/MED_Algorithm.hxx @@ -29,6 +29,7 @@ #ifndef MED_Algorithm_HeaderFile #define MED_Algorithm_HeaderFile +#include "MED_WrapperBase.hxx" #include "MED_Structures.hxx" #include <set> @@ -40,6 +41,7 @@ namespace MED typedef std::map<EEntiteMaillage,TGeom2ElemInfo> TEntity2TGeom2ElemInfo; //! Get set of TElemInfo by its geometrical type and corresponding MED ENTITY + MEDWRAPPER_EXPORT TEntity2TGeom2ElemInfo GetEntity2TGeom2ElemInfo(const PWrapper& theWrapper, const PMeshInfo& theMeshInfo, @@ -50,6 +52,7 @@ namespace MED typedef std::set<PFamilyInfo> TFamilyInfoSet; //! Read set of MED FAMILIES for defined MED file + MEDWRAPPER_EXPORT TFamilyInfoSet GetFamilyInfoSet(const PWrapper& theWrapper, const PMeshInfo& theMeshInfo); @@ -67,7 +70,8 @@ namespace MED typedef std::map<EEntiteMaillage,TFamilyTSizeSet> TEntity2FamilySet; //! Split set of MED FAMILIES by corresponding MED ENTITY - TEntity2FamilySet + MEDWRAPPER_EXPORT + TEntity2FamilySet GetEntity2FamilySet(const PWrapper& theWrapper, const TEntity2TGeom2ElemInfo& theEntity2TGeom2ElemInfo, const TFamilyInfoSet& theFamilyInfoSet); @@ -77,6 +81,7 @@ namespace MED typedef std::map<std::string,TFamilyInfoSet> TGroupInfo; //! Split the input set of MED FAMILIES by corresponding MED GROUPS + MEDWRAPPER_EXPORT TGroupInfo GetGroupInfo(const TFamilyInfoSet& theFamilyInfoSet); @@ -86,6 +91,7 @@ namespace MED typedef std::map<PFieldInfo,TTimeStampInfoSet> TFieldInfo2TimeStampInfoSet; //! Read set of MED TIMESTAMPS groupped by corresponding MED FIELDS + MEDWRAPPER_EXPORT TFieldInfo2TimeStampInfoSet GetFieldInfo2TimeStampInfoSet(const PWrapper& theWrapper, const PMeshInfo& theMeshInfo, @@ -96,6 +102,7 @@ namespace MED typedef std::map<EEntiteMaillage,TFieldInfo2TimeStampInfoSet> TEntite2TFieldInfo2TimeStampInfoSet; //! Split the input set of MED TIMESTAMPS by corresponding MED FIELDS and MED ENTITIES + MEDWRAPPER_EXPORT TEntite2TFieldInfo2TimeStampInfoSet GetEntite2TFieldInfo2TimeStampInfoSet(const TFieldInfo2TimeStampInfoSet& theFieldInfo2TimeStampInfoSet); @@ -104,6 +111,7 @@ namespace MED typedef std::map<TGaussInfo::TKey,PGaussInfo,TGaussInfo::TLess> TKey2Gauss; //! Read set of MED GAUSS + MEDWRAPPER_EXPORT TKey2Gauss GetKey2Gauss(const PWrapper& theWrapper, TErr* theErr = NULL, @@ -112,6 +120,7 @@ namespace MED //--------------------------------------------------------------- //! Get MED PROFILE by its name + MEDWRAPPER_EXPORT PProfileInfo GetProfileInfo(const PWrapper& theWrapper, const std::string& theProfileName, @@ -124,10 +133,26 @@ namespace MED typedef boost::tuple<EModeProfil,TKey2Profile> TMKey2Profile; //! Read set of MED PROFILES + MEDWRAPPER_EXPORT TMKey2Profile GetMKey2Profile(const PWrapper& theWrapper, TErr* theErr = NULL, EModeProfil theMode = eCOMPACT); + + //--------------------------------------------------------------- + //! Get Entity for Grille by family id. + MEDWRAPPER_EXPORT + EEntiteMaillage + GetEntityByFamilyId(PGrilleInfo& theInfo, + TInt theId); + + typedef std::map<TInt,TInt> TFamilyID2NbCells; + + //! Get Number of cells for theId family, for Grille + MEDWRAPPER_EXPORT + TFamilyID2NbCells + GetFamilyID2NbCells(PGrilleInfo& theInfo); + } #endif diff --git a/src/MEDWrapper/Base/MED_Common.hxx b/src/MEDWrapper/Base/MED_Common.hxx index 428de374c..2e7b8e174 100644 --- a/src/MEDWrapper/Base/MED_Common.hxx +++ b/src/MEDWrapper/Base/MED_Common.hxx @@ -29,6 +29,8 @@ #ifndef MED_Common_HeaderFile #define MED_Common_HeaderFile +#include "MED_WrapperBase.hxx" + #include <string> #include <set> #include <map> @@ -52,12 +54,11 @@ namespace MED{ typedef enum {eFAUX, eVRAI} EBooleen ; typedef double TFloat; -#if defined(SUN4SOL2) || defined(PCLINUX) || defined(OSF1_32) || defined(IRIX64_32) || defined(RS6000) || defined(HP9000) - typedef int TInt; -#endif -#if defined(IRIX64) || defined(OSF1) +#if defined(HAVE_F77INT64) typedef long TInt; -#endif +#else + typedef int TInt; +#endif typedef hid_t TIdt; typedef herr_t TErr; @@ -81,9 +82,9 @@ namespace MED{ typedef enum {eNO_PFLMOD, eGLOBAL, eCOMPACT} EModeProfil; - typedef enum {eGRILLE_CARTESIENNE,eGRILLE_POLAIRE,eGRILLE_STANDARD} EGrilleType; + typedef enum {eGRILLE_CARTESIENNE, eGRILLE_POLAIRE, eGRILLE_STANDARD} EGrilleType; - typedef enum {eCOOR, eCONN, eNOM, eNUM, eFAM,eCOOR_IND1,eCOOR_IND2,eCOOR_IND3} ETable; + typedef enum {eCOOR, eCONN, eNOM, eNUM, eFAM, eCOOR_IND1, eCOOR_IND2, eCOOR_IND3} ETable; typedef TVector<TFloat> TFloatVector; typedef TVector<std::string> TStringVector; @@ -96,6 +97,7 @@ namespace MED{ typedef std::set<EGeometrieElement> TGeomSet; typedef std::map<EEntiteMaillage,TGeomSet> TEntity2GeomSet; + MEDWRAPPER_EXPORT const TEntity2GeomSet& GetEntity2GeomSet(); @@ -116,15 +118,21 @@ namespace MED{ GetLNOMLength(); template<EVersion> - TInt + TInt MEDWRAPPER_EXPORT GetPNOMLength(); template<EVersion> + void MEDWRAPPER_EXPORT + GetVersionRelease(TInt& majeur, TInt& mineur, TInt& release); + + template<EVersion> + MEDWRAPPER_EXPORT TInt GetNbConn(EGeometrieElement typmai, EEntiteMaillage typent, TInt mdim); + MEDWRAPPER_EXPORT TInt GetNbNodes(EGeometrieElement typmai); @@ -167,10 +175,10 @@ namespace MED{ class TGrilleInfo; typedef SharedPtr<TGrilleInfo> PGrilleInfo; - struct TTimeStampVal; - typedef SharedPtr<TTimeStampVal> PTimeStampVal; + struct TTimeStampValueBase; + typedef SharedPtr<TTimeStampValueBase> PTimeStampValueBase; - class TWrapper; + struct TWrapper; typedef SharedPtr<TWrapper> PWrapper; }; diff --git a/src/MEDWrapper/Base/MED_CoordUtils.cxx b/src/MEDWrapper/Base/MED_CoordUtils.cxx index 7ab59a631..72247833d 100644 --- a/src/MEDWrapper/Base/MED_CoordUtils.cxx +++ b/src/MEDWrapper/Base/MED_CoordUtils.cxx @@ -124,15 +124,19 @@ namespace MED TInt aMeshDimension = aMeshInfo->GetDim(); bool anIsDimPresent[3] = {false, false, false}; for(int iDim = 0; iDim < aMeshDimension; iDim++){ - std::string aName = theNodeInfo->GetCoordName(iDim); - if ( aName.size() > 1 ) // PAL12148, aName has size 8 or 16 - aName = aName.substr(0,1); - if(aName == "x" || aName == "X") - anIsDimPresent[eX] = true; - else if(aName == "y" || aName == "Y") - anIsDimPresent[eY] = true; - else if(aName == "z" || aName == "Z") - anIsDimPresent[eZ] = true; + // PAL16857(SMESH not conform to the MED convention) -> + // 1D - always along X + // 2D - always in XOY plane + anIsDimPresent[iDim] = iDim < aMeshDimension; +// std::string aName = theNodeInfo->GetCoordName(iDim); +// if ( aName.size() > 1 ) // PAL12148, aName has size 8 or 16 +// aName = aName.substr(0,1); +// if(aName == "x" || aName == "X") +// anIsDimPresent[eX] = true; +// else if(aName == "y" || aName == "Y") +// anIsDimPresent[eY] = true; +// else if(aName == "z" || aName == "Z") +// anIsDimPresent[eZ] = true; } switch(aMeshDimension){ diff --git a/src/MEDWrapper/Base/MED_CoordUtils.hxx b/src/MEDWrapper/Base/MED_CoordUtils.hxx index 614ae9b1c..6c875e374 100644 --- a/src/MEDWrapper/Base/MED_CoordUtils.hxx +++ b/src/MEDWrapper/Base/MED_CoordUtils.hxx @@ -29,6 +29,8 @@ #ifndef MED_CoordUtils_HeaderFile #define MED_CoordUtils_HeaderFile +#include "MED_WrapperBase.hxx" + #include "MED_Structures.hxx" namespace MED @@ -37,7 +39,7 @@ namespace MED //--------------------------------------------------------------- - class TCoordHelper + class MEDWRAPPER_EXPORT TCoordHelper { TGetCoord* myGetCoord; @@ -52,6 +54,7 @@ namespace MED //--------------------------------------------------------------- + MEDWRAPPER_EXPORT PCoordHelper GetCoordHelper(PNodeInfo theNodeInfo); diff --git a/src/MEDWrapper/Base/MED_GaussDef.cxx b/src/MEDWrapper/Base/MED_GaussDef.cxx new file mode 100644 index 000000000..1b51cb60c --- /dev/null +++ b/src/MEDWrapper/Base/MED_GaussDef.cxx @@ -0,0 +1,577 @@ +// +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : MED_GaussDef.hxx +// Module : MED +// Author : Edward AGAPOV (eap) +// $Header: + +#include "MED_GaussDef.hxx" +#include "MED_Utilities.hxx" +#include "MED_GaussUtils.hxx" + +namespace MED +{ + using namespace std; + using namespace MED; + //--------------------------------------------------------------- + + void TGaussDef::add(const double x, const double weight) + { + if ( dim() != 1 ) + EXCEPTION( logic_error,"dim() != 1"); + if ( myWeights.capacity() == myWeights.size() ) + EXCEPTION( logic_error,"Extra gauss point"); + myCoords.push_back( x ); + myWeights.push_back( weight ); + } + void TGaussDef::add(const double x, const double y, const double weight) + { + if ( dim() != 2 ) + EXCEPTION( logic_error,"dim() != 2"); + if ( myWeights.capacity() == myWeights.size() ) + EXCEPTION( logic_error,"Extra gauss point"); + myCoords.push_back( x ); + myCoords.push_back( y ); + myWeights.push_back( weight ); + } + void TGaussDef::add(const double x, const double y, const double z, const double weight) + { + if ( dim() != 3 ) + EXCEPTION( logic_error,"dim() != 3"); + if ( myWeights.capacity() == myWeights.size() ) + EXCEPTION( logic_error,"Extra gauss point"); + myCoords.push_back( x ); + myCoords.push_back( y ); + myCoords.push_back( z ); + myWeights.push_back( weight ); + } + void TGaussDef::setRefCoords(const TShapeFun& aShapeFun) + { + myRefCoords.reserve( aShapeFun.myRefCoord.size() ); + myRefCoords.assign( aShapeFun.myRefCoord.begin(), + aShapeFun.myRefCoord.end() ); + } + + + //--------------------------------------------------------------- + /*! + * \brief Fill definition of gauss points family + */ + //--------------------------------------------------------------- + + TGaussDef::TGaussDef(const int geom, const int nbGauss, const int variant) + { + myType = geom; + myCoords .reserve( nbGauss * dim() ); + myWeights.reserve( nbGauss ); + + switch ( geom ) { + + case eSEG2: + case eSEG3: + if (geom == eSEG2) setRefCoords( TSeg2a() ); + else setRefCoords( TSeg3a() ); + switch ( nbGauss ) { + case 1: { + add( 0.0, 2.0 ); break; + } + case 2: { + const double a = 0.577350269189626; + add( a, 1.0 ); + add( -a, 1.0 ); break; + } + case 3: { + const double a = 0.774596669241; + const double P1 = 1./1.8; + const double P2 = 1./1.125; + add( -a, P1 ); + add( 0, P2 ); + add( a, P1 ); break; + } + case 4: { + const double a = 0.339981043584856, b = 0.861136311594053; + const double P1 = 0.652145154862546, P2 = 0.347854845137454 ; + add( a, P1 ); + add( -a, P1 ); + add( b, P2 ); + add( -b, P2 ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for SEG"<<nbGauss); + } + break; + + case eTRIA3: + case eTRIA6: + if ( variant == 1 ) { + if (geom == eTRIA3) setRefCoords( TTria3b() ); + else setRefCoords( TTria6b() ); + switch ( nbGauss ) { + case 1: { // FPG1 + add( 1/3., 1/3., 1/2. ); break; + } + case 3: { // FPG3 + // what about COT3 ??? + add( 1/6., 1/6., 1/6. ); + add( 2/3., 1/6., 1/6. ); + add( 1/6., 2/3., 1/6. ); break; + } + case 4: { // FPG4 + add( 1/5., 1/5., 25/(24*4.) ); + add( 3/5., 1/5., 25/(24*4.) ); + add( 1/5., 3/5., 25/(24*4.) ); + add( 1/3., 1/3., -27/(24*4.) ); break; + } + case 6: { // FPG6 + const double P1 = 0.11169079483905, P2 = 0.0549758718227661; + const double a = 0.445948490915965, b = 0.091576213509771; + add( b, b, P2 ); + add( 1-2*b, b, P2 ); + add( b, 1-2*b, P2 ); + add( a, 1-2*a, P1 ); + add( a, a, P1 ); + add( 1-2*a, a, P1 ); break; + } + case 7: { // FPG7 + const double A = 0.470142064105115; + const double B = 0.101286507323456; + const double P1 = 0.066197076394253; + const double P2 = 0.062969590272413; + add( 1/3., 1/3., 9/80. ); + add( A, A, P1 ); + add( 1-2*A, A, P1 ); + add( A, 1-2*A, P1 ); + add( B, B, P2 ); + add( 1-2*B, B, P2 ); + add( B, 1-2*B, P2 ); break; + } + case 12: { // FPG12 + const double A = 0.063089014491502; + const double B = 0.249286745170910; + const double C = 0.310352451033785; + const double D = 0.053145049844816; + const double P1 = 0.025422453185103; + const double P2 = 0.058393137863189; + const double P3 = 0.041425537809187; + add( A, A, P1 ); + add( 1-2*A, A, P1 ); + add( A, 1-2*A, P1 ); + add( B, B, P2 ); + add( 1-2*B, B, P2 ); + add( B, 1-2*B, P2 ); + add( C, D, P3 ); + add( D, C, P3 ); + add( 1-C-D, C, P3 ); + add( 1-C-D, D, P3 ); + add( C, 1-C-D, P3 ); + add( D, 1-C-D, P3 ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for TRIA, variant 1: " + <<nbGauss); + } + } + else if ( variant == 2 ) { + if (geom == eTRIA3) setRefCoords( TTria3a() ); + else setRefCoords( TTria6a() ); + switch ( nbGauss ) { + case 1: { + add( -1/3., -1/3., 2. ); break; + } + case 3: { + add( -2/3., 1/3., 2/3. ); + add( -2/3., -2/3., 2/3. ); + add( 1/3., -2/3., 2/3. ); break; + } + case 6: { + const double P1 = 0.11169079483905, P2 = 0.0549758718227661; + const double A = 0.445948490915965, B = 0.091576213509771; + add( 2*B-1, 1-4*B, 4*P2 ); + add( 2*B-1, 2*B-1, 4*P2 ); + add( 1-4*B, 2*B-1, 4*P2 ); + add( 1-4*A, 2*A-1, 4*P1 ); + add( 2*A-1, 1-4*A, 4*P1 ); + add( 2*A-1, 2*A-1, 4*P1 ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for TRIA, variant 2: " + <<nbGauss); + } + } + else if ( variant == 3 ) { + if (geom == eTRIA3) setRefCoords( TTria3b() ); + else setRefCoords( TTria6b() ); + switch ( nbGauss ) { + case 4: { + add( 1/3., 1/3., -27/96 ); + add( 0.2 , 0.2 , 25/96 ); + add( 0.6 , 0.2 , 25/96 ); + add( 0.2 , 0.6 , 25/96 ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for TRIA, variant 3: " + <<nbGauss); + } + } + break; + + case eQUAD4: + case eQUAD8: + if ( variant == 1 ) { + if (geom == eQUAD4) setRefCoords( TQuad4b() ); + else setRefCoords( TQuad8b() ); + switch ( nbGauss ) { + case 1: { // FPG1 + add( 0, 0, 4 ); break; + } + case 4: { // FPG4 + const double a = 1/sqrt(3.); + add( -a, -a, 1 ); + add( a, -a, 1 ); + add( a, a, 1 ); + add( -a, a, 1 ); break; + } + case 9: { // FPG9 + const double a = 0.774596669241483; + add( -a, -a, 25/81. ); + add( a, -a, 25/81. ); + add( a, a, 25/81. ); + add( -a, a, 25/81. ); + add( 0., -a, 40/81. ); + add( a, 0., 40/81. ); + add( 0., a, 40/81. ); + add( -a, 0., 40/81. ); + add( 0., 0., 64/81. ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for QUAD, variant 1: " + <<nbGauss); + } + } + else if ( variant == 2 ) { + if (geom == eQUAD4) setRefCoords( TQuad4a() ); + else setRefCoords( TQuad8a() ); + switch ( nbGauss ) { + case 4: { + const double a = 1/sqrt(3.); + add( -a, a, 1 ); + add( -a, -a, 1 ); + add( a, -a, 1 ); + add( a, a, 1 ); break; + } + case 9: { + const double a = 0.774596669241483; + add( -a, a, 25/81. ); + add( -a, -a, 25/81. ); + add( a, -a, 25/81. ); + add( a, a, 25/81. ); + add( -a, 0., 40/81. ); + add( 0., -a, 40/81. ); + add( a, 0., 40/81. ); + add( 0., a, 40/81. ); + add( 0., 0., 64/81. ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for QUAD, variant 1: " + <<nbGauss); + } + } + else if ( variant == 3 ) { + if (geom == eQUAD4) setRefCoords( TQuad4b() ); + else setRefCoords( TQuad8b() ); + switch ( nbGauss ) { + case 4: { + const double a = 3/sqrt(3.); + add( -a, -a, 1 ); + add( -a, a, 1 ); + add( a, -a, 1 ); + add( a, a, 1 ); break; + } + case 9: { + const double a = sqrt(3/5.), c1 = 5/9., c2 = 8/9.; + const double c12 = c1*c2, c22 = c2*c2, c1c2 = c1*c2; + add( -a, -a, c12 ); + add( -a, 0., c1c2 ); + add( -a, a, c12 ); + add( 0., -a, c1c2 ); + add( 0., 0., c22 ); + add( 0., a, c1c2 ); + add( a, -a, c12 ); + add( a, 0., c1c2 ); + add( a, a, c12 ); break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for QUAD, variant 3: " + <<nbGauss); + } + } + break; + + case eTETRA4: + case eTETRA10: + if (geom == eTETRA4) setRefCoords( TTetra4a() ); + else setRefCoords( TTetra10a() ); + switch ( nbGauss ) { + case 4: { // FPG4 + const double a = (5 - sqrt(5.))/20., b = (5 + 3*sqrt(5.))/20.; + add( a, a, a, 1/24. ); + add( a, a, b, 1/24. ); + add( a, b, a, 1/24. ); + add( b, a, a, 1/24. ); break; + } + case 5: { // FPG5 + const double a = 0.25, b = 1/6., c = 0.5; + add( a, a, a, -2/15. ); + add( b, b, b, 3/40. ); + add( b, b, c, 3/40. ); + add( b, c, b, 3/40. ); + add( c, b, b, 3/40. ); break; + } + case 15: { // FPG15 + const double a = 0.25; + const double b1 = (7 + sqrt(15.))/34., c1 = (13 + 3*sqrt(15.))/34., d = (5 - sqrt(15.))/20.; + const double b2 = (7 - sqrt(15.))/34., c2 = (13 - 3*sqrt(15.))/34., e = (5 + sqrt(15.))/20.; + const double P1 = (2665 - 14*sqrt(15.))/226800.; + const double P2 = (2665 + 14*sqrt(15.))/226800.; + add( a, a, a, 8/405.);//_____ + add( b1, b1, b1, P1 ); + add( b1, b1, c1, P1 ); + add( b1, c1, b1, P1 ); + add( c1, b1, b1, P1 );//_____ + add( b2, b2, b2, P2 ); + add( b2, b2, c2, P2 ); + add( b2, c2, b2, P2 ); + add( c2, b2, b2, P2 );//_____ + add( d, d, e, 5/567.); + add( d, e, d, 5/567.); + add( e, d, d, 5/567.); + add( d, e, e, 5/567.); + add( e, d, e, 5/567.); + add( e, e, d, 5/567.); + break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for TETRA: "<<nbGauss); + } + break; + + case ePYRA5: + case ePYRA13: + if (geom == ePYRA5) setRefCoords( TPyra5a() ); + else setRefCoords( TPyra13a() ); + switch ( nbGauss ) { + case 5: { // FPG5 + const double h1 = 0.1531754163448146; + const double h2 = 0.6372983346207416; + add( .5, 0., h1, 2/15. ); + add( 0., .5, h1, 2/15. ); + add( -.5, 0., h1, 2/15. ); + add( 0., -.5, h1, 2/15. ); + add( 0., 0., h2, 2/15. ); break; + } + case 6: { // FPG6 + const double p1 = 0.1024890634400000 ; + const double p2 = 0.1100000000000000 ; + const double p3 = 0.1467104129066667 ; + const double a = 0.5702963741068025 ; + const double h1 = 0.1666666666666666 ; + const double h2 = 0.08063183038464675; + const double h3 = 0.6098484849057127 ; + add( a, 0., h1, p1 ); + add( 0., a, h1, p1 ); + add( -a, 0., h1, p1 ); + add( 0., -a, h1, p1 ); + add( 0., 0., h2, p2 ); + add( 0., 0., h3, p3 ); break; + } + case 27: { // FPG27 + const double a1 = 0.788073483; + const double b6 = 0.499369002; + const double b1 = 0.848418011; + const double c8 = 0.478508449; + const double c1 = 0.652816472; + const double d12 = 0.032303742; + const double d1 = 1.106412899; + double z = 1/2., fz = b1/2*(1 - z); + add( 0., 0., z, a1 ); // 1 + add( fz, fz, z, b6 ); // 2 + add( -fz, fz, z, b6 ); // 3 + add( -fz, -fz, z, b6 ); // 4 + add( fz, -fz, z, b6 ); // 5 + z = (1 - b1)/2.; + add( 0., 0., z, b6 ); // 6 + z = (1 + b1)/2.; + add( 0., 0., z, b6 ); // 7 + z = (1 - c1)/2.; fz = c1*(1 - z); + add( fz, 0., z, c8 ); // 8 + add( 0., fz, z, c8 ); // 9 + add( -fz, 0., z, c8 ); // 10 + add( 0., -fz, z, c8 ); // 11 + z = (1 + c1)/2.; fz = c1*(1 - z); + add( fz, 0., z, c8 ); // 12 + add( 0., fz, z, c8 ); // 13 + add( -fz, 0., z, c8 ); // 14 + add( 0., -fz, z, c8 ); // 15 + z = (1 - d1)/2., fz = d1/2*(1 - z); + add( fz, fz, z, d12); // 16 + add( -fz, fz, z, d12); // 17 + add( -fz, -fz, z, d12); // 18 + add( fz, -fz, z, d12); // 19 + z = 1/2.; fz = d1*(1 - z); + add( fz, 0., z, d12); // 20 + add( 0., fz, z, d12); // 21 + add( -fz, 0., z, d12); // 22 + add( 0., -fz, z, d12); // 23 + z = (1 + d1)/2., fz = d1/2*(1 - z); + add( fz, fz, z, d12); // 24 + add( -fz, fz, z, d12); // 25 + add( -fz, -fz, z, d12); // 26 + add( fz, -fz, z, d12); // 27 + break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for PYRA: "<<nbGauss); + } + break; + case ePENTA6: + case ePENTA15: + if (geom == ePENTA6) setRefCoords( TPenta6a() ); + else setRefCoords( TPenta15a() ); + switch ( nbGauss ) { + case 6: { // FPG6 + const double a = sqrt(3.)/3.; + add( -a, .5, .5, 1/6. ); + add( -a, 0., .5, 1/6. ); + add( -a, .5, 0., 1/6. ); + add( a, .5, .5, 1/6. ); + add( a, 0., .5, 1/6. ); + add( a, .5, 0., 1/6. ); break; + } + case 8: { // FPG8 + const double a = 0.577350269189626; + add( -a, 1/3., 1/3., -27/96. ); + add( -a, 0.6, 0.2, 25/96. ); + add( -a, 0.2, 0.6, 25/96. ); + add( -a, 0.2, 0.2, 25/96. ); + add( +a, 1/3., 1/3., -27/96. ); + add( +a, 0.6, 0.2, 25/96. ); + add( +a, 0.2, 0.6, 25/96. ); + add( +a, 0.2, 0.2, 25/96. ); break; + } + case 21: { // FPG21 + const double d = sqrt(3/5.), c1 = 5/9., c2 = 8/9.; // d <=> alfa + const double a = (6 + sqrt(15.))/21.; + const double b = (6 - sqrt(15.))/21.; + const double P1 = (155 + sqrt(15.))/2400.; + const double P2 = (155 - sqrt(15.))/2400.; //___ + add( -d, 1/3., 1/3., c1*9/80. );//___ + add( -d, a, a, c1*P1 ); + add( -d, 1-2*a, a, c1*P1 ); + add( -d, a, 1-2*a, c1*P1 );//___ + add( -d, b, b, c1*P2 ); + add( -d, 1-2*b, b, c1*P2 ); + add( -d, b, 1-2*b, c1*P2 );//___ + add( 0., 1/3., 1/3., c2*9/80. );//___ + add( 0., a, a, c2*P1 ); + add( 0., 1-2*a, a, c2*P1 ); + add( 0., a, 1-2*a, c2*P1 );//___ + add( 0., b, b, c2*P2 ); + add( 0., 1-2*b, b, c2*P2 ); + add( 0., b, 1-2*b, c2*P2 );//___ + add( d, 1/3., 1/3., c1*9/80. );//___ + add( d, a, a, c1*P1 ); + add( d, 1-2*a, a, c1*P1 ); + add( d, a, 1-2*a, c1*P1 );//___ + add( d, b, b, c1*P2 ); + add( d, 1-2*b, b, c1*P2 ); + add( d, b, 1-2*b, c1*P2 );//___ + break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for PENTA: " <<nbGauss); + } + break; + + case eHEXA8: + case eHEXA20: + if (geom == eHEXA8) setRefCoords( THexa8a() ); + else setRefCoords( THexa20a() ); + switch ( nbGauss ) { + case 8: { // FPG8 + const double a = sqrt(3.)/3.; + add( -a, -a, -a, 1. ); + add( -a, -a, a, 1. ); + add( -a, a, -a, 1. ); + add( -a, a, a, 1. ); + add( a, -a, -a, 1. ); + add( a, -a, a, 1. ); + add( a, a, -a, 1. ); + add( a, a, a, 1. ); break; + } + case 27: { // FPG27 + const double a = sqrt(3/5.), c1 = 5/9., c2 = 8/9.; + const double c12 = c1*c1, c13 = c1*c1*c1; + const double c22 = c2*c2, c23 = c2*c2*c2; + add( -a, -a, -a, c13 ); // 1 + add( -a, -a, 0., c12*c2 ); // 2 + add( -a, -a, a, c13 ); // 3 + add( -a, 0., -a, c12*c2 ); // 4 + add( -a, 0., 0., c1*c22 ); // 5 + add( -a, 0., a, c12*c2 ); // 6 + add( -a, a, -a, c13 ); // 7 + add( -a, a, 0., c12*c2 ); // 8 + add( -a, a, a, c13 ); // 9 + add( 0., -a, -a, c12*c2 ); // 10 + add( 0., -a, 0., c1*c22 ); // 11 + add( 0., -a, a, c12*c2 ); // 12 + add( 0., 0., -a, c1*c22 ); // 13 + add( 0., 0., 0., c23 ); // 14 + add( 0., 0., a, c1*c22 ); // 15 + add( 0., a, -a, c12*c2 ); // 16 + add( 0., a, 0., c1*c22 ); // 17 + add( 0., a, a, c12*c2 ); // 18 + add( a, -a, -a, c13 ); // 19 + add( a, -a, 0., c12*c2 ); // 20 + add( a, -a, a, c13 ); // 21 + add( a, 0., -a, c12*c2 ); // 22 + add( a, 0., 0., c1*c22 ); // 23 + add( a, 0., a, c12*c2 ); // 24 + add( a, a, -a, c13 ); // 25 + add( a, a, 0., c12*c2 ); // 26 + add( a, a, a, c13 ); // 27 + break; + } + default: + EXCEPTION( logic_error,"Invalid nb of gauss points for PENTA: " <<nbGauss); + } + break; + + default: + EXCEPTION( logic_error,"unexpected EGeometrieElement: "<< geom); + } + + if ( myWeights.capacity() != myWeights.size() ) + EXCEPTION( logic_error,"Not all gauss points defined"); + } +} diff --git a/src/MEDWrapper/Base/MED_GaussDef.hxx b/src/MEDWrapper/Base/MED_GaussDef.hxx new file mode 100644 index 000000000..4e0d1ab36 --- /dev/null +++ b/src/MEDWrapper/Base/MED_GaussDef.hxx @@ -0,0 +1,76 @@ +// +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : MED_GaussDef.hxx +// Module : MED +// Author : Edward AGAPOV (eap) +// $Header: + +#ifndef MED_GaussDef_HeaderFile +#define MED_GaussDef_HeaderFile + +#include "MED_WrapperBase.hxx" + +//#include "MED_GaussUtils.hxx" <<<---- avoid dependence on boost +#include <vector> + +namespace MED +{ + class TShapeFun; + typedef std::vector<double> TDoubleVector; + /*! + * \brief Description of family of integration points + */ + struct MEDWRAPPER_EXPORT TGaussDef + { + int myType; //!< element geometry (EGeometrieElement or med_geometrie_element) + TDoubleVector myRefCoords; //!< description of reference points + TDoubleVector myCoords; //!< coordinates of Gauss points + TDoubleVector myWeights; //!< weights, len(weights)==<nb of gauss points> + + /*! + * \brief Creates definition of gauss points family + * \param geomType - element geometry (EGeometrieElement or med_geometrie_element) + * \param nbPoints - nb gauss point + * \param variant - [1-3] to choose the variant of definition + * + * Throws in case of invalid parameters + * variant == 1 refers to "Fonctions de forme et points d'integration + * des elements finis" v7.4 by J. PELLET, X. DESROCHES, 15/09/05 + * variant == 2 refers to the same doc v6.4 by J.P. LEFEBVRE, X. DESROCHES, 03/07/03 + * variant == 3 refers to the same doc v6.4, second variant for 2D elements + */ + TGaussDef(const int geomType, const int nbPoints, const int variant=1); + + int dim() const { return myType/100; } + int nbPoints() const { return myWeights.capacity(); } + + private: + void add(const double x, const double weight); + void add(const double x, const double y, const double weight); + void add(const double x, const double y, const double z, const double weight); + void setRefCoords(const TShapeFun& aShapeFun); + }; +} + +#endif diff --git a/src/MEDWrapper/Base/MED_GaussUtils.cxx b/src/MEDWrapper/Base/MED_GaussUtils.cxx index 0e7a7cfcb..87550c06e 100644 --- a/src/MEDWrapper/Base/MED_GaussUtils.cxx +++ b/src/MEDWrapper/Base/MED_GaussUtils.cxx @@ -71,6 +71,35 @@ namespace MED } + TInt + TGaussCoord + ::GetNbElem() const + { + return myNbElem; + } + + TInt + TGaussCoord + ::GetNbGauss() const + { + return myNbGauss; + } + + TInt + TGaussCoord + ::GetDim() const + { + return myDim; + } + + unsigned char* + TGaussCoord + ::GetValuePtr() + { + return (unsigned char*)&(myGaussCoord[0]); + } + + TCCoordSliceArr TGaussCoord ::GetCoordSliceArr(TInt theElemId) const @@ -129,1615 +158,1517 @@ namespace MED } - struct TShapeFun + //--------------------------------------------------------------- + class TShapeFun::TFun { - class TFun - { - TFloatVector myFun; - TInt myNbRef; - - public: - - void - Init(TInt theNbGauss, - TInt theNbRef) - { - myFun.resize(theNbGauss*theNbRef); - myNbRef = theNbRef; - } - - TCFloatVecSlice - GetFunSlice(TInt theGaussId) const - { - return TCFloatVecSlice(myFun,std::slice(theGaussId*myNbRef,myNbRef,1)); - } - - TFloatVecSlice - GetFunSlice(TInt theGaussId) - { - return TFloatVecSlice(myFun,std::slice(theGaussId*myNbRef,myNbRef,1)); - } - }; - - typedef TVector<TCCoordSlice> TCCoordSliceArr; - typedef TVector<TCoordSlice> TCoordSliceArr; - - TFloatVector myRefCoord; - TInt myDim; + TFloatVector myFun; TInt myNbRef; - TShapeFun(TInt theDim = 0, TInt theNbRef = 0): - myDim(theDim), - myNbRef(theNbRef), - myRefCoord(theNbRef*theDim) - {} + public: - TInt - GetNbRef() const + void + Init(TInt theNbGauss, + TInt theNbRef) { - return myNbRef; + myFun.resize(theNbGauss*theNbRef); + myNbRef = theNbRef; } - TCCoordSlice - GetCoord(TInt theRefId) const - { - return TCCoordSlice(myRefCoord,std::slice(theRefId*myDim,myDim,1)); - } - - TCoordSlice - GetCoord(TInt theRefId) + TCFloatVecSlice + GetFunSlice(TInt theGaussId) const { - return TCoordSlice(myRefCoord,std::slice(theRefId*myDim,myDim,1)); + return TCFloatVecSlice(myFun,std::slice(theGaussId*myNbRef,myNbRef,1)); } - - void - GetFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const + + TFloatVecSlice + GetFunSlice(TInt theGaussId) { - TInt aNbRef = theRef.size(); - TInt aNbGauss = theGauss.size(); - theFun.Init(aNbGauss,aNbRef); + return TFloatVecSlice(myFun,std::slice(theGaussId*myNbRef,myNbRef,1)); } + }; - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const = 0; - - virtual - bool - IsSatisfy(const TShapeFun::TCCoordSliceArr& theRefCoord) const - { - TInt aNbRef = theRefCoord.size(); - TInt aNbRef2 = GetNbRef(); - INITMSG(MYDEBUG,"TShapeFun::IsSatisfy "<< - "- aNbRef("<<aNbRef<<")"<< - "; aNbRef2("<<aNbRef2<<")\n"); - bool anIsSatisfy = (aNbRef == aNbRef2); - if(anIsSatisfy){ - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - const TCCoordSlice& aCoord2 = theRefCoord[aRefId]; - TCCoordSlice aCoord = GetCoord(aRefId); - TInt aDim = aCoord.size(); - bool anIsEqual = false; - for(TInt anId = 0; anId < aDim; anId++){ - anIsEqual = IsEqual(aCoord[anId],aCoord2[anId]); - if(!anIsEqual){ - anIsSatisfy = false; - break; - } - } - if(!anIsEqual){ - TCCoordSlice aCoord = GetCoord(aRefId); - INITMSG(MYDEBUG,aRefId + 1<<": aCoord = {"); - TInt aDim = aCoord.size(); - for(TInt anId = 0; anId < aDim; anId++) - ADDMSG(MYDEBUG,"\t"<<aCoord[anId]); - const TCCoordSlice& aCoord2 = theRefCoord[aRefId]; - ADDMSG(MYDEBUG,"}\t!=\taCoord2 = {"); - for(TInt anId = 0; anId < aDim; anId++) - ADDMSG(MYDEBUG,"\t"<<aCoord2[anId]); - ADDMSG(MYDEBUG,"}\n"); + //--------------------------------------------------------------- + + TShapeFun::TShapeFun(TInt theDim, TInt theNbRef): + myDim(theDim), + myNbRef(theNbRef), + myRefCoord(theNbRef*theDim) + {} + + TCCoordSlice + TShapeFun::GetCoord(TInt theRefId) const + { + return TCCoordSlice(myRefCoord,std::slice(theRefId*myDim,myDim,1)); + } + + TCoordSlice + TShapeFun::GetCoord(TInt theRefId) + { + return TCoordSlice(myRefCoord,std::slice(theRefId*myDim,myDim,1)); + } + + void + TShapeFun::GetFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + TInt aNbRef = theRef.size(); + TInt aNbGauss = theGauss.size(); + theFun.Init(aNbGauss,aNbRef); + } + + bool + TShapeFun::IsSatisfy(const TCCoordSliceArr& theRefCoord) const + { + TInt aNbRef = theRefCoord.size(); + TInt aNbRef2 = GetNbRef(); + INITMSG(MYDEBUG,"TShapeFun::IsSatisfy "<< + "- aNbRef("<<aNbRef<<")"<< + "; aNbRef2("<<aNbRef2<<")\n"); + bool anIsSatisfy = (aNbRef == aNbRef2); + if(anIsSatisfy){ + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + const TCCoordSlice& aCoord2 = theRefCoord[aRefId]; + TCCoordSlice aCoord = GetCoord(aRefId); + TInt aDim = aCoord.size(); + bool anIsEqual = false; + for(TInt anId = 0; anId < aDim; anId++){ + anIsEqual = IsEqual(aCoord[anId],aCoord2[anId]); + if(!anIsEqual){ + anIsSatisfy = false; + break; + } + } + if(!anIsEqual){ + TCCoordSlice aCoord = GetCoord(aRefId); + INITMSG(MYDEBUG,aRefId + 1<<": aCoord = {"); + TInt aDim = aCoord.size(); + for(TInt anId = 0; anId < aDim; anId++) + ADDMSG(MYDEBUG,"\t"<<aCoord[anId]); + const TCCoordSlice& aCoord2 = theRefCoord[aRefId]; + ADDMSG(MYDEBUG,"}\t!=\taCoord2 = {"); + for(TInt anId = 0; anId < aDim; anId++) + ADDMSG(MYDEBUG,"\t"<<aCoord2[anId]); + ADDMSG(MYDEBUG,"}\n"); #ifndef _DEBUG_ - return anIsSatisfy; + BEGMSG(MYDEBUG,"anIsSatisfy = "<<anIsSatisfy<<"\n"); + return anIsSatisfy; #endif - } - } + } } - - return anIsSatisfy; } - bool - Eval(const TCellInfo& theCellInfo, - const TNodeInfo& theNodeInfo, - const TElemNum& theElemNum, - const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TGaussCoord& theGaussCoord, - EModeSwitch theMode) - { - INITMSG(MYDEBUG,"TShapeFun::Eval"<<endl); - - if(IsSatisfy(theRef)){ - const PMeshInfo& aMeshInfo = theCellInfo.GetMeshInfo(); - TInt aDim = aMeshInfo->GetDim(); - TInt aNbGauss = theGauss.size(); - - bool anIsSubMesh = !theElemNum.empty(); - TInt aNbElem; - if(anIsSubMesh) - aNbElem = theElemNum.size(); - else - aNbElem = theCellInfo.GetNbElem(); - - theGaussCoord.Init(aNbElem,aNbGauss,aDim,theMode); - - TFun aFun; - InitFun(theRef,theGauss,aFun); - TInt aConnDim = theCellInfo.GetConnDim(); - - INITMSG(MYDEBUG,"aDim = "<<aDim<< - "; aNbGauss = "<<aNbGauss<< - "; aNbElem = "<<aNbElem<< - "; aNbNodes = "<<theNodeInfo.GetNbElem()<< - endl); - - for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ - TInt aCellId = anIsSubMesh? theElemNum[anElemId]-1: anElemId; - TCConnSlice aConnSlice = theCellInfo.GetConnSlice(aCellId); - TCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); - - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - TCoordSlice& aGaussCoordSlice = aCoordSliceArr[aGaussId]; - TCFloatVecSlice aFunSlice = aFun.GetFunSlice(aGaussId); - - for(TInt aConnId = 0; aConnId < aConnDim; aConnId++){ - TInt aNodeId = aConnSlice[aConnId] - 1; - TCCoordSlice aNodeCoordSlice = theNodeInfo.GetCoordSlice(aNodeId); - - for(TInt aDimId = 0; aDimId < aDim; aDimId++){ - aGaussCoordSlice[aDimId] += aNodeCoordSlice[aDimId]*aFunSlice[aConnId]; - } - } - } - } + BEGMSG(MYDEBUG,"anIsSatisfy = "<<anIsSatisfy<<"\n"); + return anIsSatisfy; + } -#ifdef _DEBUG_ - { - INITMSG(MYVALUEDEBUG,"theGauss: "); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - TCCoordSlice aCoordSlice = theGauss[aGaussId]; - ADDMSG(MYVALUEDEBUG,"{"); - for(TInt aDimId = 0; aDimId < aDim; aDimId++){ - ADDMSG(MYVALUEDEBUG,aCoordSlice[aDimId]<<" "); - } - ADDMSG(MYVALUEDEBUG,"} "); - } - ADDMSG(MYVALUEDEBUG,endl); - } - for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ - TCCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); - INITMSG(MYVALUEDEBUG,""); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - TCCoordSlice aCoordSlice = aCoordSliceArr[aGaussId]; - ADDMSG(MYVALUEDEBUG,"{"); - for(TInt aDimId = 0; aDimId < aDim; aDimId++){ - ADDMSG(MYVALUEDEBUG,aCoordSlice[aDimId]<<" "); - } - ADDMSG(MYVALUEDEBUG,"} "); - } - ADDMSG(MYVALUEDEBUG,endl); - } -#endif - return true; + bool + TShapeFun::Eval(const TCellInfo& theCellInfo, + const TNodeInfo& theNodeInfo, + const TElemNum& theElemNum, + const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TGaussCoord& theGaussCoord, + EModeSwitch theMode) + { + INITMSG(MYDEBUG,"TShapeFun::Eval"<<std::endl); + + if(IsSatisfy(theRef)){ + const PMeshInfo& aMeshInfo = theCellInfo.GetMeshInfo(); + TInt aDim = aMeshInfo->GetDim(); + TInt aNbGauss = theGauss.size(); + + bool anIsSubMesh = !theElemNum.empty(); + TInt aNbElem; + if(anIsSubMesh) + aNbElem = theElemNum.size(); + else + aNbElem = theCellInfo.GetNbElem(); + + theGaussCoord.Init(aNbElem,aNbGauss,aDim,theMode); + + TFun aFun; + InitFun(theRef,theGauss,aFun); + TInt aConnDim = theCellInfo.GetConnDim(); + + INITMSG(MYDEBUG,"aDim = "<<aDim<< + "; aNbGauss = "<<aNbGauss<< + "; aNbElem = "<<aNbElem<< + "; aNbNodes = "<<theNodeInfo.GetNbElem()<< + std::endl); + + for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ + TInt aCellId = anIsSubMesh? theElemNum[anElemId]-1: anElemId; + TCConnSlice aConnSlice = theCellInfo.GetConnSlice(aCellId); + TCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); + + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + TCoordSlice& aGaussCoordSlice = aCoordSliceArr[aGaussId]; + TCFloatVecSlice aFunSlice = aFun.GetFunSlice(aGaussId); + + for(TInt aConnId = 0; aConnId < aConnDim; aConnId++){ + TInt aNodeId = aConnSlice[aConnId] - 1; + TCCoordSlice aNodeCoordSlice = theNodeInfo.GetCoordSlice(aNodeId); + + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ + aGaussCoordSlice[aDimId] += aNodeCoordSlice[aDimId]*aFunSlice[aConnId]; + } + } + } } - return false; +#ifdef _DEBUG_ + { + INITMSG(MYVALUEDEBUG,"theGauss: "); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + TCCoordSlice aCoordSlice = theGauss[aGaussId]; + ADDMSG(MYVALUEDEBUG,"{"); + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ + ADDMSG(MYVALUEDEBUG,aCoordSlice[aDimId]<<" "); + } + ADDMSG(MYVALUEDEBUG,"} "); + } + ADDMSG(MYVALUEDEBUG,std::endl); + } + for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ + TCCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); + INITMSG(MYVALUEDEBUG,""); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + TCCoordSlice aCoordSlice = aCoordSliceArr[aGaussId]; + ADDMSG(MYVALUEDEBUG,"{"); + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ + ADDMSG(MYVALUEDEBUG,aCoordSlice[aDimId]<<" "); + } + ADDMSG(MYVALUEDEBUG,"} "); + } + ADDMSG(MYVALUEDEBUG,std::endl); + } +#endif + return true; } - }; + + return false; + } //--------------------------------------------------------------- - struct TSeg2a: TShapeFun + TSeg2a::TSeg2a():TShapeFun(1,2) { - TSeg2a(): - TShapeFun(1,2) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; break; - case 1: aCoord[0] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; break; + case 1: aCoord[0] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TSeg2a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.5*(1.0 - aCoord[0]); - aSlice[1] = 0.5*(1.0 + aCoord[0]); - } + aSlice[0] = 0.5*(1.0 - aCoord[0]); + aSlice[1] = 0.5*(1.0 + aCoord[0]); } - }; + } //--------------------------------------------------------------- - struct TSeg3a: TShapeFun + TSeg3a::TSeg3a():TShapeFun(1,3) { - TSeg3a(): - TShapeFun(1,3) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; break; - case 1: aCoord[0] = 1.0; break; - case 2: aCoord[0] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; break; + case 1: aCoord[0] = 1.0; break; + case 2: aCoord[0] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TSeg3a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.5*(1.0 - aCoord[0])*aCoord[0]; - aSlice[1] = 0.5*(1.0 + aCoord[0])*aCoord[0]; - aSlice[2] = (1.0 + aCoord[0])*(1.0 - aCoord[0]); - } + aSlice[0] = 0.5*(1.0 - aCoord[0])*aCoord[0]; + aSlice[1] = 0.5*(1.0 + aCoord[0])*aCoord[0]; + aSlice[2] = (1.0 + aCoord[0])*(1.0 - aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TTria3a: TShapeFun + TTria3a::TTria3a(): + TShapeFun(2,3) { - TTria3a(): - TShapeFun(2,3) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTria3a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.5*(1.0 + aCoord[1]); - aSlice[1] = -0.5*(aCoord[0] + aCoord[1]); - aSlice[2] = 0.5*(1.0 + aCoord[0]); - } + aSlice[0] = 0.5*(1.0 + aCoord[1]); + aSlice[1] = -0.5*(aCoord[0] + aCoord[1]); + aSlice[2] = 0.5*(1.0 + aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TTria6a: TShapeFun + TTria6a::TTria6a():TShapeFun(2,6) { - TTria6a(): - TShapeFun(2,6) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; - - case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - case 4: aCoord[0] = 0.0; aCoord[1] = -1.0; break; - case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; + + case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break; + case 4: aCoord[0] = 0.0; aCoord[1] = -1.0; break; + case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTria6a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.5*(1.0 + aCoord[1])*aCoord[1]; - aSlice[1] = 0.5*(aCoord[0] + aCoord[1])*(aCoord[0] + aCoord[1] + 1); - aSlice[2] = 0.5*(1.0 + aCoord[0])*aCoord[0]; - - aSlice[3] = -1.0*(1.0 + aCoord[1])*(aCoord[0] + aCoord[1]); - aSlice[4] = -1.0*(1.0 + aCoord[0])*(aCoord[0] + aCoord[1]); - aSlice[5] = (1.0 + aCoord[1])*(1.0 + aCoord[1]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.5*(1.0 + aCoord[1])*aCoord[1]; + aSlice[1] = 0.5*(aCoord[0] + aCoord[1])*(aCoord[0] + aCoord[1] + 1); + aSlice[2] = 0.5*(1.0 + aCoord[0])*aCoord[0]; + + aSlice[3] = -1.0*(1.0 + aCoord[1])*(aCoord[0] + aCoord[1]); + aSlice[4] = -1.0*(1.0 + aCoord[0])*(aCoord[0] + aCoord[1]); + aSlice[5] = (1.0 + aCoord[1])*(1.0 + aCoord[1]); } - }; + } + //--------------------------------------------------------------- - struct TTria3b: TShapeFun + TTria3b::TTria3b(): + TShapeFun(2,3) { - TTria3b(): - TShapeFun(2,3) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 0.0; aCoord[1] = 0.0; break; - case 1: aCoord[0] = 1.0; aCoord[1] = 0.0; break; - case 2: aCoord[0] = 0.0; aCoord[1] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 0.0; aCoord[1] = 0.0; break; + case 1: aCoord[0] = 1.0; aCoord[1] = 0.0; break; + case 2: aCoord[0] = 0.0; aCoord[1] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTria3b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 1.0 - aCoord[0] - aCoord[1]; - aSlice[1] = aCoord[0]; - aSlice[2] = aCoord[1]; - } + aSlice[0] = 1.0 - aCoord[0] - aCoord[1]; + aSlice[1] = aCoord[0]; + aSlice[2] = aCoord[1]; } - }; + } + //--------------------------------------------------------------- - struct TTria6b: TShapeFun + TTria6b::TTria6b(): + TShapeFun(2,6) { - TTria6b(): - TShapeFun(2,6) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 0.0; aCoord[1] = 0.0; break; - case 1: aCoord[0] = 1.0; aCoord[1] = 0.0; break; - case 2: aCoord[0] = 0.0; aCoord[1] = 1.0; break; - - case 3: aCoord[0] = 0.5; aCoord[1] = 0.0; break; - case 4: aCoord[0] = 0.5; aCoord[1] = 0.5; break; - case 5: aCoord[0] = 0.0; aCoord[1] = 0.5; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 0.0; aCoord[1] = 0.0; break; + case 1: aCoord[0] = 1.0; aCoord[1] = 0.0; break; + case 2: aCoord[0] = 0.0; aCoord[1] = 1.0; break; + + case 3: aCoord[0] = 0.5; aCoord[1] = 0.0; break; + case 4: aCoord[0] = 0.5; aCoord[1] = 0.5; break; + case 5: aCoord[0] = 0.0; aCoord[1] = 0.5; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTria6b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = (1.0 - aCoord[0] - aCoord[1])*(1.0 - 2.0*aCoord[0] - 2.0*aCoord[1]); - aSlice[1] = aCoord[0]*(2.0*aCoord[0] - 1.0); - aSlice[2] = aCoord[1]*(2.0*aCoord[1] - 1.0); - - aSlice[3] = 4.0*aCoord[0]*(1.0 - aCoord[0] - aCoord[1]); - aSlice[4] = 4.0*aCoord[0]*aCoord[1]; - aSlice[5] = 4.0*aCoord[1]*(1.0 - aCoord[0] - aCoord[1]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = (1.0 - aCoord[0] - aCoord[1])*(1.0 - 2.0*aCoord[0] - 2.0*aCoord[1]); + aSlice[1] = aCoord[0]*(2.0*aCoord[0] - 1.0); + aSlice[2] = aCoord[1]*(2.0*aCoord[1] - 1.0); + + aSlice[3] = 4.0*aCoord[0]*(1.0 - aCoord[0] - aCoord[1]); + aSlice[4] = 4.0*aCoord[0]*aCoord[1]; + aSlice[5] = 4.0*aCoord[1]*(1.0 - aCoord[0] - aCoord[1]); } - }; + } + //--------------------------------------------------------------- - struct TQuad4a: TShapeFun + TQuad4a::TQuad4a(): + TShapeFun(2,4) { - TQuad4a(): - TShapeFun(2,4) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TQuad4a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.25*(1.0 + aCoord[1])*(1.0 - aCoord[0]); - aSlice[1] = 0.25*(1.0 - aCoord[1])*(1.0 - aCoord[0]); - aSlice[2] = 0.25*(1.0 - aCoord[1])*(1.0 + aCoord[0]); - aSlice[3] = 0.25*(1.0 + aCoord[0])*(1.0 + aCoord[1]); - } + aSlice[0] = 0.25*(1.0 + aCoord[1])*(1.0 - aCoord[0]); + aSlice[1] = 0.25*(1.0 - aCoord[1])*(1.0 - aCoord[0]); + aSlice[2] = 0.25*(1.0 - aCoord[1])*(1.0 + aCoord[0]); + aSlice[3] = 0.25*(1.0 + aCoord[0])*(1.0 + aCoord[1]); } - }; + } + //--------------------------------------------------------------- - struct TQuad8a: TShapeFun + TQuad8a::TQuad8a(): + TShapeFun(2,8) { - TQuad8a(): - TShapeFun(2,8) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; break; - - case 4: aCoord[0] = -1.0; aCoord[1] = 0.0; break; - case 5: aCoord[0] = 0.0; aCoord[1] = -1.0; break; - case 6: aCoord[0] = 1.0; aCoord[1] = 0.0; break; - case 7: aCoord[0] = 0.0; aCoord[1] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = -1.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; break; + + case 4: aCoord[0] = -1.0; aCoord[1] = 0.0; break; + case 5: aCoord[0] = 0.0; aCoord[1] = -1.0; break; + case 6: aCoord[0] = 1.0; aCoord[1] = 0.0; break; + case 7: aCoord[0] = 0.0; aCoord[1] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TQuad8a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.25*(1.0 + aCoord[1])*(1.0 - aCoord[0])*(aCoord[1] - aCoord[0] - 1.0); - aSlice[1] = 0.25*(1.0 - aCoord[1])*(1.0 - aCoord[0])*(-aCoord[1] - aCoord[0] - 1.0); - aSlice[2] = 0.25*(1.0 - aCoord[1])*(1.0 + aCoord[0])*(-aCoord[1] + aCoord[0] - 1.0); - aSlice[3] = 0.25*(1.0 + aCoord[1])*(1.0 + aCoord[0])*(aCoord[1] + aCoord[0] - 1.0); - - aSlice[4] = 0.5*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[1]); - aSlice[5] = 0.5*(1.0 - aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[0]); - aSlice[6] = 0.5*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[1]); - aSlice[7] = 0.5*(1.0 + aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[0]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.25*(1.0 + aCoord[1])*(1.0 - aCoord[0])*(aCoord[1] - aCoord[0] - 1.0); + aSlice[1] = 0.25*(1.0 - aCoord[1])*(1.0 - aCoord[0])*(-aCoord[1] - aCoord[0] - 1.0); + aSlice[2] = 0.25*(1.0 - aCoord[1])*(1.0 + aCoord[0])*(-aCoord[1] + aCoord[0] - 1.0); + aSlice[3] = 0.25*(1.0 + aCoord[1])*(1.0 + aCoord[0])*(aCoord[1] + aCoord[0] - 1.0); + + aSlice[4] = 0.5*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[1]); + aSlice[5] = 0.5*(1.0 - aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[0]); + aSlice[6] = 0.5*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[1]); + aSlice[7] = 0.5*(1.0 + aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TQuad4b: TShapeFun + TQuad4b::TQuad4b(): + TShapeFun(2,4) { - TQuad4b(): - TShapeFun(2,4) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; break; - case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; break; - case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; break; + case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; break; + case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TQuad4b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.25*(1.0 - aCoord[0])*(1.0 - aCoord[1]); - aSlice[1] = 0.25*(1.0 + aCoord[0])*(1.0 - aCoord[1]); - aSlice[2] = 0.25*(1.0 + aCoord[0])*(1.0 + aCoord[1]); - aSlice[3] = 0.25*(1.0 - aCoord[0])*(1.0 + aCoord[1]); - } + aSlice[0] = 0.25*(1.0 - aCoord[0])*(1.0 - aCoord[1]); + aSlice[1] = 0.25*(1.0 + aCoord[0])*(1.0 - aCoord[1]); + aSlice[2] = 0.25*(1.0 + aCoord[0])*(1.0 + aCoord[1]); + aSlice[3] = 0.25*(1.0 - aCoord[0])*(1.0 + aCoord[1]); } - }; + } + //--------------------------------------------------------------- - struct TQuad8b: TShapeFun + TQuad8b::TQuad8b(): + TShapeFun(2,8) { - TQuad8b(): - TShapeFun(2,8) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; break; - case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; break; - case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break; - - case 4: aCoord[0] = 0.0; aCoord[1] = -1.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; break; - case 6: aCoord[0] = 0.0; aCoord[1] = 1.0; break; - case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; break; + case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; break; + case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; break; + + case 4: aCoord[0] = 0.0; aCoord[1] = -1.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; break; + case 6: aCoord[0] = 0.0; aCoord[1] = 1.0; break; + case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TQuad8b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.25*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(-1.0 - aCoord[0] - aCoord[1]); - aSlice[1] = 0.25*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(-1.0 + aCoord[0] - aCoord[1]); - aSlice[2] = 0.25*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(-1.0 + aCoord[0] + aCoord[1]); - aSlice[3] = 0.25*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(-1.0 - aCoord[0] + aCoord[1]); - - aSlice[4] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]); - aSlice[5] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0]); - aSlice[6] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1]); - aSlice[7] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.25*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(-1.0 - aCoord[0] - aCoord[1]); + aSlice[1] = 0.25*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(-1.0 + aCoord[0] - aCoord[1]); + aSlice[2] = 0.25*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(-1.0 + aCoord[0] + aCoord[1]); + aSlice[3] = 0.25*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(-1.0 - aCoord[0] + aCoord[1]); + + aSlice[4] = 0.5*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]); + aSlice[5] = 0.5*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0]); + aSlice[6] = 0.5*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1]); + aSlice[7] = 0.5*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0]); + + //aSlice[4] = 0.5*(1.0 - aCoord[0])*(1.0 - aCoord[0])*(1.0 - aCoord[1]); + //aSlice[5] = 0.5*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[1]); + //aSlice[6] = 0.5*(1.0 - aCoord[0])*(1.0 - aCoord[0])*(1.0 + aCoord[1]); + //aSlice[7] = 0.5*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[1]); } - }; + } + //--------------------------------------------------------------- - struct TTetra4a: TShapeFun + TTetra4a::TTetra4a(): + TShapeFun(3,4) { - TTetra4a(): - TShapeFun(3,4) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTetra4a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = aCoord[1]; - aSlice[1] = aCoord[2]; - aSlice[2] = 1.0 - aCoord[0] - aCoord[1] - aCoord[2]; - aSlice[3] = aCoord[0]; - } + aSlice[0] = aCoord[1]; + aSlice[1] = aCoord[2]; + aSlice[2] = 1.0 - aCoord[0] - aCoord[1] - aCoord[2]; + aSlice[3] = aCoord[0]; } - }; + } + //--------------------------------------------------------------- - struct TTetra10a: TShapeFun + TTetra10a::TTetra10a(): + TShapeFun(3,10) { - TTetra10a(): - TShapeFun(3,10) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - - case 4: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 6: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - - case 7: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 8: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + + case 4: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 6: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + + case 7: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 8: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTetra10a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = aCoord[1]*(2.0*aCoord[1] - 1.0); - aSlice[1] = aCoord[2]*(2.0*aCoord[2] - 1.0); - aSlice[2] = (1.0 - aCoord[0] - aCoord[1] - aCoord[2])*(1.0 - 2.0*aCoord[0] - 2.0*aCoord[1] - 2.0*aCoord[2]); - aSlice[3] = aCoord[0]*(2.0*aCoord[0] - 1.0); + aSlice[0] = aCoord[1]*(2.0*aCoord[1] - 1.0); + aSlice[1] = aCoord[2]*(2.0*aCoord[2] - 1.0); + aSlice[2] = (1.0 - aCoord[0] - aCoord[1] - aCoord[2])*(1.0 - 2.0*aCoord[0] - 2.0*aCoord[1] - 2.0*aCoord[2]); + aSlice[3] = aCoord[0]*(2.0*aCoord[0] - 1.0); - aSlice[4] = 4.0*aCoord[1]*aCoord[2]; - aSlice[5] = 4.0*aCoord[2]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[6] = 4.0*aCoord[1]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[4] = 4.0*aCoord[1]*aCoord[2]; + aSlice[5] = 4.0*aCoord[2]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[6] = 4.0*aCoord[1]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[7] = 4.0*aCoord[0]*aCoord[1]; - aSlice[8] = 4.0*aCoord[0]*aCoord[2]; - aSlice[9] = 4.0*aCoord[0]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); - } + aSlice[7] = 4.0*aCoord[0]*aCoord[1]; + aSlice[8] = 4.0*aCoord[0]*aCoord[2]; + aSlice[9] = 4.0*aCoord[0]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); } - }; + } + //--------------------------------------------------------------- - struct TTetra4b: TShapeFun + TTetra4b::TTetra4b(): + TShapeFun(3,4) { - TTetra4b(): - TShapeFun(3,4) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTetra4b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = aCoord[1]; - aSlice[2] = aCoord[2]; - aSlice[1] = 1.0 - aCoord[0] - aCoord[1] - aCoord[2]; - aSlice[3] = aCoord[0]; - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = aCoord[1]; + aSlice[2] = aCoord[2]; + aSlice[1] = 1.0 - aCoord[0] - aCoord[1] - aCoord[2]; + aSlice[3] = aCoord[0]; } - }; + } + //--------------------------------------------------------------- - struct TTetra10b: TShapeFun + TTetra10b::TTetra10b(): + TShapeFun(3,10) { - TTetra10b(): - TShapeFun(3,10) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - - case 6: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 4: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - - case 7: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 8: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + + case 6: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 5: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 4: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + + case 7: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 8: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TTetra10b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = aCoord[1]*(2.0*aCoord[1] - 1.0); - aSlice[2] = aCoord[2]*(2.0*aCoord[2] - 1.0); - aSlice[1] = (1.0 - aCoord[0] - aCoord[1] - aCoord[2])*(1.0 - 2.0*aCoord[0] - 2.0*aCoord[1] - 2.0*aCoord[2]); - aSlice[3] = aCoord[0]*(2.0*aCoord[0] - 1.0); - - aSlice[6] = 4.0*aCoord[1]*aCoord[2]; - aSlice[5] = 4.0*aCoord[2]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[4] = 4.0*aCoord[1]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); - - aSlice[7] = 4.0*aCoord[0]*aCoord[1]; - aSlice[9] = 4.0*aCoord[0]*aCoord[2]; - aSlice[8] = 4.0*aCoord[0]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = aCoord[1]*(2.0*aCoord[1] - 1.0); + aSlice[2] = aCoord[2]*(2.0*aCoord[2] - 1.0); + aSlice[1] = (1.0 - aCoord[0] - aCoord[1] - aCoord[2])*(1.0 - 2.0*aCoord[0] - 2.0*aCoord[1] - 2.0*aCoord[2]); + aSlice[3] = aCoord[0]*(2.0*aCoord[0] - 1.0); + + aSlice[6] = 4.0*aCoord[1]*aCoord[2]; + aSlice[5] = 4.0*aCoord[2]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[4] = 4.0*aCoord[1]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); + + aSlice[7] = 4.0*aCoord[0]*aCoord[1]; + aSlice[9] = 4.0*aCoord[0]*aCoord[2]; + aSlice[8] = 4.0*aCoord[0]*(1.0 - aCoord[0] - aCoord[1] - aCoord[2]); } - }; + } + //--------------------------------------------------------------- - struct THexa8a: TShapeFun + THexa8a::THexa8a(): + TShapeFun(3,8) { - THexa8a(): - TShapeFun(3,8) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - case 7: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + case 7: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + THexa8a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); - aSlice[1] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); - aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); - aSlice[3] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); - - aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); - aSlice[5] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); - aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); - aSlice[7] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); + aSlice[1] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); + aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); + aSlice[3] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); + + aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); + aSlice[5] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); + aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); + aSlice[7] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); } - }; + } + - //--------------------------------------------------------------- - struct THexa20a: TShapeFun + //--------------------------------------------------------------- + THexa20a::THexa20a(TInt theDim, TInt theNbRef): + TShapeFun(theDim,theNbRef) { - THexa20a(TInt theDim = 3, TInt theNbRef = 20): - TShapeFun(theDim,theNbRef) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - case 7: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - - case 8: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 9: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; - case 10: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 11: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; - case 12: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 13: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 14: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 15: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 16: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 17: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 18: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - case 19: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 1: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 3: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + case 7: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + + case 8: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 9: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; + case 10: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 11: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; + case 12: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 13: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 14: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 15: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 16: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 17: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 18: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + case 19: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); - - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* - (-2.0 - aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[1] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* - (-2.0 + aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* - (-2.0 + aCoord[0] + aCoord[1] - aCoord[2]); - aSlice[3] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* - (-2.0 - aCoord[0] + aCoord[1] - aCoord[2]); - aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* - (-2.0 - aCoord[0] - aCoord[1] + aCoord[2]); - aSlice[5] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* - (-2.0 + aCoord[0] - aCoord[1] + aCoord[2]); - aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* - (-2.0 + aCoord[0] + aCoord[1] + aCoord[2]); - aSlice[7] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* - (-2.0 - aCoord[0] + aCoord[1] + aCoord[2]); - - aSlice[8] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); - aSlice[9] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 - aCoord[2]); - aSlice[10] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); - aSlice[11] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 - aCoord[2]); - aSlice[12] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 - aCoord[1]); - aSlice[13] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 - aCoord[1]); - aSlice[14] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 + aCoord[1]); - aSlice[15] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 + aCoord[1]); - aSlice[16] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); - aSlice[17] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 + aCoord[2]); - aSlice[18] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); - aSlice[19] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[2]); - } + void + THexa20a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); + + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* + (-2.0 - aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[1] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* + (-2.0 + aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* + (-2.0 + aCoord[0] + aCoord[1] - aCoord[2]); + aSlice[3] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* + (-2.0 - aCoord[0] + aCoord[1] - aCoord[2]); + aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* + (-2.0 - aCoord[0] - aCoord[1] + aCoord[2]); + aSlice[5] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* + (-2.0 + aCoord[0] - aCoord[1] + aCoord[2]); + aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* + (-2.0 + aCoord[0] + aCoord[1] + aCoord[2]); + aSlice[7] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* + (-2.0 - aCoord[0] + aCoord[1] + aCoord[2]); + + aSlice[8] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); + aSlice[9] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 - aCoord[2]); + aSlice[10] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); + aSlice[11] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 - aCoord[2]); + aSlice[12] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 - aCoord[1]); + aSlice[13] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 - aCoord[1]); + aSlice[14] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 + aCoord[1]); + aSlice[15] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 + aCoord[1]); + aSlice[16] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); + aSlice[17] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 + aCoord[2]); + aSlice[18] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); + aSlice[19] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[2]); } - }; + } + //--------------------------------------------------------------- - struct THexa27a: THexa20a + THexa27a::THexa27a(): + THexa20a(3,27) { - THexa27a(): - THexa20a(3,27) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 20: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; - case 21: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 22: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 23: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 24: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 25: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 26: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 20: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; + case 21: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 22: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 23: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 24: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 25: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 26: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); - - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.125*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] - 1.0); - aSlice[1] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] - 1.0); - aSlice[2] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] - 1.0); - aSlice[3] = 0.125*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] - 1.0); - aSlice[4] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] + 1.0); - aSlice[5] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] + 1.0); - aSlice[6] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] + 1.0); - aSlice[7] = 0.125*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] + 1.0); - - aSlice[8] = 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] - 1.0); - aSlice[9] = 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); - aSlice[10]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); - aSlice[11]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); - aSlice[12]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] - 1.0)*(1.0 - aCoord[2]*aCoord[2]); - aSlice[13]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*(1.0 - aCoord[2]*aCoord[2]); - aSlice[14]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] + 1.0)*(1.0 - aCoord[2]*aCoord[2]); - aSlice[15]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] + 1.0)*(1.0 - aCoord[2]*aCoord[2]); - aSlice[16]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] + 1.0); - aSlice[17]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] + 1.0); - aSlice[18]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] + 1.0); - aSlice[19]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] + 1.0); - aSlice[20]= 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); - aSlice[21]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] - 1.0)*(1.0 - aCoord[2]*aCoord[2]); - aSlice[22]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[2]*aCoord[2]); - aSlice[23]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] + 1.0)*(1.0 - aCoord[2]*aCoord[2]); - aSlice[24]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[2]*aCoord[2]); - aSlice[25]= 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] + 1.0); - aSlice[26]= 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[1]*aCoord[1]); - } + void + THexa27a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); + + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.125*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] - 1.0); + aSlice[1] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] - 1.0); + aSlice[2] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] - 1.0); + aSlice[3] = 0.125*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] - 1.0); + aSlice[4] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] + 1.0); + aSlice[5] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] + 1.0); + aSlice[6] = 0.125*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] + 1.0); + aSlice[7] = 0.125*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] + 1.0); + + aSlice[8] = 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] - 1.0); + aSlice[9] = 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); + aSlice[10]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); + aSlice[11]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); + aSlice[12]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] - 1.0)*(1.0 - aCoord[2]*aCoord[2]); + aSlice[13]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] - 1.0)*(1.0 - aCoord[2]*aCoord[2]); + aSlice[14]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*aCoord[1]*(aCoord[1] + 1.0)*(1.0 - aCoord[2]*aCoord[2]); + aSlice[15]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*aCoord[1]*(aCoord[1] + 1.0)*(1.0 - aCoord[2]*aCoord[2]); + aSlice[16]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] - 1.0)*aCoord[2]*(aCoord[2] + 1.0); + aSlice[17]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] + 1.0); + aSlice[18]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] + 1.0)*aCoord[2]*(aCoord[2] + 1.0); + aSlice[19]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] + 1.0); + aSlice[20]= 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] - 1.0); + aSlice[21]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] - 1.0)*(1.0 - aCoord[2]*aCoord[2]); + aSlice[22]= 0.25*aCoord[0]*(aCoord[0] + 1.0)*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[2]*aCoord[2]); + aSlice[23]= 0.25*(1.0 - aCoord[0]*aCoord[0])*aCoord[1]*(aCoord[1] + 1.0)*(1.0 - aCoord[2]*aCoord[2]); + aSlice[24]= 0.25*aCoord[0]*(aCoord[0] - 1.0)*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[2]*aCoord[2]); + aSlice[25]= 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]*aCoord[1])*aCoord[2]*(aCoord[2] + 1.0); + aSlice[26]= 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[1]*aCoord[1]); } - }; + } + //--------------------------------------------------------------- - struct THexa8b: TShapeFun + THexa8b::THexa8b(): + TShapeFun(3,8) { - THexa8b(): - TShapeFun(3,8) - { - TInt aNbRef = GetNbRef(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 7: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - case 5: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - } + TInt aNbRef = GetNbRef(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 7: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + case 5: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + THexa8b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); - aSlice[3] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); - aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); - aSlice[1] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); - - aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); - aSlice[7] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); - aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); - aSlice[5] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); + aSlice[3] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); + aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); + aSlice[1] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); + + aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); + aSlice[7] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); + aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); + aSlice[5] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); } - }; + } + //--------------------------------------------------------------- - struct THexa20b: TShapeFun + THexa20b::THexa20b(TInt theDim, TInt theNbRef): + TShapeFun(theDim,theNbRef) { - THexa20b(TInt theDim = 3, TInt theNbRef = 20): - TShapeFun(theDim,theNbRef) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 7: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - case 5: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - - case 11: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; - case 10: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; - case 9: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; - case 8: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; - case 16: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 19: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 18: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 17: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 15: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; - case 14: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 13: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; - case 12: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 2: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 4: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 7: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 6: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + case 5: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + + case 11: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = -1.0; break; + case 10: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; + case 9: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = -1.0; break; + case 8: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = -1.0; break; + case 16: aCoord[0] = -1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 19: aCoord[0] = 1.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 18: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 17: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 15: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 1.0; break; + case 14: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 13: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 1.0; break; + case 12: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); - - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* - (-2.0 - aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[3] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* - (-2.0 + aCoord[0] - aCoord[1] - aCoord[2]); - aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* - (-2.0 + aCoord[0] + aCoord[1] - aCoord[2]); - aSlice[1] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* - (-2.0 - aCoord[0] + aCoord[1] - aCoord[2]); - aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* - (-2.0 - aCoord[0] - aCoord[1] + aCoord[2]); - aSlice[7] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* - (-2.0 + aCoord[0] - aCoord[1] + aCoord[2]); - aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* - (-2.0 + aCoord[0] + aCoord[1] + aCoord[2]); - aSlice[5] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* - (-2.0 - aCoord[0] + aCoord[1] + aCoord[2]); - - aSlice[11] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); - aSlice[10] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 - aCoord[2]); - aSlice[9] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); - aSlice[8] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 - aCoord[2]); - aSlice[16] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 - aCoord[1]); - aSlice[19] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 - aCoord[1]); - aSlice[18] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 + aCoord[1]); - aSlice[17] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 + aCoord[1]); - aSlice[15] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); - aSlice[14] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 + aCoord[2]); - aSlice[13] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); - aSlice[12] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[2]); - } + void + THexa20b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); + + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* + (-2.0 - aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[3] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2])* + (-2.0 + aCoord[0] - aCoord[1] - aCoord[2]); + aSlice[2] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* + (-2.0 + aCoord[0] + aCoord[1] - aCoord[2]); + aSlice[1] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2])* + (-2.0 - aCoord[0] + aCoord[1] - aCoord[2]); + aSlice[4] = 0.125*(1.0 - aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* + (-2.0 - aCoord[0] - aCoord[1] + aCoord[2]); + aSlice[7] = 0.125*(1.0 + aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2])* + (-2.0 + aCoord[0] - aCoord[1] + aCoord[2]); + aSlice[6] = 0.125*(1.0 + aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* + (-2.0 + aCoord[0] + aCoord[1] + aCoord[2]); + aSlice[5] = 0.125*(1.0 - aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2])* + (-2.0 - aCoord[0] + aCoord[1] + aCoord[2]); + + aSlice[11] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 - aCoord[2]); + aSlice[10] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 - aCoord[2]); + aSlice[9] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 - aCoord[2]); + aSlice[8] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 - aCoord[2]); + aSlice[16] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 - aCoord[1]); + aSlice[19] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 - aCoord[1]); + aSlice[18] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 + aCoord[0])*(1.0 + aCoord[1]); + aSlice[17] = 0.25*(1.0 - aCoord[2]*aCoord[2])*(1.0 - aCoord[0])*(1.0 + aCoord[1]); + aSlice[15] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 - aCoord[1])*(1.0 + aCoord[2]); + aSlice[14] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 + aCoord[0])*(1.0 + aCoord[2]); + aSlice[13] = 0.25*(1.0 - aCoord[0]*aCoord[0])*(1.0 + aCoord[1])*(1.0 + aCoord[2]); + aSlice[12] = 0.25*(1.0 - aCoord[1]*aCoord[1])*(1.0 - aCoord[0])*(1.0 + aCoord[2]); } - }; + } + //--------------------------------------------------------------- - struct TPenta6a: TShapeFun + TPenta6a::TPenta6a(): + TShapeFun(3,6) { - TPenta6a(): - TShapeFun(3,6) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TPenta6a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0]); - aSlice[1] = 0.5*aCoord[2]*(1.0 - aCoord[0]); - aSlice[2] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); + aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0]); + aSlice[1] = 0.5*aCoord[2]*(1.0 - aCoord[0]); + aSlice[2] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); - aSlice[3] = 0.5*aCoord[1]*(aCoord[0] + 1.0); - aSlice[4] = 0.5*aCoord[2]*(aCoord[0] + 1.0); - aSlice[5] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); - } + aSlice[3] = 0.5*aCoord[1]*(aCoord[0] + 1.0); + aSlice[4] = 0.5*aCoord[2]*(aCoord[0] + 1.0); + aSlice[5] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TPenta6b: TShapeFun + TPenta6b::TPenta6b(): + TShapeFun(3,6) { - TPenta6b(): - TShapeFun(3,6) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TPenta6b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0]); - aSlice[2] = 0.5*aCoord[2]*(1.0 - aCoord[0]); - aSlice[1] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); - - aSlice[3] = 0.5*aCoord[1]*(aCoord[0] + 1.0); - aSlice[5] = 0.5*aCoord[2]*(aCoord[0] + 1.0); - aSlice[4] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0]); + aSlice[2] = 0.5*aCoord[2]*(1.0 - aCoord[0]); + aSlice[1] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); + + aSlice[3] = 0.5*aCoord[1]*(aCoord[0] + 1.0); + aSlice[5] = 0.5*aCoord[2]*(aCoord[0] + 1.0); + aSlice[4] = 0.5*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TPenta15a: TShapeFun + TPenta15a::TPenta15a(): + TShapeFun(3,15) { - TPenta15a(): - TShapeFun(3,15) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - - case 6: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 8: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 9: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 10: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 11: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 12: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 13: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 14: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + + case 6: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 8: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 9: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 10: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 11: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 12: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 13: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 14: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TPenta15a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0])*(2.0*aCoord[1] - 2.0 - aCoord[0]); - aSlice[1] = 0.5*aCoord[2]*(1.0 - aCoord[0])*(2.0*aCoord[2] - 2.0 - aCoord[0]); - aSlice[2] = 0.5*(aCoord[0] - 1.0)*(1.0 - aCoord[1] - aCoord[2])*(aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); + aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0])*(2.0*aCoord[1] - 2.0 - aCoord[0]); + aSlice[1] = 0.5*aCoord[2]*(1.0 - aCoord[0])*(2.0*aCoord[2] - 2.0 - aCoord[0]); + aSlice[2] = 0.5*(aCoord[0] - 1.0)*(1.0 - aCoord[1] - aCoord[2])*(aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); - aSlice[3] = 0.5*aCoord[1]*(1.0 + aCoord[0])*(2.0*aCoord[1] - 2.0 - aCoord[0]); - aSlice[4] = 0.5*aCoord[2]*(1.0 + aCoord[0])*(2.0*aCoord[2] - 2.0 - aCoord[0]); - aSlice[5] = -0.5*(aCoord[0] + 1.0)*(1.0 - aCoord[1] - aCoord[2])*(-aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); + aSlice[3] = 0.5*aCoord[1]*(1.0 + aCoord[0])*(2.0*aCoord[1] - 2.0 + aCoord[0]); + aSlice[4] = 0.5*aCoord[2]*(1.0 + aCoord[0])*(2.0*aCoord[2] - 2.0 + aCoord[0]); + aSlice[5] = 0.5*(-aCoord[0] - 1.0)*(1.0 - aCoord[1] - aCoord[2])*(-aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); - aSlice[6] = 2.0*aCoord[1]*aCoord[2]*(1.0 - aCoord[0]); - aSlice[7] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); - aSlice[8] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); + aSlice[6] = 2.0*aCoord[1]*aCoord[2]*(1.0 - aCoord[0]); + aSlice[7] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); + aSlice[8] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); - aSlice[9] = aCoord[1]*(1.0 - aCoord[0]*aCoord[0]); - aSlice[10] = aCoord[2]*(1.0 - aCoord[0]*aCoord[0]); - aSlice[11] = (1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]*aCoord[0]); + aSlice[9] = aCoord[1]*(1.0 - aCoord[0]*aCoord[0]); + aSlice[10] = aCoord[2]*(1.0 - aCoord[0]*aCoord[0]); + aSlice[11] = (1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]*aCoord[0]); - aSlice[12] = 2.0*aCoord[1]*aCoord[2]*(1.0 + aCoord[0]); - aSlice[13] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); - aSlice[14] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); - } + aSlice[12] = 2.0*aCoord[1]*aCoord[2]*(1.0 + aCoord[0]); + aSlice[13] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); + aSlice[14] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TPenta15b: TShapeFun + TPenta15b::TPenta15b(): + TShapeFun(3,15) { - TPenta15b(): - TShapeFun(3,15) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; - case 1: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - - case 8: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 6: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 12: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 14: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - case 13: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 11: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 10: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 9: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = -1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = -0.0; aCoord[2] = 1.0; break; + case 1: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 1.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 5: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 4: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + + case 8: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 7: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 6: aCoord[0] = -1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 12: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 14: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + case 13: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 11: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 10: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 9: aCoord[0] = 1.0; aCoord[1] = 0.5; aCoord[2] = 0.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TPenta15b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0])*(2.0*aCoord[1] - 2.0 - aCoord[0]); - aSlice[2] = 0.5*aCoord[2]*(1.0 - aCoord[0])*(2.0*aCoord[2] - 2.0 - aCoord[0]); - aSlice[1] = 0.5*(aCoord[0] - 1.0)*(1.0 - aCoord[1] - aCoord[2])*(aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); - - aSlice[3] = 0.5*aCoord[1]*(1.0 + aCoord[0])*(2.0*aCoord[1] - 2.0 - aCoord[0]); - aSlice[5] = 0.5*aCoord[2]*(1.0 + aCoord[0])*(2.0*aCoord[2] - 2.0 - aCoord[0]); - aSlice[4] = -0.5*(aCoord[0] + 1.0)*(1.0 - aCoord[1] - aCoord[2])*(-aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); - - aSlice[8] = 2.0*aCoord[1]*aCoord[2]*(1.0 - aCoord[0]); - aSlice[7] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); - aSlice[6] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); - - aSlice[12] = aCoord[1]*(1.0 - aCoord[0]*aCoord[0]); - aSlice[14] = aCoord[2]*(1.0 - aCoord[0]*aCoord[0]); - aSlice[13] = (1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]*aCoord[0]); - - aSlice[11] = 2.0*aCoord[1]*aCoord[2]*(1.0 + aCoord[0]); - aSlice[10] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); - aSlice[9] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.5*aCoord[1]*(1.0 - aCoord[0])*(2.0*aCoord[1] - 2.0 - aCoord[0]); + aSlice[2] = 0.5*aCoord[2]*(1.0 - aCoord[0])*(2.0*aCoord[2] - 2.0 - aCoord[0]); + aSlice[1] = 0.5*(aCoord[0] - 1.0)*(1.0 - aCoord[1] - aCoord[2])*(aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); + + aSlice[3] = 0.5*aCoord[1]*(1.0 + aCoord[0])*(2.0*aCoord[1] - 2.0 + aCoord[0]); + aSlice[5] = 0.5*aCoord[2]*(1.0 + aCoord[0])*(2.0*aCoord[2] - 2.0 + aCoord[0]); + aSlice[4] = 0.5*(-aCoord[0] - 1.0)*(1.0 - aCoord[1] - aCoord[2])*(-aCoord[0] + 2.0*aCoord[1] + 2.0*aCoord[2]); + + aSlice[8] = 2.0*aCoord[1]*aCoord[2]*(1.0 - aCoord[0]); + aSlice[7] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); + aSlice[6] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]); + + aSlice[12] = aCoord[1]*(1.0 - aCoord[0]*aCoord[0]); + aSlice[14] = aCoord[2]*(1.0 - aCoord[0]*aCoord[0]); + aSlice[13] = (1.0 - aCoord[1] - aCoord[2])*(1.0 - aCoord[0]*aCoord[0]); + + aSlice[11] = 2.0*aCoord[1]*aCoord[2]*(1.0 + aCoord[0]); + aSlice[10] = 2.0*aCoord[2]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); + aSlice[9] = 2.0*aCoord[1]*(1.0 - aCoord[1] - aCoord[2])*(1.0 + aCoord[0]); } - }; + } + //--------------------------------------------------------------- - struct TPyra5a: TShapeFun + TPyra5a::TPyra5a(): + TShapeFun(3,5) { - TPyra5a(): - TShapeFun(3,5) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); - - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.25*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[1] = 0.25*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[2] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[3] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[4] = 1.0 - aCoord[2]; - } + void + TPyra5a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); + + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.25*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[1] = 0.25*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[2] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[3] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[4] = 1.0 - aCoord[2]; } - }; + } + //--------------------------------------------------------------- - struct TPyra5b: TShapeFun + TPyra5b::TPyra5b(): + TShapeFun(3,5) { - TPyra5b(): - TShapeFun(3,5) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); + void + TPyra5b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.25*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[3] = 0.25*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[2] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[1] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[4] = 1.0 - aCoord[2]; - } + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.25*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[3] = 0.25*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[2] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[1] = 0.25*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[4] = 1.0 - aCoord[2]; } - }; + } + //--------------------------------------------------------------- - struct TPyra13a: TShapeFun + TPyra13a::TPyra13a(): + TShapeFun(3,13) { - TPyra13a(): - TShapeFun(3,13) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - - case 5: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 6: aCoord[0] = -0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 7: aCoord[0] = -0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; - case 8: aCoord[0] = 0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; - case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 10: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 11: aCoord[0] = -0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 12: aCoord[0] = 0.0; aCoord[1] = -0.5; aCoord[2] = 0.5; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + + case 5: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 6: aCoord[0] = -0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 7: aCoord[0] = -0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; + case 8: aCoord[0] = 0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; + case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 10: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 11: aCoord[0] = -0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 12: aCoord[0] = 0.0; aCoord[1] = -0.5; aCoord[2] = 0.5; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); - - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[0] - 0.5)/(1.0 - aCoord[2]); - aSlice[1] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[1] - 0.5)/(1.0 - aCoord[2]); - aSlice[2] = 0.5*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[0] - 0.5)/(1.0 - aCoord[2]); - aSlice[3] = 0.5*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[1] - 0.5)/(1.0 - aCoord[2]); - - aSlice[4] = 2.0*aCoord[2]*(aCoord[2] - 0.5); - - aSlice[5] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[6] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[7] = 0.5*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[8] = 0.5*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - - aSlice[9] = 0.5*aCoord[2]*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - aSlice[10] = 0.5*aCoord[2]*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - aSlice[11] = 0.5*aCoord[2]*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - aSlice[12] = 0.5*aCoord[2]*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - } + void + TPyra13a::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); + + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[0] - 0.5)/(1.0 - aCoord[2]); + aSlice[1] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[1] - 0.5)/(1.0 - aCoord[2]); + aSlice[2] = 0.5*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[0] - 0.5)/(1.0 - aCoord[2]); + aSlice[3] = 0.5*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[1] - 0.5)/(1.0 - aCoord[2]); + + aSlice[4] = 2.0*aCoord[2]*(aCoord[2] - 0.5); + + aSlice[5] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[6] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[7] = 0.5*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[8] = 0.5*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + + aSlice[9] = 0.5*aCoord[2]*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); + aSlice[10] = 0.5*aCoord[2]*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); + aSlice[11] = 0.5*aCoord[2]*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); + aSlice[12] = 0.5*aCoord[2]*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); } - }; + } + //--------------------------------------------------------------- - struct TPyra13b: TShapeFun + TPyra13b::TPyra13b(): + TShapeFun(3,13) { - TPyra13b(): - TShapeFun(3,13) - { - TInt aNbRef = myRefCoord.size(); - for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ - TCoordSlice aCoord = GetCoord(aRefId); - switch(aRefId){ - case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 3: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; - case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; - case 1: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; - case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; - - case 8: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 7: aCoord[0] = -0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; - case 6: aCoord[0] = -0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; - case 5: aCoord[0] = 0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; - case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 12: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; - case 11: aCoord[0] = -0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; - case 10: aCoord[0] = 0.0; aCoord[1] = -0.5; aCoord[2] = 0.5; break; - } + TInt aNbRef = myRefCoord.size(); + for(TInt aRefId = 0; aRefId < aNbRef; aRefId++){ + TCoordSlice aCoord = GetCoord(aRefId); + switch(aRefId){ + case 0: aCoord[0] = 1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 3: aCoord[0] = 0.0; aCoord[1] = 1.0; aCoord[2] = 0.0; break; + case 2: aCoord[0] = -1.0; aCoord[1] = 0.0; aCoord[2] = 0.0; break; + case 1: aCoord[0] = 0.0; aCoord[1] = -1.0; aCoord[2] = 0.0; break; + case 4: aCoord[0] = 0.0; aCoord[1] = 0.0; aCoord[2] = 1.0; break; + + case 8: aCoord[0] = 0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 7: aCoord[0] = -0.5; aCoord[1] = 0.5; aCoord[2] = 0.0; break; + case 6: aCoord[0] = -0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; + case 5: aCoord[0] = 0.5; aCoord[1] = -0.5; aCoord[2] = 0.0; break; + case 9: aCoord[0] = 0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 12: aCoord[0] = 0.0; aCoord[1] = 0.5; aCoord[2] = 0.5; break; + case 11: aCoord[0] = -0.5; aCoord[1] = 0.0; aCoord[2] = 0.5; break; + case 10: aCoord[0] = 0.0; aCoord[1] = -0.5; aCoord[2] = 0.5; break; } } + } - virtual - void - InitFun(const TShapeFun::TCCoordSliceArr& theRef, - const TShapeFun::TCCoordSliceArr& theGauss, - TFun& theFun) const - { - GetFun(theRef,theGauss,theFun); - - TInt aNbGauss = theGauss.size(); - for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ - const TCCoordSlice& aCoord = theGauss[aGaussId]; - TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); - - aSlice[0] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[0] - 0.5)/(1.0 - aCoord[2]); - aSlice[3] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[1] - 0.5)/(1.0 - aCoord[2]); - aSlice[2] = 0.5*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[0] - 0.5)/(1.0 - aCoord[2]); - aSlice[1] = 0.5*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[1] - 0.5)/(1.0 - aCoord[2]); - - aSlice[4] = 2.0*aCoord[2]*(aCoord[2] - 0.5); - - aSlice[8] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[7] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* - (aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[6] = 0.5*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - aSlice[5] = 0.5*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* - (-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); - - aSlice[9] = 0.5*aCoord[2]*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - aSlice[12] = 0.5*aCoord[2]*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - aSlice[11] = 0.5*aCoord[2]*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - aSlice[10] = 0.5*aCoord[2]*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ - (1.0 - aCoord[2]); - } + void + TPyra13b::InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const + { + GetFun(theRef,theGauss,theFun); + + TInt aNbGauss = theGauss.size(); + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ + const TCCoordSlice& aCoord = theGauss[aGaussId]; + TFloatVecSlice aSlice = theFun.GetFunSlice(aGaussId); + + aSlice[0] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[0] - 0.5)/(1.0 - aCoord[2]); + aSlice[3] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[1] - 0.5)/(1.0 - aCoord[2]); + aSlice[2] = 0.5*(+aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[0] - 0.5)/(1.0 - aCoord[2]); + aSlice[1] = 0.5*(+aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[1] - 0.5)/(1.0 - aCoord[2]); + + aSlice[4] = 2.0*aCoord[2]*(aCoord[2] - 0.5); + + aSlice[8] = 0.5*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[7] = 0.5*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)* + (aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[6] = 0.5*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + aSlice[5] = 0.5*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)* + (-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/(1.0 - aCoord[2]); + + aSlice[9] = 0.5*aCoord[2]*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); + aSlice[12] = 0.5*aCoord[2]*(-aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); + aSlice[11] = 0.5*aCoord[2]*(aCoord[0] - aCoord[1] + aCoord[2] - 1.0)*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); + aSlice[10] = 0.5*aCoord[2]*(aCoord[0] + aCoord[1] + aCoord[2] - 1.0)*(-aCoord[0] + aCoord[1] + aCoord[2] - 1.0)/ + (1.0 - aCoord[2]); } - }; + } + //--------------------------------------------------------------- @@ -1766,7 +1697,7 @@ namespace MED switch(aGeom){ case eSEG2: { - INITMSG(MYDEBUG,"eSEG2"<<endl); + INITMSG(MYDEBUG,"eSEG2"<<std::endl); if(TSeg2a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1774,7 +1705,7 @@ namespace MED break; } case eSEG3: { - INITMSG(MYDEBUG,"eSEG3"<<endl); + INITMSG(MYDEBUG,"eSEG3"<<std::endl); if(TSeg3a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1782,7 +1713,7 @@ namespace MED break; } case eTRIA3: { - INITMSG(MYDEBUG,"eTRIA3"<<endl); + INITMSG(MYDEBUG,"eTRIA3"<<std::endl); if(TTria3a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1793,18 +1724,18 @@ namespace MED break; } case eTRIA6: { - INITMSG(MYDEBUG,"eTRIA6"<<endl); + INITMSG(MYDEBUG,"eTRIA6"<<std::endl); if(TTria6a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; if(TTria6b().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; - + break; } case eQUAD4: { - INITMSG(MYDEBUG,"eQUAD4"<<endl); + INITMSG(MYDEBUG,"eQUAD4"<<std::endl); if(TQuad4a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1815,7 +1746,7 @@ namespace MED break; } case eQUAD8: { - INITMSG(MYDEBUG,"eQUAD8"<<endl); + INITMSG(MYDEBUG,"eQUAD8"<<std::endl); if(TQuad8a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1826,7 +1757,7 @@ namespace MED break; } case eTETRA4: { - INITMSG(MYDEBUG,"eTETRA4"<<endl); + INITMSG(MYDEBUG,"eTETRA4"<<std::endl); if(TTetra4a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1837,18 +1768,18 @@ namespace MED break; } case ePYRA5: { - INITMSG(MYDEBUG,"ePYRA5"<<endl); + INITMSG(MYDEBUG,"ePYRA5"<<std::endl); if(TPyra5a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; - + if(TPyra5b().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; break; } case ePENTA6: { - INITMSG(MYDEBUG,"ePENTA6"<<endl); + INITMSG(MYDEBUG,"ePENTA6"<<std::endl); if(TPenta6a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1859,7 +1790,7 @@ namespace MED break; } case eHEXA8: { - INITMSG(MYDEBUG,"eHEXA8"<<endl); + INITMSG(MYDEBUG,"eHEXA8"<<std::endl); if(THexa8a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1870,7 +1801,7 @@ namespace MED break; } case eTETRA10: { - INITMSG(MYDEBUG,"eTETRA10"<<endl); + INITMSG(MYDEBUG,"eTETRA10"<<std::endl); if(TTetra10a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1881,18 +1812,18 @@ namespace MED break; } case ePYRA13: { - INITMSG(MYDEBUG,"ePYRA13"<<endl); + INITMSG(MYDEBUG,"ePYRA13"<<std::endl); if(TPyra13a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; - + if(TPyra13b().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; break; } case ePENTA15: { - INITMSG(MYDEBUG,"ePENTA15"<<endl); + INITMSG(MYDEBUG,"ePENTA15"<<std::endl); if(TPenta15a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1903,7 +1834,7 @@ namespace MED break; } case eHEXA20: { - INITMSG(MYDEBUG,"eHEXA20"<<endl); + INITMSG(MYDEBUG,"eHEXA20"<<std::endl); if(THexa20a().Eval(theCellInfo,theNodeInfo,theElemNum,aRefSlice,aGaussSlice,theGaussCoord,theMode)) return true; @@ -1914,7 +1845,7 @@ namespace MED break; } default: - INITMSG(MYDEBUG,"eNONE"<<endl); + INITMSG(MYDEBUG,"eNONE"<<std::endl); return false; } } @@ -1934,48 +1865,48 @@ namespace MED const PMeshInfo& aMeshInfo = theCellInfo.GetMeshInfo(); TInt aDim = aMeshInfo->GetDim(); static TInt aNbGauss = 1; - + bool anIsSubMesh = !theElemNum.empty(); TInt aNbElem; if(anIsSubMesh) aNbElem = theElemNum.size(); else aNbElem = theCellInfo.GetNbElem(); - + theGaussCoord.Init(aNbElem,aNbGauss,aDim,theMode); TInt aConnDim = theCellInfo.GetConnDim(); - + INITMSGA(MYDEBUG,0, "- aDim = "<<aDim<< "; aNbGauss = "<<aNbGauss<< "; aNbElem = "<<aNbElem<< "; aNbNodes = "<<theNodeInfo.GetNbElem()<< - endl); - + std::endl); + for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ TInt aCellId = anIsSubMesh? theElemNum[anElemId]-1: anElemId; TCConnSlice aConnSlice = theCellInfo.GetConnSlice(aCellId); TCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); - + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ TCoordSlice& aGaussCoordSlice = aCoordSliceArr[aGaussId]; - + for(TInt aConnId = 0; aConnId < aConnDim; aConnId++){ TInt aNodeId = aConnSlice[aConnId] - 1; TCCoordSlice aNodeCoordSlice = theNodeInfo.GetCoordSlice(aNodeId); - + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ aGaussCoordSlice[aDimId] += aNodeCoordSlice[aDimId]; } } - + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ aGaussCoordSlice[aDimId] /= aConnDim; } } } - + #ifdef _DEBUG_ for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ TCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); @@ -1988,7 +1919,7 @@ namespace MED } ADDMSG(MYVALUEDEBUG,"} "); } - ADDMSG(MYVALUEDEBUG,endl); + ADDMSG(MYVALUEDEBUG,std::endl); } #endif @@ -2008,14 +1939,14 @@ namespace MED const PMeshInfo& aMeshInfo = thePolygoneInfo.GetMeshInfo(); TInt aDim = aMeshInfo->GetDim(); static TInt aNbGauss = 1; - + bool anIsSubMesh = !theElemNum.empty(); TInt aNbElem; if(anIsSubMesh) aNbElem = theElemNum.size(); else aNbElem = thePolygoneInfo.GetNbElem(); - + theGaussCoord.Init(aNbElem,aNbGauss,aDim,theMode); INITMSGA(MYDEBUG,0, @@ -2023,28 +1954,28 @@ namespace MED "; aNbGauss = "<<aNbGauss<< "; aNbElem = "<<aNbElem<< "; aNbNodes = "<<theNodeInfo.GetNbElem()<< - endl); - + std::endl); + for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ TInt aCellId = anIsSubMesh? theElemNum[anElemId]-1: anElemId; - + TCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); TCConnSlice aConnSlice = thePolygoneInfo.GetConnSlice(aCellId); TInt aNbConn = thePolygoneInfo.GetNbConn(aCellId); TInt aNbNodes = thePolygoneInfo.GetNbConn(aCellId); - + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ TCoordSlice& aGaussCoordSlice = aCoordSliceArr[aGaussId]; - + for(TInt aConnId = 0; aConnId < aNbConn; aConnId++){ TInt aNodeId = aConnSlice[aConnId] - 1; TCCoordSlice aNodeCoordSlice = theNodeInfo.GetCoordSlice(aNodeId); - + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ aGaussCoordSlice[aDimId] += aNodeCoordSlice[aDimId]; } } - + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ aGaussCoordSlice[aDimId] /= aNbNodes; } @@ -2067,14 +1998,14 @@ namespace MED const PMeshInfo& aMeshInfo = thePolyedreInfo.GetMeshInfo(); TInt aDim = aMeshInfo->GetDim(); static TInt aNbGauss = 1; - + bool anIsSubMesh = !theElemNum.empty(); TInt aNbElem; if(anIsSubMesh) aNbElem = theElemNum.size(); else aNbElem = thePolyedreInfo.GetNbElem(); - + theGaussCoord.Init(aNbElem,aNbGauss,aDim,theMode); INITMSGA(MYDEBUG,0, @@ -2082,27 +2013,27 @@ namespace MED "; aNbGauss = "<<aNbGauss<< "; aNbElem = "<<aNbElem<< "; aNbNodes = "<<theNodeInfo.GetNbElem()<< - endl); - + std::endl); + for(TInt anElemId = 0; anElemId < aNbElem; anElemId++){ TInt aCellId = anIsSubMesh? theElemNum[anElemId]-1: anElemId; - + TCoordSliceArr aCoordSliceArr = theGaussCoord.GetCoordSliceArr(anElemId); TCConnSliceArr aConnSliceArr = thePolyedreInfo.GetConnSliceArr(aCellId); TInt aNbFaces = aConnSliceArr.size(); TInt aNbNodes = thePolyedreInfo.GetNbNodes(aCellId); - + for(TInt aGaussId = 0; aGaussId < aNbGauss; aGaussId++){ TCoordSlice& aGaussCoordSlice = aCoordSliceArr[aGaussId]; - + for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++){ TCConnSlice aConnSlice = aConnSliceArr[aFaceId]; TInt aNbConn = aConnSlice.size(); for(TInt aConnId = 0; aConnId < aNbConn; aConnId++){ TInt aNodeId = aConnSlice[aConnId] - 1; TCCoordSlice aNodeCoordSlice = theNodeInfo.GetCoordSlice(aNodeId); - + for(TInt aDimId = 0; aDimId < aDim; aDimId++){ aGaussCoordSlice[aDimId] += aNodeCoordSlice[aDimId]; } diff --git a/src/MEDWrapper/Base/MED_GaussUtils.hxx b/src/MEDWrapper/Base/MED_GaussUtils.hxx index a94a363d0..14de39d57 100644 --- a/src/MEDWrapper/Base/MED_GaussUtils.hxx +++ b/src/MEDWrapper/Base/MED_GaussUtils.hxx @@ -29,6 +29,8 @@ #ifndef MED_GaussUtils_HeaderFile #define MED_GaussUtils_HeaderFile +#include "MED_WrapperBase.hxx" + #include "MED_Structures.hxx" namespace MED @@ -38,7 +40,7 @@ namespace MED typedef TVector<TCoordSlice> TCoordSliceArr; //! Define a helper class to handle Gauss Points coordinates - class TGaussCoord: + class MEDWRAPPER_EXPORT TGaussCoord: virtual TModeSwitchInfo { TInt myNbElem; @@ -53,14 +55,6 @@ namespace MED TGaussCoord(); - //! Get slice of the coordinate that corresponds to defined cell (const version) - TCCoordSliceArr - GetCoordSliceArr(TInt theElemId) const; - - //! Get slice of the coordinate that corresponds to defined cell - TCoordSliceArr - GetCoordSliceArr(TInt theElemId); - //! To init the class void Init(TInt theNbElem, @@ -69,18 +63,31 @@ namespace MED EModeSwitch theMode = eFULL_INTERLACE); TInt - GetNbElem() const { return myNbElem; } + GetNbElem() const; TInt - GetNbGauss() const { return myNbGauss; } + GetNbGauss() const; TInt - GetDim() const { return myDim; } + GetDim() const; + + unsigned char* + GetValuePtr(); + + //! Get slice of the coordinate that corresponds to defined cell (const version) + TCCoordSliceArr + GetCoordSliceArr(TInt theElemId) const; + + //! Get slice of the coordinate that corresponds to defined cell + TCoordSliceArr + GetCoordSliceArr(TInt theElemId); }; + typedef SharedPtr<TGaussCoord> PGaussCoord; //--------------------------------------------------------------- //! To calculate Gauss Points coordinates + MEDWRAPPER_EXPORT bool GetGaussCoord3D(const TGaussInfo& theGaussInfo, const TCellInfo& theCellInfo, @@ -92,6 +99,7 @@ namespace MED //--------------------------------------------------------------- //! To calculate Gauss Points coordinates for defined TCellInfo as its bary center + MEDWRAPPER_EXPORT bool GetBaryCenter(const TCellInfo& theCellInfo, const TNodeInfo& theNodeInfo, @@ -100,6 +108,7 @@ namespace MED EModeSwitch theMode = eFULL_INTERLACE); //! To calculate Gauss Points coordinates for defined TPolygoneInfo as its bary center + MEDWRAPPER_EXPORT bool GetBaryCenter(const TPolygoneInfo& thePolygoneInfo, const TNodeInfo& theNodeInfo, @@ -108,12 +117,242 @@ namespace MED EModeSwitch theMode = eFULL_INTERLACE); //! To calculate Gauss Points coordinates for defined TPolyedreInfo as its bary center + MEDWRAPPER_EXPORT bool GetBaryCenter(const TPolyedreInfo& thePolyedreInfo, const TNodeInfo& theNodeInfo, TGaussCoord& theGaussCoord, const TElemNum& theElemNum = TElemNum(), EModeSwitch theMode = eFULL_INTERLACE); + + //--------------------------------------------------------------- + //! Shape function definitions + //--------------------------------------------------------------- + struct MEDWRAPPER_EXPORT TShapeFun + { + class TFun; + + TFloatVector myRefCoord; + TInt myDim; + TInt myNbRef; + + TShapeFun(TInt theDim = 0, TInt theNbRef = 0); + + TInt GetNbRef() const { return myNbRef; } + + TCCoordSlice GetCoord(TInt theRefId) const; + + TCoordSlice GetCoord(TInt theRefId); + + void GetFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + virtual + void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const = 0; + virtual + bool IsSatisfy(const TCCoordSliceArr& theRefCoord) const; + + bool Eval(const TCellInfo& theCellInfo, + const TNodeInfo& theNodeInfo, + const TElemNum& theElemNum, + const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TGaussCoord& theGaussCoord, + EModeSwitch theMode); + }; + //--------------------------------------------------------------- + struct TSeg2a: TShapeFun { + TSeg2a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TSeg3a: TShapeFun { + TSeg3a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTria3a: TShapeFun { + TTria3a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTria6a: TShapeFun { + TTria6a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTria3b: TShapeFun { + TTria3b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTria6b: TShapeFun { + TTria6b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TQuad4a: TShapeFun { + TQuad4a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TQuad8a: TShapeFun { + TQuad8a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TQuad4b: TShapeFun { + TQuad4b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TQuad8b: TShapeFun { + TQuad8b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTetra4a: TShapeFun { + TTetra4a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTetra10a: TShapeFun { + TTetra10a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTetra4b: TShapeFun { + TTetra4b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TTetra10b: TShapeFun { + TTetra10b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct THexa8a: TShapeFun { + THexa8a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct THexa20a: TShapeFun { + THexa20a(TInt theDim = 3, TInt theNbRef = 20); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct THexa27a: THexa20a { + THexa27a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct THexa8b: TShapeFun { + THexa8b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct THexa20b: TShapeFun { + THexa20b(TInt theDim = 3, TInt theNbRef = 20); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPenta6a: TShapeFun { + TPenta6a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPenta6b: TShapeFun { + TPenta6b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPenta15a: TShapeFun { + TPenta15a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPenta15b: TShapeFun { + TPenta15b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPyra5a: TShapeFun { + TPyra5a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPyra5b: TShapeFun { + TPyra5b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPyra13a: TShapeFun { + TPyra13a(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + struct TPyra13b: TShapeFun { + TPyra13b(); + virtual void InitFun(const TCCoordSliceArr& theRef, + const TCCoordSliceArr& theGauss, + TFun& theFun) const; + }; + //--------------------------------------------------------------- + } #endif diff --git a/src/MEDWrapper/Base/MED_SliceArray.hxx b/src/MEDWrapper/Base/MED_SliceArray.hxx index 5364d32e2..cce9c465c 100644 --- a/src/MEDWrapper/Base/MED_SliceArray.hxx +++ b/src/MEDWrapper/Base/MED_SliceArray.hxx @@ -29,6 +29,11 @@ #ifndef MED_SliceArray_HeaderFile #define MED_SliceArray_HeaderFile +#ifdef WNT // for correctly compiling "valarray" in modules, which are includes this file + #undef max + #undef min +#endif + #include <valarray> #include <stdexcept> @@ -45,12 +50,13 @@ namespace MED This class deal with constant pointer to the sources data and provide const method to read the them (data). */ - template<class TContainer> + template<class TValueType> class TCSlice { - typedef const TContainer* PCContainer; - PCContainer myCContainer; //!< Reference to source multy-dimension data + const TValueType* myCValuePtr; //!< Reference to source multy-dimension data + size_t mySourceSize; //!< Size of the source multy-dimension data std::slice mySlice; //!< Defines algorithm of index calculation + protected: void check_id(size_t theId) const @@ -58,7 +64,7 @@ namespace MED long int anId = -1; if(theId < mySlice.size()){ anId = mySlice.start() + theId*mySlice.stride(); - if(anId < myCContainer->size()) + if(anId < mySourceSize) return; } throw std::out_of_range("TCSlice::check_id"); @@ -88,31 +94,41 @@ namespace MED } public: - typedef typename TContainer::value_type value_type; + typedef TValueType value_type; - //! Construct the class - TCSlice(const TContainer& theContainer, + //! Construct the class from bare pointer + TCSlice(const value_type* theValuePtr, + size_t theSourceSize, + const std::slice& theSlice): + myCValuePtr(theValuePtr), + mySourceSize(theSourceSize), + mySlice(theSlice) + {} + + //! Construct the class from corresponding container + TCSlice(const TVector<value_type>& theContainer, const std::slice& theSlice): - myCContainer(&theContainer), + myCValuePtr(&theContainer[0]), + mySourceSize(theContainer.size()), mySlice(theSlice) {} //! Default constructor (dangerous) TCSlice(): - myCContainer(NULL) + myCValuePtr(NULL) {} //! Get element by its number (const version) const value_type& operator[](size_t theId) const { - return (*myCContainer)[get_id(theId)]; + return *(myCValuePtr + get_id(theId)); } const value_type& at(size_t theId) const { - return (*myCContainer)[get_id_at(theId)]; + return *(myCValuePtr + get_id_at(theId)); } //! Get range of the order numbers @@ -126,40 +142,46 @@ namespace MED //--------------------------------------------------------------- //! This class extend TCSlice functionality for non-constant case - template<class TContainer> - class TSlice: public TCSlice<TContainer> + template<class TValueType> + class TSlice: public TCSlice<TValueType> { - typedef TContainer* PContainer; - PContainer myContainer; + TValueType* myValuePtr; public: - typedef typename TContainer::value_type value_type; - typedef TCSlice<TContainer> TSupperClass; + typedef TValueType value_type; + typedef TCSlice<TValueType> TSupperClass; - //! Construct the class - TSlice(TContainer& theContainer, + //! Construct the class from bare pointer + TSlice(value_type* theValuePtr, + size_t theSourceSize, const std::slice& theSlice): - TSupperClass(theContainer,theSlice), - myContainer(&theContainer) - { - } + TSupperClass(theValuePtr, theSourceSize, theSlice), + myValuePtr(theValuePtr) + {} + + //! Construct the class from corresponding container + TSlice(TVector<value_type>& theContainer, + const std::slice& theSlice): + TSupperClass(theContainer, theSlice), + myValuePtr(&theContainer[0]) + {} //! Default constructor (dangerous) TSlice(): - myContainer(NULL) + myValuePtr(NULL) {} //! Get element by its number value_type& operator[](size_t theId) { - return (*myContainer)[this->get_id(theId)]; + return *(myValuePtr + this->get_id(theId)); } value_type& at(size_t theId) { - return (*myContainer)[this->get_id_at(theId)]; + return *(myValuePtr + this->get_id_at(theId)); } }; diff --git a/src/MEDWrapper/Base/MED_Structures.cxx b/src/MEDWrapper/Base/MED_Structures.cxx index c8e316a9f..a00690550 100644 --- a/src/MEDWrapper/Base/MED_Structures.cxx +++ b/src/MEDWrapper/Base/MED_Structures.cxx @@ -40,6 +40,18 @@ namespace MED strncpy(aPos,theValue.c_str(),aSize); } + void + SetString(TInt theId, + TInt theStep, + TString& theString, + const TString& theValue) + { + TInt aSize = std::min(TInt(theValue.size()+1),theStep); + char* aPos = &theString[theId*theStep]; + const char* aValue = &theValue[0]; + strncpy(aPos,aValue,aSize); + } + TInt GetDimGaussCoord(EGeometrieElement theGeom) { @@ -52,6 +64,18 @@ namespace MED return (theGeom%100); } + //--------------------------------------------------------------- + PFloatTimeStampValue + CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue) + { + return theTimeStampValue; + } + + PIntTimeStampValue + CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue) + { + return theTimeStampValue; + } } //--------------------------------------------------------------- @@ -88,21 +112,28 @@ TInt TElemInfo ::GetFamNum(TInt theId) const { - return myFamNum[theId]; + return (*myFamNum)[theId]; +} + +void +TElemInfo +::SetFamNum(TInt theId, TInt theVal) +{ + (*myFamNum)[theId] = theVal; } TInt TElemInfo ::GetElemNum(TInt theId) const { - return myElemNum[theId]; + return (*myElemNum)[theId]; } void TElemInfo -::SetFamNum(TInt theId,TInt theVal) +::SetElemNum(TInt theId, TInt theVal) { - myFamNum[theId] = theVal; + (*myElemNum)[theId] = theVal; } //--------------------------------------------------------------- @@ -112,9 +143,9 @@ TNodeInfo { TInt aDim = myMeshInfo->GetDim(); if(GetModeSwitch() == eFULL_INTERLACE) - return TCCoordSlice(myCoord,std::slice(theId*aDim,aDim,1)); + return TCCoordSlice(*myCoord, std::slice(theId*aDim, aDim, 1)); else - return TCCoordSlice(myCoord,std::slice(theId,aDim,aDim)); + return TCCoordSlice(*myCoord, std::slice(theId, aDim, aDim)); } TCoordSlice @@ -123,9 +154,9 @@ TNodeInfo { TInt aDim = myMeshInfo->GetDim(); if(GetModeSwitch() == eFULL_INTERLACE) - return TCoordSlice(myCoord,std::slice(theId*aDim,aDim,1)); + return TCoordSlice(*myCoord, std::slice(theId*aDim,aDim,1)); else - return TCoordSlice(myCoord,std::slice(theId,aDim,aDim)); + return TCoordSlice(*myCoord, std::slice(theId,aDim,aDim)); } //--------------------------------------------------------------- @@ -134,9 +165,9 @@ TCellInfo ::GetConnSlice(TInt theElemId) const { if(GetModeSwitch() == eFULL_INTERLACE) - return TCConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbNodes(myGeom),1)); + return TCConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1)); else - return TCConnSlice(myConn,std::slice(theElemId,GetNbNodes(myGeom),GetConnDim())); + return TCConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim())); } TConnSlice @@ -144,9 +175,9 @@ TCellInfo ::GetConnSlice(TInt theElemId) { if(GetModeSwitch() == eFULL_INTERLACE) - return TConnSlice(myConn,std::slice(GetConnDim()*theElemId,GetNbNodes(myGeom),1)); + return TConnSlice(*myConn, std::slice(GetConnDim()*theElemId, GetNbNodes(myGeom), 1)); else - return TConnSlice(myConn,std::slice(theElemId,GetNbNodes(myGeom),GetConnDim())); + return TConnSlice(*myConn, std::slice(theElemId, GetNbNodes(myGeom), GetConnDim())); } @@ -155,21 +186,21 @@ TInt TPolygoneInfo ::GetNbConn(TInt theElemId) const { - return myIndex[theElemId + 1] - myIndex[theElemId]; + return (*myIndex)[theElemId + 1] - (*myIndex)[theElemId]; } TCConnSlice TPolygoneInfo ::GetConnSlice(TInt theElemId) const { - return TCConnSlice(myConn,std::slice(myIndex[theElemId]-1,GetNbConn(theElemId),1)); + return TCConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1)); } TConnSlice TPolygoneInfo ::GetConnSlice(TInt theElemId) { - return TConnSlice(myConn,std::slice(myIndex[theElemId]-1,GetNbConn(theElemId),1)); + return TConnSlice(*myConn, std::slice((*myIndex)[theElemId] - 1, GetNbConn(theElemId), 1)); } @@ -178,7 +209,7 @@ TInt TPolyedreInfo ::GetNbFaces(TInt theElemId) const { - return myIndex[theElemId+1] - myIndex[theElemId]; + return (*myIndex)[theElemId+1] - (*myIndex)[theElemId]; } TInt @@ -187,10 +218,10 @@ TPolyedreInfo { TInt aNbNodes = 0; TInt aNbFaces = GetNbFaces(theElemId); - TInt aStartFaceId = myIndex[theElemId] - 1; + TInt aStartFaceId = (*myIndex)[theElemId] - 1; for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){ - TInt aCurrentId = myFaces[aStartFaceId]; - TInt aDiff = myFaces[aStartFaceId + 1] - aCurrentId; + TInt aCurrentId = (*myFaces)[aStartFaceId]; + TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId; aNbNodes += aDiff; } return aNbNodes; @@ -202,12 +233,12 @@ TPolyedreInfo { TInt aNbFaces = GetNbFaces(theElemId); TCConnSliceArr aConnSliceArr(aNbFaces); - TInt aStartFaceId = myIndex[theElemId] - 1; + TInt aStartFaceId = (*myIndex)[theElemId] - 1; for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){ - TInt aCurrentId = myFaces[aStartFaceId]; - TInt aDiff = myFaces[aStartFaceId + 1] - aCurrentId; + TInt aCurrentId = (*myFaces)[aStartFaceId]; + TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId; aConnSliceArr[aFaceId] = - TCConnSlice(myConn,std::slice(aCurrentId - 1,aDiff,1)); + TCConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1)); } return aConnSliceArr; } @@ -218,30 +249,84 @@ TPolyedreInfo { TInt aNbFaces = GetNbFaces(theElemId); TConnSliceArr aConnSliceArr(aNbFaces); - TInt aStartFaceId = myIndex[theElemId] - 1; + TInt aStartFaceId = (*myIndex)[theElemId] - 1; for(TInt aFaceId = 0; aFaceId < aNbFaces; aFaceId++, aStartFaceId++){ - TInt aCurrentId = myFaces[aStartFaceId]; - TInt aDiff = myFaces[aStartFaceId + 1] - aCurrentId; + TInt aCurrentId = (*myFaces)[aStartFaceId]; + TInt aDiff = (*myFaces)[aStartFaceId + 1] - aCurrentId; aConnSliceArr[aFaceId] = - TConnSlice(myConn,std::slice(aCurrentId - 1,aDiff,1)); + TConnSlice(*myConn, std::slice(aCurrentId - 1, aDiff, 1)); } return aConnSliceArr; } +//--------------------------------------------------------------- +TMeshValueBase +::TMeshValueBase(): + myNbElem(0), + myNbComp(0), + myNbGauss(0), + myStep(0) +{} + +void +TMeshValueBase +::Allocate(TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode) +{ + myModeSwitch = theMode; + + myNbElem = theNbElem; + myNbGauss = theNbGauss; + myNbComp = theNbComp; + + myStep = theNbComp*theNbGauss; +} + +size_t +TMeshValueBase +::GetSize() const +{ + return myNbElem * myStep; +} + +size_t +TMeshValueBase +::GetNbVal() const +{ + return myNbElem * myNbGauss; +} + +size_t +TMeshValueBase +::GetNbGauss() const +{ + return myNbGauss; +} + +size_t +TMeshValueBase +::GetStep() const +{ + return myStep; +} + + //--------------------------------------------------------------- TInt TProfileInfo ::GetElemNum(TInt theId) const { - return myElemNum[theId]; + return (*myElemNum)[theId]; } void TProfileInfo ::SetElemNum(TInt theId,TInt theVal) { - myElemNum[theId] = theVal; + (*myElemNum)[theId] = theVal; } //--------------------------------------------------------------- @@ -263,6 +348,12 @@ bool TGaussInfo::TLess ::operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const { + if(!&theLeft) + return true; + + if(!&theRight) + return false; + if(theLeft.myGeom != theRight.myGeom) return theLeft.myGeom < theRight.myGeom; @@ -326,137 +417,6 @@ TTimeStampInfo } -//--------------------------------------------------------------- -void -TMeshValue -::Init(TInt theNbElem, - TInt theNbGauss, - TInt theNbComp, - EModeSwitch theMode) -{ - myModeSwitch = theMode; - - myNbElem = theNbElem; - myNbGauss = theNbGauss; - myNbComp = theNbComp; - - myStep = theNbComp*theNbGauss; - - myValue.resize(theNbElem*myStep); -} - -//--------------------------------------------------------------- -TCValueSliceArr -TMeshValue -::GetGaussValueSliceArr(TInt theElemId) const -{ - TCValueSliceArr aValueSliceArr(myNbGauss); - if(GetModeSwitch() == eFULL_INTERLACE){ - TInt anId = theElemId*myStep; - for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TCValueSlice(myValue,std::slice(anId,myNbComp,1)); - anId += myNbComp; - } - } - else{ - for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TCValueSlice(myValue,std::slice(theElemId,myNbComp,myStep)); - } - } - return aValueSliceArr; -} - -TValueSliceArr -TMeshValue -::GetGaussValueSliceArr(TInt theElemId) -{ - TValueSliceArr aValueSliceArr(myNbGauss); - if(GetModeSwitch() == eFULL_INTERLACE){ - TInt anId = theElemId*myStep; - for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TValueSlice(myValue,std::slice(anId,myNbComp,1)); - anId += myNbComp; - } - } - else{ - for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TValueSlice(myValue,std::slice(theElemId,myNbComp,myStep)); - } - } - return aValueSliceArr; -} - -//--------------------------------------------------------------- -TCValueSliceArr -TMeshValue -::GetCompValueSliceArr(TInt theElemId) const -{ - TCValueSliceArr aValueSliceArr(myNbComp); - if(GetModeSwitch() == eFULL_INTERLACE){ - TInt anId = theElemId*myStep; - for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ - aValueSliceArr[aCompId] = - TCValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp)); - anId += 1; - } - } - else{ - for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ - aValueSliceArr[aCompId] = - TCValueSlice(myValue,std::slice(theElemId,myNbGauss,myStep)); - } - } - return aValueSliceArr; -} - - -TValueSliceArr -TMeshValue -::GetCompValueSliceArr(TInt theElemId) -{ - if(GetModeSwitch() == eFULL_INTERLACE){ - TValueSliceArr aValueSliceArr(myNbComp); - TInt anId = theElemId*myStep; - for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ - aValueSliceArr[aCompId] = - TValueSlice(myValue,std::slice(anId,myNbGauss,myNbComp)); - anId += 1; - } - return aValueSliceArr; - } - else{ - TValueSliceArr aValueSliceArr(myNbGauss); - for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ - aValueSliceArr[aGaussId] = - TValueSlice(myValue,std::slice(theElemId,myNbComp,myStep)); - } - return aValueSliceArr; - } -} - - -//--------------------------------------------------------------- -const TMeshValue& -TTimeStampVal -::GetMeshValue(EGeometrieElement theGeom) const -{ - TGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom); - if(anIter == myGeom2Value.end()) - EXCEPTION(runtime_error,"TTimeStampVal::GetMeshValue - myGeom2Value.find(theGeom) fails"); - return anIter->second; -} - -TMeshValue& -TTimeStampVal -::GetMeshValue(EGeometrieElement theGeom) -{ - return myGeom2Value[theGeom]; -} - //--------------------------------------------------------------- // TGrilleInfo structure methods //--------------------------------------------------------------- @@ -489,7 +449,7 @@ TGrilleInfo return myIndixes; } -TIndexes +TIndexes& TGrilleInfo ::GetMapOfIndexes() { @@ -503,17 +463,17 @@ TGrilleInfo { TIndexes::const_iterator aIter=myIndixes.find(theAxisNumber); if(aIter==myIndixes.end()) - EXCEPTION(runtime_error,"const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails"); + EXCEPTION(std::runtime_error, "const TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails"); return aIter->second; } -TFloatVector +TFloatVector& TGrilleInfo ::GetIndexes(TInt theAxisNumber) { TIndexes::iterator aIter=myIndixes.find(theAxisNumber); if(aIter==myIndixes.end()) - EXCEPTION(runtime_error,"TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber); fails"); + EXCEPTION(std::runtime_error, "TGrilleInfo::GetIndexes - myIndixes.find(theAxisNumber="<<theAxisNumber<<"); fails"); return aIter->second; } @@ -534,9 +494,9 @@ TGrilleInfo if(myGrilleType == eGRILLE_STANDARD) for(int i=0;i<aDim;i++) if(nbNodes == 0) - nbNodes = myGrilleStructure[i]; + nbNodes = this->GetGrilleStructure()[i]; else - nbNodes = nbNodes*myGrilleStructure[i]; + nbNodes = nbNodes*this->GetGrilleStructure()[i]; else for(int i=0;i<aDim;i++) if(nbNodes == 0) @@ -553,12 +513,12 @@ TGrilleInfo { TInt nbCells=0; TInt aDim = myMeshInfo->GetDim(); - if(myGrilleType == eGRILLE_STANDARD) + if(this->GetGrilleType() == eGRILLE_STANDARD) for(int i=0;i<aDim;i++) if(nbCells == 0) - nbCells = myGrilleStructure[i]-1; + nbCells = this->GetGrilleStructure()[i]-1; else - nbCells = nbCells*(myGrilleStructure[i]-1); + nbCells = nbCells*(this->GetGrilleStructure()[i]-1); else for(int i=0;i<aDim;i++) if(nbCells == 0) @@ -623,7 +583,7 @@ TGrilleInfo return myCoord; } -TNodeCoord +TNodeCoord& TGrilleInfo ::GetNodeCoord() { @@ -640,7 +600,7 @@ TGrilleInfo aCoord.resize(aDim); if(theId >= aNbNodes) - EXCEPTION(runtime_error,"TGrilleInfo::GetCoord - theId out of range"); + EXCEPTION(std::runtime_error, "TGrilleInfo::GetCoord - theId out of range"); if(myGrilleType == eGRILLE_STANDARD){ switch(aDim){ @@ -776,3 +736,31 @@ TGrilleInfo return anIndexes; } + +TInt +TGrilleInfo +::GetFamNumNode(TInt theId) const +{ + return myFamNumNode[theId]; +} + +void +TGrilleInfo +::SetFamNumNode(TInt theId,TInt theVal) +{ + myFamNumNode[theId] = theVal; +} + +TInt +TGrilleInfo +::GetFamNum(TInt theId) const +{ + return myFamNum[theId]; +} + +void +TGrilleInfo +::SetFamNum(TInt theId,TInt theVal) +{ + myFamNum[theId] = theVal; +} diff --git a/src/MEDWrapper/Base/MED_Structures.hxx b/src/MEDWrapper/Base/MED_Structures.hxx index 549c63327..ee0e0e3e9 100644 --- a/src/MEDWrapper/Base/MED_Structures.hxx +++ b/src/MEDWrapper/Base/MED_Structures.hxx @@ -30,6 +30,7 @@ #define MED_Structures_HeaderFile #include "MED_Common.hxx" +#include "MED_Utilities.hxx" namespace MED { @@ -37,19 +38,31 @@ namespace MED //--------------------------------------------------------------- //! Defines a type for managing sequence of strings typedef TVector<char> TString; + typedef SharedPtr<TString> PString; //! Extract a substring from the sequence of the strings - std::string GetString(TInt theId, TInt theStep, - const TString& theString); - + MEDWRAPPER_EXPORT + std::string + GetString(TInt theId, TInt theStep, + const TString& theString); + //! Set a substring in the sequence of the strings - void SetString(TInt theId, TInt theStep, + MEDWRAPPER_EXPORT + void + SetString(TInt theId, TInt theStep, TString& theString, const std::string& theValue); + //! Set a substring in the sequence of the strings + MEDWRAPPER_EXPORT + void + SetString(TInt theId, TInt theStep, + TString& theString, + const TString& theValue); + //--------------------------------------------------------------- //! Define a parent class for all MEDWrapper classes - struct TBase + struct MEDWRAPPER_EXPORT TBase { virtual ~TBase() {} }; @@ -57,11 +70,12 @@ namespace MED //--------------------------------------------------------------- //! Define a parent class for all named MED entities - struct TNameInfo: virtual TBase + struct MEDWRAPPER_EXPORT TNameInfo: virtual TBase { TString myName; //!< Keeps its name virtual std::string GetName() const = 0; //!< Gets its name virtual void SetName(const std::string& theValue) = 0; //!< Set a new name + virtual void SetName(const TString& theValue) = 0; //!< Set a new name }; @@ -71,7 +85,7 @@ namespace MED It defines through corresponding enumeration (EModeSwitch) how the sequence should be interpreted in C or Fortran mode (eFULL_INTERLACE or eNON_INTERLACE). */ - struct TModeSwitchInfo: virtual TBase + struct MEDWRAPPER_EXPORT TModeSwitchInfo: virtual TBase { //! To construct instance of the class by default TModeSwitchInfo(): @@ -90,7 +104,7 @@ namespace MED //--------------------------------------------------------------- //! Define a base class which represents MED Mesh entity - struct TMeshInfo: virtual TNameInfo + struct MEDWRAPPER_EXPORT TMeshInfo: virtual TNameInfo { TInt myDim; //!< Dimension of the mesh (0, 1, 2 or 3) TInt GetDim() const { return myDim;} //!< Gets dimension of the mesh @@ -106,13 +120,13 @@ namespace MED //--------------------------------------------------------------- typedef TVector<TInt> TIntVector; - typedef TSlice<TIntVector> TIntVecSlice; - typedef TCSlice<TIntVector> TCIntVecSlice; + typedef TSlice<TInt> TIntVecSlice; + typedef TCSlice<TInt> TCIntVecSlice; typedef TIntVector TFamAttr; //! Define a base class which represents MED Family entity - struct TFamilyInfo: virtual TNameInfo + struct MEDWRAPPER_EXPORT TFamilyInfo: virtual TNameInfo { PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh //! Get a reference to corresponding MED Mesh @@ -162,9 +176,10 @@ namespace MED //--------------------------------------------------------------- typedef TIntVector TElemNum; + typedef SharedPtr<TElemNum> PElemNum; //! Define a parent class for all MED entities that describes mesh entites such as nodes and cells. - struct TElemInfo: virtual TBase + struct MEDWRAPPER_EXPORT TElemInfo: virtual TBase { PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh //! Get a reference to corresponding MED Mesh @@ -174,7 +189,7 @@ namespace MED TInt GetNbElem() const { return myNbElem;} //! Get number of mesh elements //! Defines sequence MED Family indexes for corresponding mesh entites - TElemNum myFamNum; + PElemNum myFamNum; //! Get number of a MED FAMILY by order number of the mesh element TInt GetFamNum(TInt theId) const; //! Set number of a MED FAMILY for the mesh element with the order number @@ -186,7 +201,7 @@ namespace MED EBooleen IsElemNum() const { return myIsElemNum;} //! Contains sequence of the indexes for the mesh elements - TElemNum myElemNum; + PElemNum myElemNum; //! Get a reference number of the mesh element by its order number TInt GetElemNum(TInt theId) const; //! Set a reference number for the mesh element by its order number @@ -198,7 +213,7 @@ namespace MED EBooleen IsElemNames() const { return myIsElemNames;} //! Contains sequence of the names for the mesh elements - TString myElemNames; + PString myElemNames; //! Get name of the mesh element by its order number virtual std::string GetElemName(TInt theId) const = 0; //! Set name of the mesh element by its order number @@ -208,19 +223,21 @@ namespace MED //--------------------------------------------------------------- typedef TVector<TFloat> TFloatVector; - typedef TSlice<TFloatVector> TFloatVecSlice; - typedef TCSlice<TFloatVector> TCFloatVecSlice; + typedef TSlice<TFloat> TFloatVecSlice; + typedef TCSlice<TFloat> TCFloatVecSlice; typedef TFloatVector TNodeCoord; + typedef SharedPtr<TNodeCoord> PNodeCoord; + typedef TFloatVecSlice TCoordSlice; typedef TCFloatVecSlice TCCoordSlice; //! Define a base class which represents MED Nodes entity - struct TNodeInfo: + struct MEDWRAPPER_EXPORT TNodeInfo: virtual TElemInfo, virtual TModeSwitchInfo { - TNodeCoord myCoord; //!< Contains all nodal coordinates + PNodeCoord myCoord; //!< Contains all nodal coordinates //! Gives coordinates for mesh node by its number (const version) TCCoordSlice GetCoordSlice(TInt theId) const; @@ -252,7 +269,7 @@ namespace MED typedef TCIntVecSlice TCConnSlice; //! Define a base class which represents MED Cells entity - struct TCellInfo: + struct MEDWRAPPER_EXPORT TCellInfo: virtual TElemInfo, virtual TModeSwitchInfo { @@ -270,7 +287,7 @@ namespace MED virtual TInt GetConnDim() const = 0; //!< Gives step in the connectivity sequence - TElemNum myConn; //!< Defines sequence which describe connectivity for ech of mesh cell + PElemNum myConn; //!< Defines sequence which describe connectivity for ech of mesh cell //! Gives connectivities for mesh cell by its number (const version) TCConnSlice GetConnSlice(TInt theElemId) const; @@ -280,7 +297,7 @@ namespace MED //--------------------------------------------------------------- //! Define a base class which represents MED Polygon entity - struct TPolygoneInfo: + struct MEDWRAPPER_EXPORT TPolygoneInfo: virtual TElemInfo { //! Defines the MED Entity where the polygons belongs to @@ -298,8 +315,8 @@ namespace MED //! Let known in what connectivity the cells are writen EConnectivite GetConnMode() const { return myConnMode;} - TElemNum myConn; //!< Table de connectivities - TElemNum myIndex; //!< Table de indexes + PElemNum myConn; //!< Table de connectivities + PElemNum myIndex; //!< Table de indexes //! Gives number of the connectivities for the defined polygon TInt GetNbConn(TInt theElemId) const; @@ -315,7 +332,7 @@ namespace MED typedef TVector<TConnSlice> TConnSliceArr; //! Define a base class which represents MED Polyedre entity - struct TPolyedreInfo: + struct MEDWRAPPER_EXPORT TPolyedreInfo: virtual TElemInfo { //! Defines the MED Entity where the polyedres belongs to @@ -333,9 +350,9 @@ namespace MED //! Let known in what connectivity the cells are writen EConnectivite GetConnMode() const { return myConnMode;} - TElemNum myConn; //!< Table de connectivities - TElemNum myFaces; //!< Table de faces indexes - TElemNum myIndex; //!< Table de indexes + PElemNum myConn; //!< Table de connectivities + PElemNum myFaces; //!< Table de faces indexes + PElemNum myIndex; //!< Table de indexes //! Gives number of the faces for the defined polyedre (const version) TInt GetNbFaces(TInt theElemId) const; @@ -350,7 +367,7 @@ namespace MED //--------------------------------------------------------------- //! Define a base class which represents MED Field entity - struct TFieldInfo: + struct MEDWRAPPER_EXPORT TFieldInfo: virtual TNameInfo { PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh @@ -389,23 +406,25 @@ namespace MED //--------------------------------------------------------------- //! Get dimension of the Gauss coordinates for the defined type of mesh cell + MEDWRAPPER_EXPORT TInt GetDimGaussCoord(EGeometrieElement theGeom); //! Get number of referenced nodes for the defined type of mesh cell + MEDWRAPPER_EXPORT TInt GetNbRefCoord(EGeometrieElement theGeom); typedef TFloatVector TWeight; //! The class represents MED Gauss entity - struct TGaussInfo: + struct MEDWRAPPER_EXPORT TGaussInfo: virtual TNameInfo, virtual TModeSwitchInfo { typedef boost::tuple<EGeometrieElement,std::string> TKey; typedef boost::tuple<TKey,TInt> TInfo; - struct TLess + struct MEDWRAPPER_EXPORT TLess { bool operator()(const TKey& theLeft, const TKey& theRight) const; @@ -445,7 +464,7 @@ namespace MED TInt GetDim() const { return GetDimGaussCoord(GetGeom());} //! Gives number of the Gauss Points - TInt GetNbGauss() const { return myGaussCoord.size()/GetDim();} + TInt GetNbGauss() const { return (TInt)(myGaussCoord.size()/GetDim());} }; @@ -454,7 +473,7 @@ namespace MED typedef std::map<EGeometrieElement,TInt> TGeom2NbGauss; //! Define a base class which represents MED TimeStamp - struct TTimeStampInfo: + struct MEDWRAPPER_EXPORT TTimeStampInfo: virtual TBase { PFieldInfo myFieldInfo; //!< A reference to correspondig MED Field @@ -498,7 +517,7 @@ namespace MED //--------------------------------------------------------------- //! The class represents MED Profile entity - struct TProfileInfo: + struct MEDWRAPPER_EXPORT TProfileInfo: virtual TNameInfo { typedef std::string TKey; @@ -510,7 +529,7 @@ namespace MED //! Set mode for the MED Profile void SetMode(EModeProfil theMode) { myMode = theMode;} - TElemNum myElemNum; //!< Keeps sequence of cell by its number which belong to the profile + PElemNum myElemNum; //!< Keeps sequence of cell by its number which belong to the profile //! Get number of mesh elelemts by its order number TInt GetElemNum(TInt theId) const; //! Set number of mesh elelemts by its order number @@ -520,86 +539,420 @@ namespace MED bool IsPresent() const { return GetName() != "";} //! Let known size of the MED Profile - TInt GetSize() const { return myElemNum.size();} + TInt GetSize() const { return (TInt)myElemNum->size();} }; //--------------------------------------------------------------- - typedef TFloatVector TValue; - typedef TSlice<TValue> TValueSlice; - typedef TCSlice<TValue> TCValueSlice; - - typedef TVector<TCValueSlice> TCValueSliceArr; - typedef TVector<TValueSlice> TValueSliceArr; - //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp - struct TMeshValue: + struct MEDWRAPPER_EXPORT TMeshValueBase: virtual TModeSwitchInfo { - TValue myValue; - TInt myNbElem; TInt myNbComp; TInt myNbGauss; TInt myStep; + TMeshValueBase(); + + //! Initialize the class + void + Allocate(TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE); + + //! Returns size of the value container + size_t + GetSize() const; + + //! Returns MED interpetation of the value size + size_t + GetNbVal() const; + + //! Returns number of Gauss Points bounded with the value + size_t + GetNbGauss() const; + + //! Returns step inside of the data array + size_t + GetStep() const; + + //! Returns bare pointer on the internal value representation + virtual + unsigned char* + GetValuePtr() = 0; + }; + + //--------------------------------------------------------------- + //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp + template<class TValueType> + struct TTMeshValue: + virtual TMeshValueBase + { + typedef TValueType TValue; + typedef typename TValueType::value_type TElement; + + typedef TSlice<TElement> TValueSlice; + typedef TCSlice<TElement> TCValueSlice; + + typedef TVector<TCValueSlice> TCValueSliceArr; + typedef TVector<TValueSlice> TValueSliceArr; + + TValue myValue; + //! Initialize the class void - Init(TInt theNbElem, - TInt theNbGauss, - TInt theNbComp, - EModeSwitch theMode = eFULL_INTERLACE); + Allocate(TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE) + { + TMeshValueBase::Allocate(theNbElem, theNbGauss, theNbComp, theMode); + myValue.resize(theNbElem * this->GetStep()); + } + + //! Returns bare pointer on the internal value representation + virtual + unsigned char* + GetValuePtr() + { + return (unsigned char*)&myValue[0]; + } + + //! Returns bare pointer on the internal value representation + virtual + TElement* + GetPointer() + { + return &myValue[0]; + } + + //! Returns bare pointer on the internal value representation + virtual + const TElement* + GetPointer() const + { + return &myValue[0]; + } //! Iteration through Gauss Points by their components TCValueSliceArr - GetGaussValueSliceArr(TInt theElemId) const; + GetGaussValueSliceArr(TInt theElemId) const + { + TCValueSliceArr aValueSliceArr(myNbGauss); + if(GetModeSwitch() == eFULL_INTERLACE){ + TInt anId = theElemId * myStep; + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TCValueSlice(myValue, std::slice(anId, myNbComp, 1)); + anId += myNbComp; + } + } + else{ + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TCValueSlice(myValue, std::slice(theElemId, myNbComp, myStep)); + } + } + return aValueSliceArr; + } //! Iteration through Gauss Points by their components TValueSliceArr - GetGaussValueSliceArr(TInt theElemId); + GetGaussValueSliceArr(TInt theElemId) + { + TValueSliceArr aValueSliceArr(myNbGauss); + if(GetModeSwitch() == eFULL_INTERLACE){ + TInt anId = theElemId*myStep; + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue, std::slice(anId, myNbComp, 1)); + anId += myNbComp; + } + } + else{ + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue, std::slice(theElemId, myNbComp, myStep)); + } + } + return aValueSliceArr; + } //! Iteration through components by corresponding Gauss Points TCValueSliceArr - GetCompValueSliceArr(TInt theElemId) const; + GetCompValueSliceArr(TInt theElemId) const + { + TCValueSliceArr aValueSliceArr(myNbComp); + if(GetModeSwitch() == eFULL_INTERLACE){ + TInt anId = theElemId*myStep; + for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TCValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp)); + anId += 1; + } + } + else{ + for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TCValueSlice(myValue, std::slice(theElemId, myNbGauss, myStep)); + } + } + return aValueSliceArr; + } //! Iteration through components by corresponding Gauss Points TValueSliceArr - GetCompValueSliceArr(TInt theElemId); + GetCompValueSliceArr(TInt theElemId) + { + if(GetModeSwitch() == eFULL_INTERLACE){ + TValueSliceArr aValueSliceArr(myNbComp); + TInt anId = theElemId*myStep; + for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp)); + anId += 1; + } + return aValueSliceArr; + } + else{ + TValueSliceArr aValueSliceArr(myNbGauss); + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue,std::slice(theElemId, myNbComp, myStep)); + } + return aValueSliceArr; + } + } }; + typedef TTMeshValue<TFloatVector> TFloatMeshValue; + typedef TTMeshValue<TIntVector> TIntMeshValue; //--------------------------------------------------------------- + // Backward compatibility declarations + typedef TFloatVector TValue; + typedef TSlice<TFloat> TValueSlice; + typedef TCSlice<TFloat> TCValueSlice; + + typedef TVector<TCValueSlice> TCValueSliceArr; + typedef TVector<TValueSlice> TValueSliceArr; + + typedef TFloatMeshValue TMeshValue; typedef std::map<EGeometrieElement,TMeshValue> TGeom2Value; + + //--------------------------------------------------------------- typedef std::map<EGeometrieElement,PProfileInfo> TGeom2Profile; + typedef std::set<EGeometrieElement> TGeom; - //! The class implements a container for MED TimeStamp values - struct TTimeStampVal: + //! The class is a base class for MED TimeStamp values holder + struct MEDWRAPPER_EXPORT TTimeStampValueBase: virtual TModeSwitchInfo { - PTimeStampInfo myTimeStampInfo; //!< A reference to correspondig MED TimeStamp + //! A reference to correspondig MED TimeStamp + PTimeStampInfo myTimeStampInfo; //!< Get a reference to correspondig MED TimeStamp const PTimeStampInfo& GetTimeStampInfo() const { return myTimeStampInfo;} + //! Keeps set of MED EGeometrieElement which contains values for the timestamp + TGeomSet myGeomSet; + const TGeomSet& GetGeomSet() const { return myGeomSet;} + //! Keeps map of MED Profiles per geometric type TGeom2Profile myGeom2Profile; //! Gets a map of MED Profiles per geometric type const TGeom2Profile& GetGeom2Profile() const { return myGeom2Profile;} - TGeom2Value myGeom2Value; + //! Gets type of the champ + virtual + ETypeChamp + GetTypeChamp() const = 0; + + //! Allocates values for the given geometry + virtual + void + AllocateValue(EGeometrieElement theGeom, + TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE) = 0; + + virtual + size_t + GetValueSize(EGeometrieElement theGeom) const = 0; + + virtual + size_t + GetNbVal(EGeometrieElement theGeom) const = 0; + + virtual + size_t + GetNbGauss(EGeometrieElement theGeom) const = 0; + + virtual + unsigned char* + GetValuePtr(EGeometrieElement theGeom) = 0; + }; + + + //--------------------------------------------------------------- + //! The class implements a container for MED TimeStamp values + template<class TMeshValueType> + struct TTimeStampValue: + virtual TTimeStampValueBase + { + typedef TMeshValueType TTMeshValue; + typedef SharedPtr<TMeshValueType> PTMeshValue; + typedef typename TMeshValueType::TElement TElement; + typedef std::map<EGeometrieElement, PTMeshValue> TTGeom2Value; + + ETypeChamp myTypeChamp; //<! Keeps type of the champ + + //! Gets type of the champ + virtual + ETypeChamp + GetTypeChamp() const + { + return myTypeChamp; + } //! Keeps map of MED TimeStamp values per geometric type (const version) - const TMeshValue& GetMeshValue(EGeometrieElement theGeom) const; + TTGeom2Value myGeom2Value; + + const TTGeom2Value& + GetGeom2Value() const + { + return myGeom2Value; + } + + //! Gets MED TimeStamp values for the given geometric type (const version) + const PTMeshValue& + GetMeshValuePtr(EGeometrieElement theGeom) const + { + typename TTGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom); + if(anIter == myGeom2Value.end()) + EXCEPTION(std::runtime_error,"TTimeStampValue::GetMeshValuePtr - myGeom2Value.find(theGeom) fails"); + return anIter->second; + } + + //! Gets MED TimeStamp values for the given geometric type + PTMeshValue& + GetMeshValuePtr(EGeometrieElement theGeom) + { + myGeomSet.insert(theGeom); + if(myGeom2Value.find(theGeom) == myGeom2Value.end()){ + myGeom2Value[theGeom] = PTMeshValue(new TTMeshValue()); + return myGeom2Value[theGeom]; + } + return myGeom2Value[theGeom]; + } + + //! Gets MED TimeStamp values for the given geometric type (const version) + const TTMeshValue& + GetMeshValue(EGeometrieElement theGeom) const + { + return *(this->GetMeshValuePtr(theGeom)); + } - //! Keeps map of MED TimeStamp values per geometric type - TMeshValue& GetMeshValue(EGeometrieElement theGeom); + //! Gets MED TimeStamp values for the given geometric type + TTMeshValue& + GetMeshValue(EGeometrieElement theGeom) + { + return *(this->GetMeshValuePtr(theGeom)); + } }; + //--------------------------------------------------------------- + typedef TTimeStampValue<TFloatMeshValue> TFloatTimeStampValue; + typedef SharedPtr<TFloatTimeStampValue> PFloatTimeStampValue; + + PFloatTimeStampValue MEDWRAPPER_EXPORT + CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue); + + typedef TTimeStampValue<TIntMeshValue> TIntTimeStampValue; + typedef SharedPtr<TIntTimeStampValue> PIntTimeStampValue; + + PIntTimeStampValue MEDWRAPPER_EXPORT + CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue); + + + //--------------------------------------------------------------- + template<class TMeshValueTypeFrom, class TMeshValueTypeTo> + void + CopyTimeStampValue(SharedPtr<TTimeStampValue<TMeshValueTypeFrom> > theTimeStampValueFrom, + SharedPtr<TTimeStampValue<TMeshValueTypeTo> > theTimeStampValueTo) + { + typedef TTimeStampValue<TMeshValueTypeFrom> TimeStampValueTypeFrom; + typedef TTimeStampValue<TMeshValueTypeTo> TimeStampValueTypeTo; + typedef typename TMeshValueTypeTo::TElement TElementTo; + + typename TimeStampValueTypeFrom::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value; + typename TimeStampValueTypeFrom::TTGeom2Value::const_iterator anIter = aGeom2Value.begin(); + for(; anIter != aGeom2Value.end(); anIter++){ + const EGeometrieElement& aGeom = anIter->first; + const typename TimeStampValueTypeFrom::TTMeshValue& aMeshValue = *anIter->second; + typename TimeStampValueTypeTo::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom); + aMeshValue2.Allocate(aMeshValue.myNbElem, + aMeshValue.myNbGauss, + aMeshValue.myNbComp, + aMeshValue.myModeSwitch); + const typename TimeStampValueTypeFrom::TTMeshValue::TValue& aValue = aMeshValue.myValue; + typename TimeStampValueTypeTo::TTMeshValue::TValue& aValue2 = aMeshValue2.myValue; + TInt aSize = aValue.size(); + for(TInt anId = 0; anId < aSize; anId++) + aValue2[anId] = TElementTo(aValue[anId]); + } + } + + template<class TMeshValueType> + void + CopyTimeStampValue(SharedPtr<TTimeStampValue<TMeshValueType> > theTimeStampValueFrom, + SharedPtr<TTimeStampValue<TMeshValueType> > theTimeStampValueTo) + { + typedef TTimeStampValue<TMeshValueType> TimeStampValueType; + typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value; + typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin(); + for(; anIter != aGeom2Value.end(); anIter++){ + const EGeometrieElement& aGeom = anIter->first; + const typename TimeStampValueType::TTMeshValue& aMeshValue = *anIter->second; + typename TimeStampValueType::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom); + aMeshValue2 = aMeshValue; + } + } + + //--------------------------------------------------------------- + inline + void + CopyTimeStampValueBase(const PTimeStampValueBase& theValueFrom, + const PTimeStampValueBase& theValueTo) + { + if(theValueFrom->GetTypeChamp() == theValueTo->GetTypeChamp()){ + if(theValueFrom->GetTypeChamp() == eFLOAT64) + CopyTimeStampValue<TFloatMeshValue>(theValueFrom, theValueTo); + else if(theValueFrom->GetTypeChamp() == eINT) + CopyTimeStampValue<TIntMeshValue>(theValueFrom, theValueTo); + }else{ + if(theValueFrom->GetTypeChamp() == eFLOAT64 && theValueTo->GetTypeChamp() == eINT) + CopyTimeStampValue<TFloatMeshValue, TIntMeshValue>(theValueFrom, theValueTo); + else if(theValueFrom->GetTypeChamp() == eINT && theValueTo->GetTypeChamp() == eFLOAT64) + CopyTimeStampValue<TIntMeshValue, TFloatMeshValue>(theValueFrom, theValueTo); + } + } + + + //--------------------------------------------------------------- + // Backward compatibility declarations + typedef TFloatTimeStampValue TTimeStampVal; + typedef PFloatTimeStampValue PTimeStampVal; + + //--------------------------------------------------------------- typedef std::map<TInt,TFloatVector> TIndexes; typedef std::map<TInt,TString> TNames; //! Define a base class which represents MED Grille - struct TGrilleInfo: + struct MEDWRAPPER_EXPORT TGrilleInfo: virtual TModeSwitchInfo { @@ -609,7 +962,7 @@ namespace MED TNodeCoord myCoord; //!< Contains all nodal coordinates, now used only for eGRILLE_STANDARD //! Gives coordinates for mesh nodes (const version) const TNodeCoord& GetNodeCoord() const; - TNodeCoord GetNodeCoord(); + TNodeCoord& GetNodeCoord(); //! Gives coordinates for mesh node by its number, array index from 0 TNodeCoord GetCoord(TInt theId); //! Gives ids of nodes for mesh cell by its number, array index from 0 @@ -643,18 +996,18 @@ namespace MED //!Gets a map of Tables (const version) const TIndexes& GetMapOfIndexes() const ; //!Gets a map of Tables - TIndexes GetMapOfIndexes(); + TIndexes& GetMapOfIndexes(); //!Gets a Table of indexes for certain axe(const version) const TFloatVector& GetIndexes(TInt theAxisNumber) const; //!Gets a Table of indexes for certain axe - TFloatVector GetIndexes(TInt theAxisNumber); + TFloatVector& GetIndexes(TInt theAxisNumber); //!Gets a number of indices per axe TInt GetNbIndexes(TInt theAxisNumber); TInt GetNbNodes();//! Return count of all points TInt GetNbCells();//! Return count of all cells EGeometrieElement GetGeom();//! Return geometry of cells (calculated from mesh dimension) - EEntiteMaillage GetEntity();//! Return entity (eMAILLE) + EEntiteMaillage GetEntity();//! Return entity (eMAILLE) /*! *Vector of grille structure (Example: {3,4,5}, 3 nodes in X axe, 4 nodes in Y axe, ...) @@ -670,13 +1023,21 @@ namespace MED /*! *Defines sequence MED Family indexes for corresponding mesh entites - *Not used now. */ TElemNum myFamNum; //! Get number of a MED FAMILY by order number of the mesh element TInt GetFamNum(TInt theId) const; //! Set number of a MED FAMILY for the mesh element with the order number void SetFamNum(TInt theId, TInt theVal); + + /*! + *Defines sequence MED Family indexes for corresponding mesh nodes + */ + TElemNum myFamNumNode; + //! Get number of a MED FAMILY by order number of the mesh node + TInt GetFamNumNode(TInt theId) const; + //! Set number of a MED FAMILY for the mesh node with the order number + void SetFamNumNode(TInt theId, TInt theVal); }; diff --git a/src/MEDWrapper/Base/MED_TStructures.hxx b/src/MEDWrapper/Base/MED_TStructures.hxx index f9bd0ecd2..15794a80b 100644 --- a/src/MEDWrapper/Base/MED_TStructures.hxx +++ b/src/MEDWrapper/Base/MED_TStructures.hxx @@ -33,6 +33,66 @@ namespace MED { + //--------------------------------------------------------------- + //! To provide a common way to handle values of MEDWrapper types as native MED types + template<class TValue, class TRepresentation> + struct TValueHolder + { + TValue& myValue; + TRepresentation myRepresentation; + + TValueHolder(TValue& theValue): + myValue(theValue), + myRepresentation(TRepresentation(theValue)) + {} + + ~TValueHolder() + { + myValue = TValue(myRepresentation); + } + + TRepresentation* + operator& () + { + return &myRepresentation; + } + + operator TRepresentation () const + { + return myRepresentation; + } + + const TValue& + operator() () const + { + return myValue; + } + }; + + //! To customize TValueHolder common template definition for TVector + template<class TVal, class TRepresentation> + struct TValueHolder<TVector<TVal>, TRepresentation> + { + typedef TVector<TVal> TValue; + TValue& myValue; + TRepresentation* myRepresentation; + + TValueHolder(TValue& theValue): + myValue(theValue) + { + if(theValue.empty()) + myRepresentation = (TRepresentation*)NULL; + else + myRepresentation = (TRepresentation*)&theValue[0]; + } + + TRepresentation* + operator& () + { + return myRepresentation; + } + }; + //--------------------------------------------------------------- template<EVersion eVersion> struct TTNameInfo: virtual TNameInfo @@ -47,14 +107,21 @@ namespace MED std::string GetName() const { - return GetString(0,GetNOMLength<eVersion>(),myName); + return GetString(0, GetNOMLength<eVersion>(), myName); } virtual void SetName(const std::string& theValue) { - SetString(0,GetNOMLength<eVersion>(),myName,theValue); + SetString(0, GetNOMLength<eVersion>(), myName, theValue); + } + + virtual + void + SetName(const TString& theValue) + { + SetString(0, GetNOMLength<eVersion>(), myName, theValue); } }; @@ -94,14 +161,14 @@ namespace MED std::string GetDesc() const { - return GetString(0,GetDESCLength<eVersion>(),myDesc); + return GetString(0, GetDESCLength<eVersion>(), myDesc); } virtual void SetDesc(const std::string& theValue) { - SetString(0,GetDESCLength<eVersion>(),myDesc,theValue); + SetString(0, GetDESCLength<eVersion>(), myDesc, theValue); } }; @@ -175,7 +242,7 @@ namespace MED myId = theId; - myNbGroup = theGroupNames.size(); + myNbGroup = (TInt)theGroupNames.size(); myGroupNames.resize(myNbGroup*GetLNOMLength<eVersion>()+1); if(myNbGroup){ TStringSet::const_iterator anIter = theGroupNames.begin(); @@ -185,12 +252,12 @@ namespace MED } } - myNbAttr = theAttrDescs.size(); + myNbAttr = (TInt)theAttrDescs.size(); myAttrId.resize(myNbAttr); myAttrVal.resize(myNbAttr); myAttrDesc.resize(myNbAttr*GetDESCLength<eVersion>()+1); if(myNbAttr){ - for(TInt anId = 0, anEnd = theAttrDescs.size(); anId < anEnd; anId++){ + for(TInt anId = 0, anEnd = (TInt)theAttrDescs.size(); anId < anEnd; anId++){ SetAttrDesc(anId,theAttrDescs[anId]); myAttrVal[anId] = theAttrVals[anId]; myAttrId[anId] = theAttrIds[anId]; @@ -202,28 +269,28 @@ namespace MED std::string GetGroupName(TInt theId) const { - return GetString(theId,GetLNOMLength<eVersion>(),myGroupNames); + return GetString(theId, GetLNOMLength<eVersion>(), myGroupNames); } virtual void SetGroupName(TInt theId, const std::string& theValue) { - SetString(theId,GetLNOMLength<eVersion>(),myGroupNames,theValue); + SetString(theId, GetLNOMLength<eVersion>(), myGroupNames, theValue); } virtual std::string GetAttrDesc(TInt theId) const { - return GetString(theId,GetDESCLength<eVersion>(),myAttrDesc); + return GetString(theId, GetDESCLength<eVersion>(), myAttrDesc); } virtual void SetAttrDesc(TInt theId, const std::string& theValue) { - SetString(theId,GetDESCLength<eVersion>(),myAttrDesc,theValue); + SetString(theId, GetDESCLength<eVersion>(), myAttrDesc, theValue); } }; @@ -237,24 +304,30 @@ namespace MED myMeshInfo = theMeshInfo; myNbElem = theInfo->GetNbElem(); - myFamNum.resize(myNbElem); + myFamNum.reset(new TElemNum(myNbElem)); myIsElemNum = theInfo->IsElemNum(); - myElemNum.resize(myIsElemNum == eFAUX? 0: myNbElem); + if(theInfo->IsElemNum()) + myElemNum.reset(new TElemNum(myNbElem)); + else + myElemNum.reset(new TElemNum()); myIsElemNames = theInfo->IsElemNames(); - myElemNames.resize(myNbElem*GetPNOMLength<eVersion>()+1); + if(theInfo->IsElemNames()) + myElemNames.reset(new TString(myNbElem*GetPNOMLength<eVersion>() + 1)); + else + myElemNames.reset(new TString()); - if(myNbElem){ + if(theInfo->GetNbElem()){ for(TInt anId = 0; anId < myNbElem; anId++){ - myFamNum[anId] = theInfo->GetFamNum(anId); + SetFamNum(anId, theInfo->GetFamNum(anId)); } - if(myIsElemNum == eVRAI){ + if(theInfo->IsElemNum() == eVRAI){ for(TInt anId = 0; anId < myNbElem; anId++){ - myElemNum[anId] = theInfo->GetElemNum(anId); + SetElemNum(anId, theInfo->GetElemNum(anId)); } } - if(myIsElemNames == eVRAI){ + if(theInfo->IsElemNames() == eVRAI){ for(TInt anId = 0; anId < myNbElem; anId++){ SetElemName(anId,theInfo->GetElemName(anId)); } @@ -270,16 +343,20 @@ namespace MED myMeshInfo = theMeshInfo; myNbElem = theNbElem; - myFamNum.resize(theNbElem); + myFamNum.reset(new TElemNum(theNbElem)); myIsElemNum = theIsElemNum; if(theIsElemNum) - myElemNum.resize(theNbElem); + myElemNum.reset(new TElemNum(theNbElem)); + else + myElemNum.reset(new TElemNum()); myIsElemNames = theIsElemNames; if(theIsElemNames) - myElemNames.resize(theNbElem*GetPNOMLength<eVersion>()+1); - } + myElemNames.reset(new TString(theNbElem*GetPNOMLength<eVersion>() + 1)); + else + myElemNames.reset(new TString()); + } TTElemInfo(const PMeshInfo& theMeshInfo, TInt theNbElem, @@ -290,23 +367,27 @@ namespace MED myMeshInfo = theMeshInfo; myNbElem = theNbElem; + myFamNum.reset(new TElemNum(theNbElem)); myIsElemNum = theElemNums.size()? eVRAI: eFAUX; if(myIsElemNum) - myElemNum.resize(theNbElem); + myElemNum.reset(new TElemNum(theNbElem)); + else + myElemNum.reset(new TElemNum()); myIsElemNames = theElemNames.size()? eVRAI: eFAUX; if(myIsElemNames) - myElemNames.resize(theNbElem*GetPNOMLength<eVersion>()+1); - + myElemNames.reset(new TString(theNbElem*GetPNOMLength<eVersion>() + 1)); + else + myElemNames.reset(new TString()); + if(theNbElem){ - myFamNum.resize(theNbElem); if(theFamilyNums.size()) - myFamNum = theFamilyNums; + *myFamNum = theFamilyNums; if(myIsElemNum) - myElemNum = theElemNums; + *myElemNum = theElemNums; if(myIsElemNames){ for(TInt anId = 0; anId < theNbElem; anId++){ @@ -321,14 +402,14 @@ namespace MED std::string GetElemName(TInt theId) const { - return GetString(theId,GetPNOMLength<eVersion>(),myElemNames); + return GetString(theId,GetPNOMLength<eVersion>(), *myElemNames); } virtual void SetElemName(TInt theId, const std::string& theValue) { - SetString(theId,GetPNOMLength<eVersion>(),myElemNames,theValue); + SetString(theId,GetPNOMLength<eVersion>(), *myElemNames, theValue); } }; @@ -342,14 +423,14 @@ namespace MED typedef TTElemInfo<eVersion> TElemInfoBase; TTNodeInfo(const PMeshInfo& theMeshInfo, const PNodeInfo& theInfo): - TElemInfoBase(theMeshInfo,theInfo), + TElemInfoBase(theMeshInfo, theInfo), TNodeInfo(theInfo) { myModeSwitch = theInfo->GetModeSwitch(); mySystem = theInfo->GetSystem(); - myCoord = theInfo->myCoord; + myCoord.reset(new TNodeCoord(*theInfo->myCoord)); TInt aDim = theMeshInfo->GetDim(); @@ -376,7 +457,7 @@ namespace MED { mySystem = theSystem; - myCoord.resize(theNbElem*theMeshInfo->myDim); + myCoord.reset(new TNodeCoord(theNbElem * theMeshInfo->myDim)); if(theIsElemNum) myCoordUnits.resize(theMeshInfo->myDim*GetPNOMLength<eVersion>()+1); @@ -396,7 +477,7 @@ namespace MED const TIntVector& theElemNums, const TStringVector& theElemNames): TElemInfoBase(theMeshInfo, - theNodeCoords.size()/theMeshInfo->GetDim(), + (TInt)theNodeCoords.size()/theMeshInfo->GetDim(), theFamilyNums, theElemNums, theElemNames), @@ -404,7 +485,7 @@ namespace MED { mySystem = theSystem; - myCoord = theNodeCoords; + myCoord.reset(new TNodeCoord(theNodeCoords)); TInt aDim = theMeshInfo->GetDim(); @@ -413,10 +494,10 @@ namespace MED for(TInt anId = 0; anId < aDim; anId++) SetCoordName(anId,theCoordNames[anId]); - myCoordUnits.resize(aDim*GetPNOMLength<eVersion>()+1); + myCoordUnits.resize(aDim*GetPNOMLength<eVersion>() + 1); if(!theCoordUnits.empty()) for(TInt anId = 0; anId < aDim; anId++) - SetCoordUnit(anId,theCoordUnits[anId]); + SetCoordUnit(anId, theCoordUnits[anId]); } virtual @@ -462,8 +543,8 @@ namespace MED myEntity = theInfo->GetEntity(); myGeom = theInfo->GetGeom(); - myIndex = theInfo->myIndex; - myConn = theInfo->myConn; + myIndex.reset(new TElemNum(*theInfo->myIndex)); + myConn.reset(new TElemNum(*theInfo->myConn)); myConnMode = theInfo->GetConnMode(); } @@ -484,8 +565,8 @@ namespace MED myEntity = theEntity; myGeom = theGeom; - myIndex.resize(theNbElem+1); - myConn.resize(theConnSize); + myIndex.reset(new TElemNum(theNbElem + 1)); + myConn.reset(new TElemNum(theConnSize)); myConnMode = theConnMode; } @@ -500,7 +581,7 @@ namespace MED const TIntVector& theElemNums, const TStringVector& theElemNames): TElemInfoBase(theMeshInfo, - theIndexes.size() - 1, + (TInt)theIndexes.size() - 1, theFamilyNums, theElemNums, theElemNames) @@ -508,8 +589,8 @@ namespace MED myEntity = theEntity; myGeom = theGeom; - myIndex = theIndexes; - myConn = theConnectivities; + myIndex.reset(new TElemNum(theIndexes)); + myConn.reset(new TElemNum(theConnectivities)); myConnMode = theConnMode; } @@ -529,9 +610,9 @@ namespace MED myEntity = theInfo->GetEntity(); myGeom = theInfo->GetGeom(); - myIndex = theInfo->myIndex; - myFaces = theInfo->myFaces; - myConn = theInfo->myConn; + myIndex.reset(new TElemNum(*theInfo->myIndex)); + myFaces.reset(new TElemNum(*theInfo->myFaces)); + myConn.reset(new TElemNum(*theInfo->myConn)); myConnMode = theInfo->GetConnMode(); } @@ -553,9 +634,9 @@ namespace MED myEntity = theEntity; myGeom = theGeom; - myIndex.resize(theNbElem + 1); - myFaces.resize(theNbFaces); - myConn.resize(theConnSize); + myIndex.reset(new TElemNum(theNbElem + 1)); + myFaces.reset(new TElemNum(theNbFaces)); + myConn.reset(new TElemNum(theConnSize)); myConnMode = theConnMode; } @@ -571,7 +652,7 @@ namespace MED const TIntVector& theElemNums, const TStringVector& theElemNames): TElemInfoBase(theMeshInfo, - theIndexes.size()-1, + (TInt)theIndexes.size()-1, theFamilyNums, theElemNums, theElemNames) @@ -579,9 +660,9 @@ namespace MED myEntity = theEntity; myGeom = theGeom; - myIndex = theIndexes; - myFaces = theFaces; - myConn = theConnectivities; + myIndex.reset(new TElemNum(theIndexes)); + myFaces.reset(new TElemNum(theFaces)); + myConn.reset(new TElemNum(theConnectivities)); myConnMode = theConnMode; } @@ -603,7 +684,8 @@ namespace MED myConnMode = theInfo->GetConnMode(); TInt aConnDim = GetNbNodes(myGeom); - myConn.resize(myNbElem*GetNbConn<eVersion>(myGeom,myEntity,myMeshInfo->myDim)); + TInt aNbConn = GetNbConn<eVersion>(myGeom, myEntity, myMeshInfo->myDim); + myConn.reset(new TElemNum(myNbElem * aNbConn)); for(TInt anElemId = 0; anElemId < myNbElem; anElemId++){ TConnSlice aConnSlice = GetConnSlice(anElemId); TCConnSlice aConnSlice2 = theInfo->GetConnSlice(anElemId); @@ -631,7 +713,8 @@ namespace MED myGeom = theGeom; myConnMode = theConnMode; - myConn.resize(theNbElem*GetNbConn<eVersion>(theGeom,myEntity,theMeshInfo->myDim)); + TInt aNbConn = GetNbConn<eVersion>(theGeom, myEntity, theMeshInfo->myDim); + myConn.reset(new TElemNum(theNbElem * aNbConn)); } TTCellInfo(const PMeshInfo& theMeshInfo, @@ -644,7 +727,7 @@ namespace MED const TStringVector& theElemNames, EModeSwitch theMode): TElemInfoBase(theMeshInfo, - theConnectivities.size()/GetNbNodes(theGeom), + (TInt)theConnectivities.size() / GetNbNodes(theGeom), theFamilyNums, theElemNums, theElemNames), @@ -655,21 +738,21 @@ namespace MED myConnMode = theConnMode; TInt aConnDim = GetNbNodes(myGeom); - myConn.resize(myNbElem*GetNbConn<eVersion>(myGeom,myEntity,myMeshInfo->myDim)); + TInt aNbConn = GetNbConn<eVersion>(myGeom, myEntity, myMeshInfo->myDim); + myConn.reset(new TElemNum(myNbElem * aNbConn)); for(TInt anElemId = 0; anElemId < myNbElem; anElemId++){ TConnSlice aConnSlice = GetConnSlice(anElemId); for(TInt anConnId = 0; anConnId < aConnDim; anConnId++){ - aConnSlice[anConnId] = theConnectivities[anElemId*aConnDim+anConnId]; + aConnSlice[anConnId] = theConnectivities[anElemId*aConnDim + anConnId]; } } - } virtual TInt GetConnDim() const { - return GetNbConn<eVersion>(myGeom,myEntity,myMeshInfo->myDim); + return GetNbConn<eVersion>(myGeom, myEntity, myMeshInfo->myDim); } }; @@ -857,38 +940,46 @@ namespace MED TNameInfoBase(boost::get<0>(theInfo)) { TInt aSize = boost::get<1>(theInfo); - myElemNum.resize(aSize); + myElemNum.reset(new TElemNum(aSize)); myMode = aSize > 0? theMode: eNO_PFLMOD; } }; //--------------------------------------------------------------- - template<EVersion eVersion> - struct TTTimeStampVal: virtual TTimeStampVal + template<EVersion eVersion, class TMeshValueType> + struct TTTimeStampValue: virtual TTimeStampValue<TMeshValueType> { - TTTimeStampVal(const PTimeStampInfo& theTimeStampInfo, - const PTimeStampVal& theInfo) + TTTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampValueBase& theInfo, + ETypeChamp theTypeChamp) { - myTimeStampInfo = theTimeStampInfo; - - myGeom2Profile = theInfo->GetGeom2Profile(); - - myGeom2Value = theInfo->myGeom2Value; + typedef TTimeStampValue<TMeshValueType> TCompatible; + if(TCompatible* aCompatible = dynamic_cast<TCompatible*>(theInfo.get())){ + this->myTimeStampInfo = theTimeStampInfo; + this->myTypeChamp = theTypeChamp; + this->myGeom2Profile = aCompatible->GetGeom2Profile(); + this->myGeom2Value = aCompatible->myGeom2Value; + this->myGeomSet = aCompatible->GetGeomSet(); + }else + EXCEPTION(std::runtime_error,"TTTimeStampValue::TTTimeStampValue - use incompatible arguments!"); } - TTTimeStampVal(const PTimeStampInfo& theTimeStampInfo, - const TGeom2Profile& theGeom2Profile, - EModeSwitch theMode): + TTTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + ETypeChamp theTypeChamp, + const TGeom2Profile& theGeom2Profile, + EModeSwitch theMode): TModeSwitchInfo(theMode) { - myTimeStampInfo = theTimeStampInfo; + this->myTimeStampInfo = theTimeStampInfo; - myGeom2Profile = theGeom2Profile; + this->myTypeChamp = theTypeChamp; + + this->myGeom2Profile = theGeom2Profile; TInt aNbComp = theTimeStampInfo->myFieldInfo->myNbComp; - const TGeom2Size& aGeom2Size = theTimeStampInfo->myGeom2Size; + const TGeom2Size& aGeom2Size = theTimeStampInfo->GetGeom2Size(); TGeom2Size::const_iterator anIter = aGeom2Size.begin(); for(; anIter != aGeom2Size.end(); anIter++){ const EGeometrieElement& aGeom = anIter->first; @@ -904,10 +995,48 @@ namespace MED TInt aNbGauss = theTimeStampInfo->GetNbGauss(aGeom); - TMeshValue& aMeshValue = GetMeshValue(aGeom); - aMeshValue.Init(aNbElem,aNbGauss,aNbComp); + this->GetMeshValue(aGeom).Allocate(aNbElem,aNbGauss,aNbComp); } } + + virtual + size_t + GetValueSize(EGeometrieElement theGeom) const + { + return this->GetMeshValue(theGeom).GetSize(); + } + + virtual + size_t + GetNbVal(EGeometrieElement theGeom) const + { + return this->GetMeshValue(theGeom).GetNbVal(); + } + + virtual + size_t + GetNbGauss(EGeometrieElement theGeom) const + { + return this->GetMeshValue(theGeom).GetNbGauss(); + } + + virtual + void + AllocateValue(EGeometrieElement theGeom, + TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE) + { + this->GetMeshValue(theGeom).Allocate(theNbElem,theNbGauss,theNbComp,theMode); + } + + virtual + unsigned char* + GetValuePtr(EGeometrieElement theGeom) + { + return this->GetMeshValue(theGeom).GetValuePtr(); + } }; //--------------------------------------------------------------- @@ -934,6 +1063,10 @@ namespace MED myGrilleType = theInfo->GetGrilleType(); + myFamNumNode.resize(theInfo->GetNbNodes()); + myFamNumNode = theInfo->myFamNumNode; + + myFamNum = theInfo->myFamNum; } TTGrilleInfo(const PMeshInfo& theMeshInfo, @@ -952,7 +1085,7 @@ namespace MED } myGrilleStructure.resize(theMeshInfo->myDim); - + myFamNumNode.resize(nnoeuds); } TTGrilleInfo(const PMeshInfo& theMeshInfo, diff --git a/src/MEDWrapper/Base/MED_TWrapper.hxx b/src/MEDWrapper/Base/MED_TWrapper.hxx index 506739f7f..1df33bd86 100644 --- a/src/MEDWrapper/Base/MED_TWrapper.hxx +++ b/src/MEDWrapper/Base/MED_TWrapper.hxx @@ -39,7 +39,16 @@ namespace MED class TTWrapper: public TWrapper { public: - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- + //! Gets version of the MED library used for the MED file + virtual + EVersion + GetVersion() + { + return eVersion; + } + + //---------------------------------------------------------------------------- virtual PMeshInfo CrMeshInfo(TInt theDim = 0, @@ -62,7 +71,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo, @@ -109,7 +118,7 @@ namespace MED theInfo)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PElemInfo CrElemInfo(const PMeshInfo& theMeshInfo, @@ -140,7 +149,7 @@ namespace MED aElemNames)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo, @@ -193,7 +202,7 @@ namespace MED theInfo)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PPolygoneInfo CrPolygoneInfo(const PMeshInfo& theMeshInfo, @@ -250,7 +259,7 @@ namespace MED theInfo)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PPolyedreInfo CrPolyedreInfo(const PMeshInfo& theMeshInfo, @@ -311,7 +320,7 @@ namespace MED theInfo)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo, @@ -369,7 +378,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PFieldInfo CrFieldInfo(const PMeshInfo& theMeshInfo, @@ -399,7 +408,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PTimeStampInfo CrTimeStampInfo(const PFieldInfo& theFieldInfo, @@ -435,7 +444,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PGaussInfo CrGaussInfo(const TGaussInfo::TInfo& theInfo, @@ -447,7 +456,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PProfileInfo CrProfileInfo(const TProfileInfo::TInfo& theInfo, @@ -459,30 +468,45 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual - PTimeStampVal - CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo, - const TGeom2Profile& theGeom2Profile = TGeom2Profile(), - EModeSwitch theMode = eFULL_INTERLACE) - { - return PTimeStampVal(new TTTimeStampVal<eVersion> - (theTimeStampInfo, - theGeom2Profile, - theMode)); + PTimeStampValueBase + CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + ETypeChamp theTypeChamp, + const TGeom2Profile& theGeom2Profile = TGeom2Profile(), + EModeSwitch theMode = eFULL_INTERLACE) + { + if(theTypeChamp == eFLOAT64) + return PTimeStampValueBase(new TTTimeStampValue<eVersion, TFloatMeshValue> + (theTimeStampInfo, + theTypeChamp, + theGeom2Profile, + theMode)); + return PTimeStampValueBase(new TTTimeStampValue<eVersion, TIntMeshValue> + (theTimeStampInfo, + theTypeChamp, + theGeom2Profile, + theMode)); } virtual - PTimeStampVal - CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo, - const PTimeStampVal& theInfo) + PTimeStampValueBase + CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampValueBase& theInfo, + ETypeChamp theTypeChamp) { - return PTimeStampVal(new TTTimeStampVal<eVersion> - (theTimeStampInfo, - theInfo)); + if(theTypeChamp == eFLOAT64) + return PTimeStampValueBase(new TTTimeStampValue<eVersion, TFloatMeshValue> + (theTimeStampInfo, + theInfo, + theTypeChamp)); + return PTimeStampValueBase(new TTTimeStampValue<eVersion, TIntMeshValue> + (theTimeStampInfo, + theInfo, + theTypeChamp)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual PGrilleInfo CrGrilleInfo(const PMeshInfo& theMeshInfo, @@ -525,7 +549,7 @@ namespace MED type, nbNodeVec)); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- }; } diff --git a/src/MEDWrapper/Base/MED_Utilities.hxx b/src/MEDWrapper/Base/MED_Utilities.hxx index bf970e2b4..0d3aee086 100644 --- a/src/MEDWrapper/Base/MED_Utilities.hxx +++ b/src/MEDWrapper/Base/MED_Utilities.hxx @@ -29,22 +29,25 @@ #ifndef MED_Utilities_HeaderFile #define MED_Utilities_HeaderFile +#include "MED_WrapperBase.hxx" + #include <iostream> #include <sstream> #include <string> #include <stdexcept> -namespace MED{ - using namespace std; - class PrefixPrinter{ +namespace MED +{ + class MEDWRAPPER_EXPORT PrefixPrinter + { static int myCounter; bool myIsActive; public: PrefixPrinter(bool theIsActive = true); ~PrefixPrinter(); - static string GetPrefix(); + static std::string GetPrefix(); }; }; @@ -68,7 +71,7 @@ namespace MED{ #define EXCEPTION(TYPE, MSG) {\ std::ostringstream aStream;\ aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\ - throw TYPE(aStream.str());\ + throw TYPE(aStream.str().c_str());\ } #endif diff --git a/src/MEDWrapper/Base/MED_Wrapper.cxx b/src/MEDWrapper/Base/MED_Wrapper.cxx index ab8c893bc..979e59178 100644 --- a/src/MEDWrapper/Base/MED_Wrapper.cxx +++ b/src/MEDWrapper/Base/MED_Wrapper.cxx @@ -24,13 +24,13 @@ namespace MED myWrapper(theWrapper) { boost::detail::thread::lock_ops<TWrapper::TMutex>::lock(myWrapper->myMutex); - INITMSG(MYDEBUG,"TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<endl); + INITMSG(MYDEBUG,"TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl); } TLockProxy ::~TLockProxy() { - INITMSG(MYDEBUG,"~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<endl); + INITMSG(MYDEBUG,"~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl); boost::detail::thread::lock_ops<TWrapper::TMutex>::unlock(myWrapper->myMutex); } @@ -41,7 +41,12 @@ namespace MED return myWrapper; } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- + TWrapper::~TWrapper() + { + } + + //---------------------------------------------------------------------------- PMeshInfo TWrapper ::GetPMeshInfo(TInt theId, @@ -53,7 +58,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PFamilyInfo TWrapper ::GetPFamilyInfo(const PMeshInfo& theMeshInfo, @@ -70,7 +75,7 @@ namespace MED GetFamilyInfo(theId,*anInfo,theErr); #ifdef _DEBUG_ - string aName = anInfo->GetName(); + std::string aName = anInfo->GetName(); INITMSG(MYDEBUG,"GetPFamilyInfo - aFamilyName = '"<<aName<< "'; andId = "<<anInfo->GetId()<< "; aNbAttr = "<<aNbAttr<< @@ -85,7 +90,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PNodeInfo TWrapper ::GetPNodeInfo(const PMeshInfo& theMeshInfo, @@ -112,29 +117,29 @@ namespace MED } ADDMSG(MYVALUEDEBUG," "); } - ADDMSG(MYDEBUG,endl); + ADDMSG(MYDEBUG, std::endl); - BEGMSG(MYVALUEDEBUG,"GetFamNum: "); + BEGMSG(MYVALUEDEBUG, "GetFamNum: "); for(TInt iElem = 0; iElem < aNbElem; iElem++){ ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", "); } - ADDMSG(MYVALUEDEBUG,endl); + ADDMSG(MYVALUEDEBUG, std::endl); if(anInfo->IsElemNum()){ BEGMSG(MYVALUEDEBUG,"GetElemNum: "); for(TInt iElem = 0; iElem < aNbElem; iElem++){ ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", "); } - ADDMSG(MYVALUEDEBUG,endl); + ADDMSG(MYVALUEDEBUG, std::endl); } } - ADDMSG(MYDEBUG,endl); + ADDMSG(MYDEBUG, std::endl); #endif return anInfo; } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PPolygoneInfo TWrapper ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo, @@ -162,13 +167,13 @@ namespace MED } ADDMSG(MYDEBUG," "); } - ADDMSG(MYDEBUG,endl); + ADDMSG(MYDEBUG, std::endl); #endif return anInfo; } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PPolyedreInfo TWrapper ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo, @@ -203,12 +208,13 @@ namespace MED } ADDMSG(MYDEBUG,"} "); } - ADDMSG(MYDEBUG,endl); + ADDMSG(MYDEBUG, std::endl); #endif return anInfo; } + //---------------------------------------------------------------------------- PElemInfo TWrapper ::GetPElemInfo(const PMeshInfo& theMeshInfo, @@ -297,7 +303,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PCellInfo TWrapper ::GetPCellInfo(const PMeshInfo& theMeshInfo, @@ -323,29 +329,29 @@ namespace MED } ADDMSG(MYVALUEDEBUG," "); } - ADDMSG(MYDEBUG,endl); + ADDMSG(MYDEBUG, std::endl); BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetFamNum: "); for(TInt iElem = 0; iElem < aNbElem; iElem++){ ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", "); } - ADDMSG(MYVALUEDEBUG,endl); + ADDMSG(MYVALUEDEBUG, std::endl); if(anInfo->IsElemNum()){ BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetElemNum: "); for(TInt iElem = 0; iElem < aNbElem; iElem++){ ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", "); } - ADDMSG(MYVALUEDEBUG,endl); + ADDMSG(MYVALUEDEBUG, std::endl); } - ADDMSG(MYDEBUG,endl); + ADDMSG(MYDEBUG, std::endl); #endif return anInfo; } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PFieldInfo TWrapper ::GetPFieldInfo(const PMeshInfo& theMeshInfo, @@ -362,14 +368,14 @@ namespace MED "- aName = '"<<anInfo->GetName()<<"'"<< "; aType = "<<anInfo->GetType()<< "; aNbComp = "<<aNbComp<< - endl); + std::endl); #endif return anInfo; } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PTimeStampInfo TWrapper ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo, @@ -395,7 +401,7 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- PProfileInfo TWrapper ::GetPProfileInfo(TInt theId, @@ -410,34 +416,52 @@ namespace MED } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - PTimeStampVal + //---------------------------------------------------------------------------- + PTimeStampValueBase TWrapper - ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo, - const TMKey2Profile& theMKey2Profile, - const TKey2Gauss& theKey2Gauss, - TErr* theErr) + ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const TGeom2Profile& theGeom2Profile, + EModeSwitch theMode) { - PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo); - GetTimeStampVal(*anInfo,theMKey2Profile,theKey2Gauss,theErr); + PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo(); + return CrTimeStampValue(theTimeStampInfo, + aFieldInfo->GetType(), + theGeom2Profile, + theMode); + } -#ifdef _DEBUG_ + //---------------------------------------------------------------------------- + PTimeStampValueBase + TWrapper + ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampValueBase& theInfo) + { PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo(); - INITMSG(MYDEBUG,"GetPTimeStampVal\n"); - TGeom2Value& aGeom2Value = anInfo->myGeom2Value; - TGeom2Value::const_iterator anIter = aGeom2Value.begin(); + return CrTimeStampValue(theTimeStampInfo, + theInfo, + aFieldInfo->GetType()); + } + + //---------------------------------------------------------------------------- + template<class TimeStampValueType> + void + Print(SharedPtr<TimeStampValueType> theTimeStampValue) + { + INITMSG(MYDEBUG,"Print - TimeStampValue\n"); + typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value; + typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin(); for(; anIter != aGeom2Value.end(); anIter++){ const EGeometrieElement& aGeom = anIter->first; - const TMeshValue& aMeshValue = anIter->second; + const typename TimeStampValueType::TTMeshValue& aMeshValue = anIter->second; TInt aNbElem = aMeshValue.myNbElem; TInt aNbGauss = aMeshValue.myNbGauss; TInt aNbComp = aMeshValue.myNbComp; INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aNbElem<<": "); for(TInt iElem = 0; iElem < aNbElem; iElem++){ - TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem); + typename TimeStampValueType::TTMeshValue::TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem); ADDMSG(MYVALUEDEBUG,"{"); for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){ - const TCValueSlice& aValueSlice = aValueSliceArr[iGauss]; + const typename TimeStampValueType::TTMeshValue::TCValueSlice& aValueSlice = aValueSliceArr[iGauss]; for(TInt iComp = 0; iComp < aNbComp; iComp++){ ADDMSG(MYVALUEDEBUG,aValueSlice[iComp]<<" "); } @@ -447,11 +471,120 @@ namespace MED } ADDMSG(MYDEBUG,"\n"); } + } + + //---------------------------------------------------------------------------- + PTimeStampValueBase + TWrapper + ::GetPTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr) + { + PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo(); + PTimeStampValueBase anInfo = CrTimeStampValue(theTimeStampInfo, + aFieldInfo->GetType()); + GetTimeStampValue(anInfo, + theMKey2Profile, + theKey2Gauss, + theErr); +#ifdef _DEBUG_ + if(aFieldInfo->GetType() == eFLOAT64) + Print<TFloatTimeStampValue>(anInfo); + else + Print<TIntTimeStampValue>(anInfo); #endif + return anInfo; + } + //---------------------------------------------------------------------------- + void + TWrapper + ::GetTimeStampVal(const PTimeStampVal& theVal, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr) + { + PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo(); + PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo(); + if(aFieldInfo->GetType() == eFLOAT64) + GetTimeStampValue(theVal, + theMKey2Profile, + theKey2Gauss, + theErr); + else{ + PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo, + theVal, + eINT); + GetTimeStampValue(aVal, + theMKey2Profile, + theKey2Gauss, + theErr); + CopyTimeStampValueBase(aVal, theVal); + } + } + + //---------------------------------------------------------------------------- + void + TWrapper + ::SetTimeStamp(const PTimeStampVal& theVal, + TErr* theErr) + { + PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo(); + PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo(); + if(aFieldInfo->GetType() == eFLOAT64) + SetTimeStampValue(theVal, theErr); + else{ + PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo, + eINT, + theVal->GetGeom2Profile(), + theVal->GetModeSwitch()); + CopyTimeStampValueBase(theVal, aVal); + SetTimeStampValue(aVal, theErr); + } + } + + //---------------------------------------------------------------------------- + PTimeStampVal + TWrapper + ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo, + const TGeom2Profile& theGeom2Profile, + EModeSwitch theMode) + { + return CrTimeStampValue(theTimeStampInfo, + eFLOAT64, + theGeom2Profile, + theMode); + } + + //---------------------------------------------------------------------------- + PTimeStampVal + TWrapper + ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampVal& theInfo) + { + return CrTimeStampValue(theTimeStampInfo, + theInfo, + eFLOAT64); + } + + //---------------------------------------------------------------------------- + PTimeStampVal + TWrapper + ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr) + { + PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo); + GetTimeStampVal(anInfo, + theMKey2Profile, + theKey2Gauss, + theErr); return anInfo; } + //---------------------------------------------------------------------------- PGrilleInfo TWrapper ::GetPGrilleInfo(const PMeshInfo& theMeshInfo) @@ -489,9 +622,39 @@ namespace MED GetGrilleInfo(anInfo); anInfo->SetGrilleType(type); + +#ifdef _DEBUG_ + INITMSG(MYDEBUG,"GetPGrilleInfo: "); + { + TInt aNbElem = anInfo->GetNbNodes(); + BEGMSG(MYVALUEDEBUG,"GetFamNumNode: "); + for(TInt iElem = 0; iElem < aNbElem; iElem++){ + ADDMSG(MYVALUEDEBUG,anInfo->GetFamNumNode(iElem)<<", "); + } + TInt aNbCells = anInfo->GetNbCells(); + BEGMSG(MYVALUEDEBUG,"GetFamNum: "); + for(TInt iElem = 0; iElem < aNbCells; iElem++){ + ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", "); + } + ADDMSG(MYVALUEDEBUG, std::endl); + BEGMSG(MYVALUEDEBUG,"GetCoordName: "); + for(TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++){ + ADDMSG(MYVALUEDEBUG,anInfo->GetCoordName(iElem)<<", "); + } + ADDMSG(MYVALUEDEBUG, std::endl); + BEGMSG(MYVALUEDEBUG,"GetCoordUnit: "); + for(TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++){ + ADDMSG(MYVALUEDEBUG,anInfo->GetCoordUnit(iElem)<<", "); + } + ADDMSG(MYVALUEDEBUG, std::endl); + + } +#endif + return anInfo; } + //---------------------------------------------------------------------------- PGrilleInfo TWrapper ::GetPGrilleInfo(const PMeshInfo& theMeshInfo, diff --git a/src/MEDWrapper/Base/MED_Wrapper.hxx b/src/MEDWrapper/Base/MED_Wrapper.hxx index cb1397b0e..67c995c4f 100644 --- a/src/MEDWrapper/Base/MED_Wrapper.hxx +++ b/src/MEDWrapper/Base/MED_Wrapper.hxx @@ -29,6 +29,8 @@ #ifndef MED_Wrapper_HeaderFile #define MED_Wrapper_HeaderFile +#include "MED_WrapperBase.hxx" + #include "MED_Structures.hxx" #include "MED_Algorithm.hxx" @@ -39,13 +41,22 @@ namespace MED //---------------------------------------------------------------------------- //! Define a base class that wraps the MED API - struct TWrapper + struct MEDWRAPPER_EXPORT TWrapper { typedef boost::mutex TMutex; //! This is a syncronization primitive which allow to support thread safety for the MED access - TMutex myMutex; + TMutex myMutex; + + virtual + ~TWrapper(); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- + //! Gets version of the MED library used for the MED file + virtual + EVersion + GetVersion() = 0; + + //---------------------------------------------------------------------------- //! Creates a MEDWrapper MED Mesh representation virtual PMeshInfo @@ -84,7 +95,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read number of MED Family entities in the defined MED file virtual TInt @@ -150,7 +161,7 @@ namespace MED TInt theId, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read sequence of names for any descendant of TElemInfo virtual void @@ -216,7 +227,7 @@ namespace MED EConnectivite theConnMode = eNOD, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read number of nodes in defined MED Mesh virtual TInt @@ -301,7 +312,7 @@ namespace MED GetPNodeInfo(const PMeshInfo& theMeshInfo, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read a MEDWrapper MED Polygones representation from defined MED file /*! This feature is support only for version of 2.2 and higher */ virtual @@ -394,7 +405,7 @@ namespace MED EGeometrieElement theGeom, EConnectivite theConnMode = eNOD); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read a MEDWrapper MED Polyedres representation from defined MED file /*! This feature is support only for version of 2.2 and higher */ virtual @@ -487,7 +498,7 @@ namespace MED EGeometrieElement theGeom, EConnectivite theConnMode = eNOD); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Get TEntityInfo which contains brief information about existing cells and their destribution among MED ENTITIES virtual TEntityInfo @@ -556,7 +567,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read number of MED FIELDS in defined MED Mesh virtual TInt @@ -605,7 +616,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read number of MED GAUSS in defined MED Mesh /*! This feature is support only for version of 2.2 and higher */ virtual @@ -622,7 +633,7 @@ namespace MED GetGaussPreInfo(TInt theId, TErr* theErr = NULL) { - return TGaussInfo::TInfo(); + return TGaussInfo::TInfo( TGaussInfo::TKey(ePOINT1,""),0 ); } //! Read a MEDWrapper MED GAUSS representation by its order number from defined MED file @@ -642,7 +653,7 @@ namespace MED EModeSwitch theMode = eFULL_INTERLACE) = 0; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read number of MED TIMESTAMPS in defined MED Mesh /*! By the way some additional information can be obtained: @@ -692,7 +703,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read number of MED PROFILES in defined MED Mesh virtual TInt @@ -717,6 +728,12 @@ namespace MED CrProfileInfo(const TProfileInfo::TInfo& theInfo, EModeProfil theMode = eCOMPACT) = 0; + //! Write a MEDWrapper MED PROFILE representation + virtual + void + SetProfileInfo(const TProfileInfo& theInfo, + TErr* theErr = NULL) = 0; + //! Read a MEDWrapper MED PROFILE representation by its order number from defined MED file PProfileInfo GetPProfileInfo(TInt theId, @@ -724,33 +741,84 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- //! Read the values for MEDWrapper MED TIEMSTAMP from defined MED file virtual void - GetTimeStampVal(TTimeStampVal& theVal, + GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr = NULL) = 0; + + //! Write the values for MEDWrapper MED TIEMSTAMP to defined MED file + virtual + void + SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + TErr* theErr = NULL) = 0; + + //! Creates the values for MEDWrapper MED TIEMSTAMP representation + virtual + PTimeStampValueBase + CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + ETypeChamp theTypeChamp, + const TGeom2Profile& theGeom2Profile = TGeom2Profile(), + EModeSwitch theMode = eFULL_INTERLACE) = 0; + + //! Creates the values for MEDWrapper MED TIEMSTAMP representation + virtual + PTimeStampValueBase + CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const TGeom2Profile& theGeom2Profile = TGeom2Profile(), + EModeSwitch theMode = eFULL_INTERLACE); + + //! A copy-constructor for the values for MEDWrapper MED TIEMSTAMP representation + virtual + PTimeStampValueBase + CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampValueBase& theInfo, + ETypeChamp theTypeChamp) = 0; + + //! A copy-constructor for the values for MEDWrapper MED TIEMSTAMP representation + virtual + PTimeStampValueBase + CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampValueBase& theInfo); + + //! Read the values for MEDWrapper MED TIEMSTAMP from defined MED file + PTimeStampValueBase + GetPTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr = NULL); + + //---------------------------------------------------------------------------- + // Backward compatibility declarations + //! Read the values for MEDWrapper MED TIEMSTAMP from defined MED file + virtual + void + GetTimeStampVal(const PTimeStampVal& theVal, const TMKey2Profile& theMKey2Profile, const TKey2Gauss& theKey2Gauss, - TErr* theErr = NULL) = 0; + TErr* theErr = NULL); //! Write the values for MEDWrapper MED TIEMSTAMP to defined MED file virtual void - SetTimeStamp(const TTimeStampVal& theTimeStampVal, - TErr* theErr = NULL) = 0; + SetTimeStamp(const PTimeStampVal& theVal, + TErr* theErr = NULL); //! Creates the values for MEDWrapper MED TIEMSTAMP representation virtual PTimeStampVal CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo, const TGeom2Profile& theGeom2Profile = TGeom2Profile(), - EModeSwitch theMode = eFULL_INTERLACE) = 0; + EModeSwitch theMode = eFULL_INTERLACE); //! A copy-constructor for the values for MEDWrapper MED TIEMSTAMP representation virtual PTimeStampVal CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo, - const PTimeStampVal& theInfo) = 0; + const PTimeStampVal& theInfo); //! Read the values for MEDWrapper MED TIEMSTAMP from defined MED file PTimeStampVal @@ -759,6 +827,7 @@ namespace MED const TKey2Gauss& theKey2Gauss, TErr* theErr = NULL); + //---------------------------------------------------------------------------- //! Read a MEDWrapper MED Grille representation from defined MED file /*! This feature is support only for version of 2.2 and higher */ PGrilleInfo @@ -846,7 +915,7 @@ namespace MED //---------------------------------------------------------------------------- //! This class provide thread-safety for MEDWrapper interaction - class TLockProxy + class MEDWRAPPER_EXPORT TLockProxy { TLockProxy& operator=(const TLockProxy& ); TWrapper* myWrapper; @@ -863,7 +932,7 @@ namespace MED //---------------------------------------------------------------------------- //! To specialize the SharedPtr for TWrapper template<> - class SharedPtr<TWrapper>: public boost::shared_ptr<TWrapper> + class MEDWRAPPER_EXPORT SharedPtr<TWrapper>: public boost::shared_ptr<TWrapper> { public: SharedPtr() {} diff --git a/src/MEDWrapper/Base/MED_WrapperBase.hxx b/src/MEDWrapper/Base/MED_WrapperBase.hxx new file mode 100755 index 000000000..b0bbf02e6 --- /dev/null +++ b/src/MEDWrapper/Base/MED_WrapperBase.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MED_WrapperBase.hxx +// Author : Alexander A. BORODIN +// Module : MED + +#ifndef _MED_WrapperBase_HXX_ +#define _MED_WrapperBase_HXX_ + +#ifdef WNT + #if defined MEDWRAPPER_BASE_EXPORTS + #if defined WIN32 + #define MEDWRAPPER_EXPORT __declspec( dllexport ) + #else + #define MEDWRAPPER_EXPORT + #endif + #else + #if defined WIN32 + #define MEDWRAPPER_EXPORT __declspec( dllimport ) + #else + #define MEDWRAPPER_EXPORT + #endif + #endif +#else + #define MEDWRAPPER_EXPORT +#endif + +#endif diff --git a/src/MEDWrapper/Base/Makefile.am b/src/MEDWrapper/Base/Makefile.am new file mode 100644 index 000000000..5786b153b --- /dev/null +++ b/src/MEDWrapper/Base/Makefile.am @@ -0,0 +1,59 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : +# Author : +# Module : +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDWrapperBase.la + +salomeinclude_HEADERS= \ + MED_Common.hxx \ + MED_Vector.hxx \ + MED_SharedPtr.hxx \ + MED_SliceArray.hxx \ + MED_Wrapper.hxx \ + MED_TWrapper.hxx \ + MED_Structures.hxx \ + MED_TStructures.hxx \ + MED_Algorithm.hxx \ + MED_GaussUtils.hxx \ + MED_CoordUtils.hxx \ + MED_Utilities.hxx \ + MED_GaussDef.hxx \ + MED_WrapperBase.hxx + +dist_libMEDWrapperBase_la_SOURCES= \ + MED_Structures.cxx \ + MED_Wrapper.cxx \ + MED_Algorithm.cxx \ + MED_GaussUtils.cxx \ + MED_CoordUtils.cxx \ + MED_Utilities.cxx \ + MED_GaussDef.cxx + +libMEDWrapperBase_la_CPPFLAGS= $(BOOST_CPPFLAGS) $(HDF5_INCLUDES) -D@MACHINE@ -I$(top_builddir)/salome_adm/unix $(MED_CPPFLAGS) +libMEDWrapperBase_la_LDFLAGS= $(BOOST_LIBS) -lboost_thread${BOOST_LIBSUFFIX} diff --git a/src/MEDWrapper/Base/Makefile.in b/src/MEDWrapper/Base/Makefile.in deleted file mode 100644 index 2459d8a4a..000000000 --- a/src/MEDWrapper/Base/Makefile.in +++ /dev/null @@ -1,70 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl -BOOST_LIBSUFFIX=@BOOST_LIBSUFFIX@ - -@COMMENCE@ - -EXPORT_HEADERS = \ - MED_Common.hxx \ - MED_Vector.hxx \ - MED_SharedPtr.hxx \ - MED_SliceArray.hxx \ - MED_Wrapper.hxx \ - MED_TWrapper.hxx \ - MED_Structures.hxx \ - MED_TStructures.hxx \ - MED_Algorithm.hxx \ - MED_GaussUtils.hxx \ - MED_CoordUtils.hxx \ - MED_Utilities.hxx - -# Libraries targets - -LIB = libMEDWrapperBase.la -LIB_SRC = \ - MED_Structures.cxx \ - MED_Wrapper.cxx \ - MED_Algorithm.cxx \ - MED_GaussUtils.cxx \ - MED_CoordUtils.cxx \ - MED_Utilities.cxx - -# Executables targets -BIN = -BIN_SRC = - -CPPFLAGS+= $(BOOST_CPPFLAGS) $(HDF5_INCLUDES) -D@MACHINE@ - -LDFLAGS+= $(BOOST_LIBS) -lboost_thread${BOOST_LIBSUFFIX} - -@CONCLUDE@ diff --git a/src/MEDWrapper/Factory/MED_Factory.cxx b/src/MEDWrapper/Factory/MED_Factory.cxx index 883a4193c..eb9a164e4 100644 --- a/src/MEDWrapper/Factory/MED_Factory.cxx +++ b/src/MEDWrapper/Factory/MED_Factory.cxx @@ -54,10 +54,12 @@ namespace MED INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'"<<std::endl); EVersion aVersion = eVUnknown; +#ifndef WIN32 if(theDoPreCheckInSeparateProcess){ // First check, is it possible to deal with the file std::ostringstream aStr; - aStr<<"bash -c \""<<getenv("MED_ROOT_DIR")<<"/bin/salome/mprint_version "<<theFileName<<"\""; + // File name is in quotes for the case of space(s) inside it (PAL13009) + aStr<<"bash -c \""<<getenv("MED_ROOT_DIR")<<"/bin/salome/mprint_version \'"<<theFileName<<"\'\""; if(!MYDEBUG) aStr<<" 2>&1 > /dev/null"; @@ -68,16 +70,17 @@ namespace MED if(aStatus != 0) return aVersion; } +#endif // Next, try to open the file trough the MED API char* aFileName = const_cast<char*>(theFileName.c_str()); med_idt aFid = MEDouvrir(aFileName,MED_LECTURE); - MSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aFid = "<<aFid<<endl); + MSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aFid = "<<aFid<<std::endl); if(aFid >= 0){ med_int aMajor, aMinor, aRelease; med_err aRet = MEDversionLire(aFid,&aMajor,&aMinor,&aRelease); - INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aRet = "<<aRet<<endl); + INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aRet = "<<aRet<<std::endl); if(aRet >= 0){ if(aMajor >= 2 && aMinor >= 2) aVersion = eV2_2; @@ -104,7 +107,7 @@ namespace MED aWrapper.reset(new MED::V2_1::TVWrapper(theFileName)); break; default: - EXCEPTION(runtime_error,"MED::CrWrapper - theFileName = '"<<theFileName<<"'"); + EXCEPTION(std::runtime_error,"MED::CrWrapper - theFileName = '"<<theFileName<<"'"); } return aWrapper; } diff --git a/src/MEDWrapper/Factory/MED_Factory.hxx b/src/MEDWrapper/Factory/MED_Factory.hxx index 664cddcf4..69a46dae4 100644 --- a/src/MEDWrapper/Factory/MED_Factory.hxx +++ b/src/MEDWrapper/Factory/MED_Factory.hxx @@ -29,18 +29,24 @@ #ifndef MED_Factory_HeaderFile #define MED_Factory_HeaderFile +#include "MED_WrapperFactory.hxx" #include "MED_Wrapper.hxx" -namespace MED{ - - EVersion GetVersionId(const std::string& theFileName, - bool theDoPreCheckInSeparateProcess = false); - - PWrapper CrWrapper(const std::string& theFileName, - bool theDoPreCheckInSeparateProcess = false); - - PWrapper CrWrapper(const std::string& theFileName, EVersion theId); - +namespace MED +{ + MEDWRAPPER_FACTORY_EXPORT + EVersion + GetVersionId(const std::string& theFileName, + bool theDoPreCheckInSeparateProcess = false); + + MEDWRAPPER_FACTORY_EXPORT + PWrapper + CrWrapper(const std::string& theFileName, + bool theDoPreCheckInSeparateProcess = false); + + MEDWRAPPER_FACTORY_EXPORT + PWrapper + CrWrapper(const std::string& theFileName, EVersion theId); } #endif diff --git a/src/MEDWrapper/Factory/MED_Test.cxx b/src/MEDWrapper/Factory/MED_Test.cxx index 4f1d6a76d..67ae2c862 100644 --- a/src/MEDWrapper/Factory/MED_Test.cxx +++ b/src/MEDWrapper/Factory/MED_Test.cxx @@ -52,14 +52,14 @@ void CheckMed(const std::string& theFileName) TKey2Gauss aKey2Gauss = GetKey2Gauss(aMed); TMKey2Profile aMKey2Profile = GetMKey2Profile(aMed); - INITMSG(MYDEBUG,"aMed->GetNbProfiles() = "<<aMed->GetNbProfiles()<<endl); + INITMSG(MYDEBUG,"aMed->GetNbProfiles() = "<<aMed->GetNbProfiles()<<std::endl); TInt aNbMeshes = aMed->GetNbMeshes(); - BEGMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<endl); + BEGMSG(MYDEBUG,"GetNbMeshes() = "<<aNbMeshes<<std::endl); for(TInt iMesh = 1; iMesh <= aNbMeshes; iMesh++){ PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh); - INITMSG(MYDEBUG,"aMeshInfo->GetName() = '"<<aMeshInfo->GetName()<<"'"<<endl); + INITMSG(MYDEBUG,"aMeshInfo->GetName() = '"<<aMeshInfo->GetName()<<"'"<<std::endl); TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo); @@ -84,7 +84,7 @@ void CheckMed(const std::string& theFileName) "- aName = '"<<aFieldInfo->GetName()<<"'"<< "; aType = "<<aFieldInfo->GetType()<< "; aNbComp = "<<aFieldInfo->GetNbComp()<< - endl); + std::endl); const TTimeStampInfoSet& aTimeStampInfoSet = aFieldInfo2TimeStampInfoSetIter->second; TTimeStampInfoSet::const_iterator aTimeStampInfoSettIter = aTimeStampInfoSet.begin(); for(; aTimeStampInfoSettIter != aTimeStampInfoSet.end(); aTimeStampInfoSettIter++){ @@ -93,10 +93,11 @@ void CheckMed(const std::string& theFileName) "GetPTimeStampInfo "<< "- anEntity = "<<aTimeStampInfo->GetEntity()<< "; aNumDt = "<<aTimeStampInfo->GetNumDt()<< - endl); - PTimeStampVal aTimeStampVal = aMed->GetPTimeStampVal(aTimeStampInfo, - aMKey2Profile, - aKey2Gauss); + std::endl); + PTimeStampValueBase aTimeStampValue = + aMed->GetPTimeStampValue(aTimeStampInfo, + aMKey2Profile, + aKey2Gauss); } } } @@ -187,7 +188,7 @@ void CopyMed(const PWrapper& theMed, TInt aNbTimeStamps = theMed->GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aGeom2Size); { - INITMSG(MYDEBUG,"GetNbTimeStamps = "<<aNbTimeStamps<<endl); + INITMSG(MYDEBUG,"GetNbTimeStamps = "<<aNbTimeStamps<<std::endl); for(TInt iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){ PTimeStampInfo aTimeStampInfo = theMed->GetPTimeStampInfo(aFieldInfo,anEntity,aGeom2Size,iTimeStamp+1); @@ -197,14 +198,16 @@ void CopyMed(const PWrapper& theMed, PTimeStampInfo aTimeStampInfo2 = theMed->CrTimeStampInfo(aFieldInfo2,aTimeStampInfo); - PTimeStampVal aTimeStampVal = theMed->GetPTimeStampVal(aTimeStampInfo, - aMKey2Profile, - aKey2Gauss); + PTimeStampValueBase aTimeStampValue = + theMed->GetPTimeStampValue(aTimeStampInfo, + aMKey2Profile, + aKey2Gauss); - PTimeStampVal aTimeStampVal2 = theMed->CrTimeStampVal(aTimeStampInfo2, - aTimeStampVal); + PTimeStampValueBase aTimeStampValue2 = + theMed->CrTimeStampValue(aTimeStampInfo2, + aTimeStampValue); - if(MYWRITEDEBUG) theMed2->SetTimeStamp(aTimeStampVal2); + if(MYWRITEDEBUG) theMed2->SetTimeStamp(aTimeStampValue2); } } } @@ -235,7 +238,7 @@ void CopyMed(const PWrapper& theMed, aName[0] += theIncr; aFamilyInfo2->SetName(aName); theMed2->SetFamilyInfo(aFamilyInfo2); - INITMSG(MYDEBUG,"GetNbFamilies = "<<theMed2->GetNbFamilies(aMeshInfo2)<<endl); + INITMSG(MYDEBUG,"GetNbFamilies = "<<theMed2->GetNbFamilies(aMeshInfo2)<<std::endl); } } diff --git a/src/MEDWrapper/Factory/MED_WrapperFactory.hxx b/src/MEDWrapper/Factory/MED_WrapperFactory.hxx new file mode 100755 index 000000000..c40f6cbd0 --- /dev/null +++ b/src/MEDWrapper/Factory/MED_WrapperFactory.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : MED_WrapperFactory.hxx +// Author : Alexander A. BORODIN +// Module : MED + +#ifndef _MED_WrapperFactory_HXX_ +#define _MED_WrapperFactory_HXX_ + +#ifdef WNT + #if defined MEDWRAPPER_FACTORY_EXPORTS + #if defined WIN32 + #define MEDWRAPPER_FACTORY_EXPORT __declspec( dllexport ) + #else + #define MEDWRAPPER_FACTORY_EXPORT + #endif + #else + #if defined WIN32 + #define MEDWRAPPER_FACTORY_EXPORT __declspec( dllimport ) + #else + #define MEDWRAPPER_FACTORY_EXPORT + #endif + #endif +#else + #define MEDWRAPPER_FACTORY_EXPORT +#endif + +#endif diff --git a/src/MEDWrapper/Factory/Makefile.am b/src/MEDWrapper/Factory/Makefile.am new file mode 100644 index 000000000..456cdaa57 --- /dev/null +++ b/src/MEDWrapper/Factory/Makefile.am @@ -0,0 +1,55 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : +# Author : +# Module : +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDWrapper.la + +salomeinclude_HEADERS= \ + MED_Factory.hxx \ + MED_WrapperFactory.hxx + +dist_libMEDWrapper_la_SOURCES= \ + MED_Factory.cxx + +libMEDWrapper_la_CPPFLAGS= $(BOOST_CPPFLAGS) $(MED2_INCLUDES) \ + -I$(srcdir)/../Base -I$(top_builddir)/salome_adm/unix -I$(srcdir)/../V2_1/Wrapper -I$(srcdir)/../V2_2 +libMEDWrapper_la_LDFLAGS= ../V2_2/libMEDWrapper_V2_2.la ../V2_1/Wrapper/libMEDWrapper_V2_1.la + +# Executables targets +bin_PROGRAMS = MED_Test mprint_version + +dist_MED_Test_SOURCES= MED_Test.cxx +MED_Test_CPPFLAGS= $(libMEDWrapper_la_CPPFLAGS) +MED_Test_LDADD= $(libMEDWrapper_la_LDFLAGS) ../Base/libMEDWrapperBase.la ../V2_1/Core/libmed_V2_1.la \ + $(BOOST_LIBS) -lboost_thread${BOOST_LIBSUFFIX} libMEDWrapper.la + +dist_mprint_version_SOURCES= mprint_version.cxx +mprint_version_CPPFLAGS= $(libMEDWrapper_la_CPPFLAGS) +mprint_version_LDADD= $(libMEDWrapper_la_LDFLAGS) ../Base/libMEDWrapperBase.la ../V2_1/Core/libmed_V2_1.la \ + $(BOOST_LIBS) -lboost_thread${BOOST_LIBSUFFIX} libMEDWrapper.la diff --git a/src/MEDWrapper/Factory/Makefile.in b/src/MEDWrapper/Factory/Makefile.in deleted file mode 100644 index d672d9fb3..000000000 --- a/src/MEDWrapper/Factory/Makefile.in +++ /dev/null @@ -1,56 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl -BOOST_LIBSUFFIX=@BOOST_LIBSUFFIX@ - -@COMMENCE@ - -# Libraries targets - -LIB = libMEDWrapper.la -LIB_SRC = \ - MED_Factory.cxx - -EXPORT_HEADERS = \ - MED_Factory.hxx - -# Executables targets -BIN = MED_Test mprint_version -BIN_SRC = - -CPPFLAGS+= $(BOOST_CPPFLAGS) $(MED2_INCLUDES) - -LDFLAGS+= -lMEDWrapper_V2_2 -lMEDWrapper_V2_1 - -LDFLAGSFORBIN=$(LDFLAGS) -lMEDWrapperBase $(BOOST_LIBS) -lboost_thread${BOOST_LIBSUFFIX} -lmed_V2_1 - -@CONCLUDE@ diff --git a/src/MEDWrapper/Makefile.am b/src/MEDWrapper/Makefile.am new file mode 100644 index 000000000..061fa236d --- /dev/null +++ b/src/MEDWrapper/Makefile.am @@ -0,0 +1,33 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# if without KERNEL, build only med 2.1 library +if MED_ENABLE_KERNEL + SUBDIRS = Base V2_1 V2_2 Factory +else !MED_ENABLE_KERNEL + SUBDIRS = Base V2_1 +endif + +DIST_SUBDIRS = Base V2_1 V2_2 Factory diff --git a/src/MEDWrapper/Makefile.in b/src/MEDWrapper/Makefile.in deleted file mode 100644 index 9976c034b..000000000 --- a/src/MEDWrapper/Makefile.in +++ /dev/null @@ -1,44 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -# if without KERNEL, build only med 2.1 library -ifeq ($(MED_WITH_KERNEL),yes) - SUBDIRS = Base V2_1 V2_2 Factory -else - SUBDIRS = V2_1 -endif - -@MODULE@ diff --git a/src/MEDWrapper/V2_1/Core/MEDattrFermer.cxx b/src/MEDWrapper/V2_1/Core/MEDattrFermer.cxx index 6a7b708e0..7345daa30 100644 --- a/src/MEDWrapper/V2_1/Core/MEDattrFermer.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDattrFermer.cxx @@ -42,3 +42,4 @@ _MEDattrFermer(med_idt id) } } + diff --git a/src/MEDWrapper/V2_1/Core/MEDattrNumEcrire.cxx b/src/MEDWrapper/V2_1/Core/MEDattrNumEcrire.cxx index 51ae76e11..aa3c85f93 100644 --- a/src/MEDWrapper/V2_1/Core/MEDattrNumEcrire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDattrNumEcrire.cxx @@ -47,8 +47,9 @@ _MEDattrNumEcrire(med_idt pere,med_type_champ type,char *nom,unsigned char *val, /* 1) IA32 is LE but due to an (?HDF convertion BUG?) when using H5T_NATIVE_DOUBLE/MED_REEL64? under PCLINUX the file read under SGI is incorrect 2) Compaq OSF/1 is LE, since we force SGI64,SUN4SOL2,HP to write double in LE even if they are BE, mips OSF/1 must be BE - REM : Be careful of compatibility between MED files when changing this (med2.2) */ -#if defined(PCLINUX) || defined(OSF1) + REM : Be careful of compatibility between MED files when changing this (med2.2) + */ +#if defined(PCLINUX) || defined(PPRO_NT) || defined(PCLINUX64) || defined(PCLINUX64_32) || defined(OSF1) type_hdf = H5T_IEEE_F64BE; #else type_hdf = H5T_IEEE_F64LE; @@ -56,9 +57,9 @@ _MEDattrNumEcrire(med_idt pere,med_type_champ type,char *nom,unsigned char *val, break; case MED_INT : -#if defined(IRIX64) || defined(OSF1) - type_hdf = H5T_NATIVE_LONG; -#elif defined(PCLINUX) +#if defined(HAVE_F77INT64) + type_hdf = H5T_NATIVE_LONG; +#elif defined(PCLINUX) || defined(PCLINUX64_32) /* This explicit convertion avoid a core dump between in HDF&ASTER when reading on SGI a file written under a PCLINUX system (in founction H5Tconvert), we don't know yet if it is an HDF bug or an ASTER one */ @@ -93,7 +94,7 @@ _MEDattrNumEcrire(med_idt pere,med_type_champ type,char *nom,unsigned char *val, if ((ret = H5Aclose(attr)) < 0) return -1; -#if defined(PCLINUX) +#if defined(PCLINUX) || defined(PCLINUX64_32) /* This explicit convertion cancel the previous on which avoid a mysterious bug between HDF&ASTER when reading a file written under a PCLINUX system, we don't know yet if it is an HDF bug or an ASTER one */ if (type == MED_INT) diff --git a/src/MEDWrapper/V2_1/Core/MEDattrNumLire.cxx b/src/MEDWrapper/V2_1/Core/MEDattrNumLire.cxx index 12299c5a7..6d31bdee9 100644 --- a/src/MEDWrapper/V2_1/Core/MEDattrNumLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDattrNumLire.cxx @@ -46,7 +46,7 @@ _MEDattrNumLire(med_idt pere,med_type_champ type,char *nom,unsigned char *val) switch(type) { case MED_REEL64 : -#if defined(PCLINUX) || defined(OSF1) +#if defined(PCLINUX) || defined(OSF1) || defined(PPRO_NT) || defined(PCLINUX64) || defined(PCLINUX64_32) type_hdf = H5T_IEEE_F64BE; #else type_hdf = H5T_IEEE_F64LE; @@ -54,7 +54,7 @@ _MEDattrNumLire(med_idt pere,med_type_champ type,char *nom,unsigned char *val) break; case MED_INT : -#if defined(IRIX64) || defined(OSF1) +#if defined(HAVE_F77INT64) type_hdf = H5T_NATIVE_LONG; #else type_hdf = H5T_NATIVE_INT; @@ -68,6 +68,12 @@ _MEDattrNumLire(med_idt pere,med_type_champ type,char *nom,unsigned char *val) if ((ret = H5Aread(attid,type_hdf,val)) < 0) return -1; + if (strcmp(nom, MED_NOM_NGA) == 0 ) { + med_int* ngauss = (med_int*)val; + if( *ngauss <= 0 || *ngauss > 128) + *ngauss =1; + } + if ((ret = H5Aclose(attid)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDbodyFittedEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDbodyFittedEcr.cxx index c7d84f46a..9d7577b99 100644 --- a/src/MEDWrapper/V2_1/Core/MEDbodyFittedEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDbodyFittedEcr.cxx @@ -19,7 +19,7 @@ #include "med_outils.hxx" #include "med.hxx" -#if defined(IRIX64) +#if defined(HAVE_F77INT64) #define MED_INTEGER MED_INT64 #else #define MED_INTEGER MED_INT32 diff --git a/src/MEDWrapper/V2_1/Core/MEDchampCr.cxx b/src/MEDWrapper/V2_1/Core/MEDchampCr.cxx index 13fe5520a..5e9718541 100644 --- a/src/MEDWrapper/V2_1/Core/MEDchampCr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDchampCr.cxx @@ -31,7 +31,6 @@ MEDchampCr(med_idt fid, char *champ, med_type_champ type, char *comp, med_err ret = 0; med_idt root,gid; char chemin[MED_TAILLE_CHA+1]; - med_size dimd[1]; med_int _type = (med_int) type; /* diff --git a/src/MEDWrapper/V2_1/Core/MEDchampEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDchampEcr.cxx index 14f5090bc..240c69b28 100644 --- a/src/MEDWrapper/V2_1/Core/MEDchampEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDchampEcr.cxx @@ -177,8 +177,8 @@ MEDchampEcr(med_idt fid, char *maa, char *cha,unsigned char *val,med_mode_switch else psize = i; - pfltabtmp = (med_int *) malloc (sizeof(med_int)*psize); - pfltab = (med_ssize *) malloc (sizeof(med_ssize)*psize); + pfltabtmp = (med_int *) malloc (sizeof(med_int)*(size_t)psize); + pfltab = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)psize); if ((ret = MEDprofilLire(fid,pfltabtmp,pflname)) < 0) return -1; for (i=0;i<psize;i++) @@ -203,7 +203,7 @@ MEDchampEcr(med_idt fid, char *maa, char *cha,unsigned char *val,med_mode_switch break; case MED_INT32 : -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(datagroup2,MED_NOM_CO,MED_INT64,interlace,ncomp,numco,psize,pfltab,ngauss,dimd,val, mode)) < 0) return -1; @@ -215,7 +215,7 @@ MEDchampEcr(med_idt fid, char *maa, char *cha,unsigned char *val,med_mode_switch break; case MED_INT64 : -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(datagroup2,MED_NOM_CO,MED_INT64,interlace,ncomp,numco,psize,pfltab,ngauss,dimd,val, mode)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDchampInfo.cxx b/src/MEDWrapper/V2_1/Core/MEDchampInfo.cxx index 6ff52b375..c3634ef10 100644 --- a/src/MEDWrapper/V2_1/Core/MEDchampInfo.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDchampInfo.cxx @@ -28,7 +28,8 @@ MEDchampInfo(med_idt fid,int indice,char *champ, { med_err ret=0; med_idt gid; - char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1]; + char chemin[MED_TAILLE_CHA+MED_TAILLE_LNOM+1]; //SRN: Changed to MED_TAILLE_LNOM to avoid a crash + // in case if a field name longer than MED_TAILLE_NOM int num; /* @@ -44,6 +45,8 @@ MEDchampInfo(med_idt fid,int indice,char *champ, if ((ret = _MEDobjetIdentifier(fid,chemin,num,champ)) < 0) return -1; + if(strlen(champ) > MED_TAILLE_NOM) return -1; + /* * Si le Data Group cha n'existe pas => erreur */ @@ -55,8 +58,15 @@ MEDchampInfo(med_idt fid,int indice,char *champ, /* * La liste des attributs */ - if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,(med_int*) type)) < 0) + + // MPV 05.10.2006 + // BUG IPAL 13482: on 64bit Mandriva OS sizeof(med_int)=8, but sizeof(med_type_champ)=4 + med_int aType; + // if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,(med_int*) type)) < 0) + if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&aType)) < 0) return -1; + *type = (med_type_champ)aType; + if ((ret = _MEDattrStringLire(gid,MED_NOM_NOM,ncomp*MED_TAILLE_PNOM, comp)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDchampLire.cxx b/src/MEDWrapper/V2_1/Core/MEDchampLire.cxx index ad21a6840..ddb01e8c8 100644 --- a/src/MEDWrapper/V2_1/Core/MEDchampLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDchampLire.cxx @@ -104,8 +104,8 @@ MEDchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switc else psize = i; - pfltabtmp = (med_int *) malloc (sizeof(med_int)*psize); - pfltab = (med_ssize *) malloc (sizeof(med_ssize)*psize); + pfltabtmp = (med_int *) malloc (sizeof(med_int)*(size_t)psize); + pfltab = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)psize); if ((ret = MEDprofilLire(fid,pfltabtmp,profil)) < 0) return -1; for (i=0;i<psize;i++) @@ -146,9 +146,9 @@ MEDchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switc psize,pfltab,ngauss,val))< 0) return -1; break; - + case MED_INT32 : -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(datagroup2,MED_NOM_CO,MED_INT64, interlace,ncomp,numco, psize,pfltab,ngauss,val))< 0) @@ -162,7 +162,7 @@ MEDchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switc break; case MED_INT64 : -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(datagroup2,MED_NOM_CO,MED_INT64, interlace,ncomp,numco, psize,pfltab,ngauss,val))< 0) diff --git a/src/MEDWrapper/V2_1/Core/MEDconnEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDconnEcr.cxx index a8395b5c2..591b9fd88 100644 --- a/src/MEDWrapper/V2_1/Core/MEDconnEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDconnEcr.cxx @@ -106,7 +106,7 @@ MEDconnEcr(med_idt fid,char *maa, med_int mdim, med_int *connectivite,med_mode_s return -1; } dimd[0] = nbre*taille; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT64,mode_switch,(med_size)taille,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char*) connectivite,mode)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDconnLire.cxx b/src/MEDWrapper/V2_1/Core/MEDconnLire.cxx index 9e6c29f48..65ecfaeab 100644 --- a/src/MEDWrapper/V2_1/Core/MEDconnLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDconnLire.cxx @@ -37,12 +37,12 @@ MEDconnLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_sw char nom_ent[MED_TAILLE_NOM_ENTITE+1]; char nom_geo[MED_TAILLE_NOM_ENTITE+1]; char nom_dataset[MED_TAILLE_NOM_ENTITE+1]; - med_ssize * pfltab; + med_ssize * pfltab = NULL; med_size psize; int dim,nnoe,ndes; int nsup = 0; int taille; - int i,j; + int i; /* * On inhibe le gestionnaire d'erreur HDF 5 @@ -104,7 +104,7 @@ MEDconnLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_sw taille = nsup + ndes; if ( psizetmp != MED_NOPF ) { psize = psizetmp; - pfltab = (med_ssize *) malloc (sizeof(med_ssize)*psize); + pfltab = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)psize); for (i=0;i<psizetmp;i++) pfltab[i] = (med_ssize) (pfltabtmp[i]); }; @@ -116,7 +116,7 @@ MEDconnLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_sw } -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(geoid,nom_dataset,MED_INT64, mode_switch,(med_size)taille,MED_ALL, psize,pfltab,MED_NOPG, diff --git a/src/MEDWrapper/V2_1/Core/MEDcoordLire.cxx b/src/MEDWrapper/V2_1/Core/MEDcoordLire.cxx index 1335f1a1b..c020bb8bc 100644 --- a/src/MEDWrapper/V2_1/Core/MEDcoordLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDcoordLire.cxx @@ -34,10 +34,9 @@ MEDcoordLire(med_idt fid, char *maa, med_int mdim, med_float *coo, med_idt maaid, noeid, dataset; med_err ret; char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1]; - int i,j; - med_float *new_coo; + int i; med_int type_rep_int; - med_ssize * pfltab; + med_ssize * pfltab = NULL; /* * On inhibe le gestionnaire d'erreur @@ -63,7 +62,7 @@ MEDcoordLire(med_idt fid, char *maa, med_int mdim, med_float *coo, * Convertion de med_int en med_ssize */ if ( psize != MED_NOPF ) { - pfltab = (med_ssize *) malloc (sizeof(med_ssize)*psize); + pfltab = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)psize); for (i=0;i<psize;i++) pfltab[i] = (med_ssize) pfltabtmp[i]; } diff --git a/src/MEDWrapper/V2_1/Core/MEDdatasetNumEcrire.cxx b/src/MEDWrapper/V2_1/Core/MEDdatasetNumEcrire.cxx index bc9d6ff73..f2b1ce8d1 100644 --- a/src/MEDWrapper/V2_1/Core/MEDdatasetNumEcrire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDdatasetNumEcrire.cxx @@ -96,7 +96,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, the file read under SGI is incorrect 2) Compaq OSF/1 is LE, since we force SGI64,SUN4SOL2,HP to write double in LE even if they are BE, mips OSF/1 must be BE REM : Be careful of compatibility between MED files when changing this (med2.2) */ -#if defined(PCLINUX) || defined(OSF1) +#if defined(PCLINUX) || defined(PCLINUX64) || defined(PCLINUX64_32) || defined(OSF1) || defined( PPRO_NT ) type_hdf = H5T_IEEE_F64BE; #else type_hdf = H5T_IEEE_F64LE; @@ -104,7 +104,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, break; case MED_INT32 : -#if defined(PCLINUX) +#if defined(PCLINUX) || defined(PCLINUX64) || defined(PCLINUX64_32) type_hdf = H5T_STD_I32BE; if ((H5Tconvert(H5T_NATIVE_INT,H5T_STD_I32BE,(hsize_t)*size,(void *)val,NULL,(hid_t)0)) < 0) return -1; @@ -152,13 +152,13 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/ if ( fixdim != MED_ALL) { - firstdim = fixdim-1; - lastdim = fixdim; + firstdim = (int)fixdim-1; + lastdim = (int)fixdim; dimutil = 1; } else { firstdim = 0; - lastdim = nbdim; - dimutil = nbdim; + lastdim = (int)nbdim; + dimutil = (int)nbdim; } count [0] = (*size)/(nbdim); @@ -197,8 +197,8 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, pflmem = (med_size *) malloc (sizeof(med_size)*pcount[0]); pfldsk = (med_size *) malloc (sizeof(med_size)*pcount[0]); #else - pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); - pfldsk = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); + pflmem = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)pcount[0]); + pfldsk = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)pcount[0]); #endif switch(pflmod) @@ -213,7 +213,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, for (i=0; i < psize; i++) /* i balaye les Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pflmem[index] = (pfltab[i]-1)*ngauss*nbdim + j*nbdim+dim; pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; } @@ -226,10 +226,10 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(memspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) + if ( (ret = H5Sselect_elements(memspace,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pflmem ) ) <0) return -1; - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -248,7 +248,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, for (i=0; i < psize; i++) /* i balaye les Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pflmem[index] = i*ngauss*nbdim + j*nbdim+dim; pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; } @@ -261,10 +261,10 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(memspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) + if ( (ret = H5Sselect_elements(memspace,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pflmem ) ) <0) return -1; - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -311,13 +311,13 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, if ( fixdim != MED_ALL) { - firstdim = fixdim-1; - lastdim = fixdim; + firstdim = (int)fixdim-1; + lastdim = (int)fixdim; dimutil = 1; } else { firstdim = 0; - lastdim = nbdim; - dimutil = nbdim; + lastdim = (int)nbdim; + dimutil = (int)nbdim; } pflsize [0] = psize*ngauss*nbdim; @@ -325,7 +325,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, #ifdef HDF_NEW_API pfldsk = (med_size *) malloc(sizeof(med_size)*pcount[0]); #else - pfldsk = (med_ssize *) malloc(sizeof(med_ssize)*pcount[0]); + pfldsk = (med_ssize *) malloc(sizeof(med_ssize)*(size_t)pcount[0]); #endif switch(pflmod) @@ -336,7 +336,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, for (i=0; i < psize; i++) /* i balaye le nbre d'Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pfldsk[index] = dim*count[0]+(pfltab[i]-1)*ngauss+j; } } @@ -345,7 +345,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,(size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -366,7 +366,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, #ifdef HDF_NEW_API pflmem = (med_size *) malloc (sizeof(med_size)*pcount[0]); #else - pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); + pflmem = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)pcount[0]); #endif /* Le profil COMPACT est contigĂ¼e, mais il est possible que l'on selectionne uniquemenent une dimension*/ @@ -375,7 +375,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, for (i=0; i < psize; i++) /* i balaye le nbre d'Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pflmem[index] = dim*(psize*ngauss) + (pfltab[i]-1)*ngauss+j; pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; } @@ -388,10 +388,10 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET,pcount[0], (const hssize_t **) pflmem ) ) <0) + if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET,(size_t)pcount[0], (const hssize_t **) pflmem ) ) <0) return -1; - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,(size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -428,7 +428,7 @@ _MEDdatasetNumEcrire(med_idt pere,char *nom, med_type_champ type, if ((ret = H5Dclose(dataset)) < 0) return -1; -#if defined(PCLINUX) +#if defined(PCLINUX) || defined(PCLINUX64) || defined(PCLINUX64_32) if (type == MED_INT32) if ((H5Tconvert(H5T_STD_I32BE,H5T_NATIVE_INT,(hsize_t)*size,(void *)val,NULL,(hid_t)0)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDdatasetNumLire.cxx b/src/MEDWrapper/V2_1/Core/MEDdatasetNumLire.cxx index e6ce9c37a..8420c22f5 100644 --- a/src/MEDWrapper/V2_1/Core/MEDdatasetNumLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDdatasetNumLire.cxx @@ -92,10 +92,11 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, { case MED_REEL64 : /* 1) IA32 is LE but due to an (?HDF convertion BUG?) when using H5T_NATIVE_DOUBLE/MED_REEL64? under PCLINUX - the file read under SGI is incorrect + the file read under SGI is incorrect 2) Compaq OSF/1 is LE, since we force SGI64,SUN4SOL2,HP to write double in LE even if they are BE, mips OSF/1 must be BE - REM : Be careful of compatibility between MED files when changing this (med2.2) */ -#if defined(PCLINUX) || defined(OSF1) + REM : Be careful of compatibility between MED files when changing this (med2.2) + 3) PPRO_NT is added for med2.1.6 support under Win32 */ +#if defined(PCLINUX) || defined(OSF1) || defined(PPRO_NT) || defined(PCLINUX64) || defined(PCLINUX64_32) type_hdf = H5T_IEEE_F64BE; #else type_hdf = H5T_IEEE_F64LE; @@ -135,13 +136,13 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, /*Initialisation des indices de boucle du traitement de l'entrelacement en fonction de la dimension fixee*/ if ( fixdim != MED_ALL) { - firstdim = fixdim-1; - lastdim = fixdim; + firstdim = (int)fixdim-1; + lastdim = (int)fixdim; dimutil = 1; } else { firstdim = 0; - lastdim = nbdim; - dimutil = nbdim; + lastdim = (int)nbdim; + dimutil = (int)nbdim; } count [0] = (*size)/(nbdim); @@ -181,8 +182,8 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, pflmem = (med_size *) malloc (sizeof(med_size)*pcount[0]); pfldsk = (med_size *) malloc (sizeof(med_size)*pcount[0]); #else - pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); - pfldsk = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); + pflmem = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)pcount[0]); + pfldsk = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)pcount[0]); #endif switch(pflmod) @@ -197,7 +198,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, for (i=0; i < psize; i++) /* i balaye les Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pflmem[index] = (pfltab[i]-1)*ngauss*nbdim + j*nbdim+dim; pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; } @@ -210,10 +211,10 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) + if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pflmem ) ) <0) return -1; - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -232,7 +233,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, for (i=0; i < psize; i++) /* i balaye les Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pflmem[index] = i*ngauss*nbdim + j*nbdim+dim; pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; } @@ -245,10 +246,10 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) + if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pflmem ) ) <0) return -1; - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -264,7 +265,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, free(pflmem); free(pfldsk); } - + break; case MED_NO_INTERLACE : @@ -294,13 +295,13 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, if ( fixdim != MED_ALL) { - firstdim = fixdim-1; - lastdim = fixdim; + firstdim = (int)fixdim-1; + lastdim = (int)fixdim; dimutil = 1; } else { firstdim = 0; - lastdim = nbdim; - dimutil = nbdim; + lastdim = (int)nbdim; + dimutil = (int)nbdim; } pflsize [0] = psize*ngauss*nbdim; @@ -308,7 +309,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, #ifdef HDF_NEW_API pfldsk = (med_size *) malloc(sizeof(med_size)*pcount[0]); #else - pfldsk = (med_ssize *) malloc(sizeof(med_ssize)*pcount[0]); + pfldsk = (med_ssize *) malloc(sizeof(med_ssize)*(size_t)pcount[0]); #endif switch(pflmod) @@ -319,7 +320,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, for (i=0; i < psize; i++) /* i balaye le nbre d'Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); + index = i*ngauss+j + (dim-firstdim)*((int)psize*ngauss); pfldsk[index] = dim*count[0]+(pfltab[i]-1)*ngauss+j; } } @@ -328,7 +329,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,(size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -349,18 +350,22 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, #ifdef HDF_NEW_API pflmem = (med_size *) malloc (sizeof(med_size)*pcount[0]); #else - pflmem = (med_ssize *) malloc (sizeof(med_ssize)*pcount[0]); + pflmem = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)pcount[0]); #endif /* Le profil COMPACT est contigĂ¼e, mais il est possible que l'on selectionne uniquemenent une dimension*/ + index = 0; for (dim=firstdim; dim < lastdim; dim++) { for (i=0; i < psize; i++) /* i balaye le nbre d'Ă©lements du profil */ for (j=0; j < ngauss; j++) { - index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); - pflmem[index] = dim*(psize*ngauss) + (pfltab[i]-1)*ngauss+j; - pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; +// index = i*ngauss+j + (dim-firstdim)*(psize*ngauss); +// pflmem[index] = dim*(psize*ngauss) + (pfltab[i]-1)*ngauss+j; +// pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; + pflmem[index] = ( (dim*psize) + i )*ngauss + j; + pfldsk[index] = dim*count[0] + (pfltab[i]-1)*ngauss+j; + index++; } } @@ -371,10 +376,10 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hsize_t **) pfldsk ) ) <0) return -1; #else - if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, pcount[0], (const hssize_t **) pflmem ) ) <0) + if ( (ret = H5Sselect_elements(memspace ,H5S_SELECT_SET, (size_t)pcount[0], (const hssize_t **) pflmem ) ) <0) return -1; - if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,pcount[0], (const hssize_t **) pfldsk ) ) <0) + if ( (ret = H5Sselect_elements(dataspace,H5S_SELECT_SET,(size_t)pcount[0], (const hssize_t **) pfldsk ) ) <0) return -1; #endif @@ -389,7 +394,7 @@ _MEDdatasetNumLire(med_idt pere,char *nom,med_type_champ type, } free(pfldsk); - + }; break; diff --git a/src/MEDWrapper/V2_1/Core/MEDequivEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDequivEcr.cxx index dfa3f72b1..9b14c4f40 100644 --- a/src/MEDWrapper/V2_1/Core/MEDequivEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDequivEcr.cxx @@ -87,7 +87,7 @@ MEDequivEcr(med_idt fid, char *maa, char *eq, med_int *corr, med_int n, dimd[0] = 2*n; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_COR,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char*) corr,mode)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDequivLire.cxx b/src/MEDWrapper/V2_1/Core/MEDequivLire.cxx index 824e21c99..d6a510cfd 100644 --- a/src/MEDWrapper/V2_1/Core/MEDequivLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDequivLire.cxx @@ -71,7 +71,7 @@ MEDequivLire(med_idt fid, char *maa, char *eq, med_int *corr, med_int n, } if ((datagroup = _MEDdatagroupOuvrir(eqid,nomdatagroup)) < 0) return -1; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(datagroup,MED_NOM_COR,MED_INT64, MED_NO_INTERLACE,1,MED_ALL, MED_NOPF,0,MED_NOPG, diff --git a/src/MEDWrapper/V2_1/Core/MEDfamCr.cxx b/src/MEDWrapper/V2_1/Core/MEDfamCr.cxx index 19faf22f8..a4ed21531 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfamCr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfamCr.cxx @@ -118,7 +118,7 @@ MEDfamCr(med_idt fid,char* maa,char *famille,med_int numero, * Le Data Set "IDE" */ dimd[0] = n_attr; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_IDE,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char *)attr_ident,MED_REMP)) < 0) return -1; @@ -132,7 +132,7 @@ MEDfamCr(med_idt fid,char* maa,char *famille,med_int numero, * Le Data Set "VAL" */ dimd[0] = n_attr; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_VAL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char*)attr_val,MED_REMP)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDfamEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDfamEcr.cxx index e6beb4bf9..255d22f7e 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfamEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfamEcr.cxx @@ -86,7 +86,7 @@ MEDfamEcr(med_idt fid,char *maa, med_int *fam, med_int n, med_mode_acces mode, else root = geoid; dimd[0] = n; -#if defined(IRIX64) || defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_FAM,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char*)fam,mode)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDfamInfo.cxx b/src/MEDWrapper/V2_1/Core/MEDfamInfo.cxx index b4527b122..6dd555ee3 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfamInfo.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfamInfo.cxx @@ -103,7 +103,7 @@ MEDfamInfo(med_idt fid,char *maa,int indice, char *famille, /* * Le Data Set "IDE" */ -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(datagroup,MED_NOM_IDE,MED_INT64, MED_NO_INTERLACE,1,MED_ALL, MED_NOPF,0,MED_NOPG, @@ -120,7 +120,7 @@ MEDfamInfo(med_idt fid,char *maa,int indice, char *famille, /* * Le Data Set "VAL" */ -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(datagroup,MED_NOM_VAL,MED_INT64, MED_NO_INTERLACE,1,MED_ALL, MED_NOPF,0,MED_NOPG, diff --git a/src/MEDWrapper/V2_1/Core/MEDfamLire.cxx b/src/MEDWrapper/V2_1/Core/MEDfamLire.cxx index 501b98f7c..0dad71fbb 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfamLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfamLire.cxx @@ -81,7 +81,7 @@ MEDfamLire(med_idt fid,char *maa, med_int *fam, med_int n, root = entid; else root = geoid; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(root,MED_NOM_FAM,MED_INT64, MED_NO_INTERLACE,1,MED_ALL, MED_NOPF,0,MED_NOPG, diff --git a/src/MEDWrapper/V2_1/Core/MEDfichDesEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDfichDesEcr.cxx index e33569305..8bdb5dc7d 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfichDesEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfichDesEcr.cxx @@ -26,7 +26,6 @@ namespace med_2_1{ med_err MEDfichDesEcr(med_idt fid, char *des, med_mode_acces mode) { - med_idt attr; med_idt root; med_err ret; char nom[] = MED_NOM_DESCRIPTEUR; diff --git a/src/MEDWrapper/V2_1/Core/MEDfichEntete.cxx b/src/MEDWrapper/V2_1/Core/MEDfichEntete.cxx index b191d3a4a..d31fae967 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfichEntete.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfichEntete.cxx @@ -26,7 +26,7 @@ namespace med_2_1{ med_err MEDfichEntete(med_idt fid, med_fich_info quoi, char str[]) { - med_idt atid, root; + med_idt root; med_err ret; char locale[MED_TAILLE_DESC+1]; char chemin[MED_TAILLE_MAA+1]; @@ -65,7 +65,7 @@ MEDfichEntete(med_idt fid, med_fich_info quoi, char str[]) return -1; strcpy(str,locale); - if ((ret == _MEDdatagroupFermer(root)) < 0) + if ((ret = _MEDdatagroupFermer(root)) < 0) return -1; break; diff --git a/src/MEDWrapper/V2_1/Core/MEDfstring.cxx b/src/MEDWrapper/V2_1/Core/MEDfstring.cxx index e1bc4faae..3410f0914 100644 --- a/src/MEDWrapper/V2_1/Core/MEDfstring.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDfstring.cxx @@ -32,7 +32,7 @@ _MEDfstring(char *chaine, med_int longueur_fixee) if (longueur_fixee == 0 ) return 0; - longueur_reelle = strlen(chaine); + longueur_reelle = (int)strlen(chaine); if (longueur_fixee < longueur_reelle) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDgridInfo.cxx b/src/MEDWrapper/V2_1/Core/MEDgridInfo.cxx index 43de1b2dd..35eceff84 100644 --- a/src/MEDWrapper/V2_1/Core/MEDgridInfo.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDgridInfo.cxx @@ -47,11 +47,13 @@ MEDgridInfo(med_idt fid, int indice, med_int *isAGrid, med_grid_type *typ) maaid = _MEDdatagroupOuvrir(fid, chemin); if (maaid < 0) return(-1); - if (_MEDattrEntierLire(maaid, MED_NOM_GRD, typ) < 0) { + med_int aTmpType; // MPV bug IPAL 13621: for 64bits platform read 64 bits (not 32 - as for type) + if (_MEDattrEntierLire(maaid, MED_NOM_GRD, &aTmpType) < 0) { *isAGrid = 0; } else { *isAGrid = 1; }; + *typ = (med_grid_type)aTmpType;// MPV bug IPAL 13621: now use this 64bits value to set enumeration if (_MEDdatagroupFermer(maaid) < 0) return(-1); return(0); diff --git a/src/MEDWrapper/V2_1/Core/MEDlFichDes.cxx b/src/MEDWrapper/V2_1/Core/MEDlFichDes.cxx index 7e63c919b..4aa35898f 100644 --- a/src/MEDWrapper/V2_1/Core/MEDlFichDes.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDlFichDes.cxx @@ -68,12 +68,12 @@ MEDlFichDes(med_idt fid) return -1; } - longueur = strlen(des); + longueur = (med_int)strlen(des); /* * fermetures */ - if ((ret == _MEDdatagroupFermer(root)) < 0) + if ((ret = _MEDdatagroupFermer(root)) < 0) return -1; return longueur; diff --git a/src/MEDWrapper/V2_1/Core/MEDnProfil.cxx b/src/MEDWrapper/V2_1/Core/MEDnProfil.cxx index 5dcb6482f..ed8109944 100644 --- a/src/MEDWrapper/V2_1/Core/MEDnProfil.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDnProfil.cxx @@ -25,7 +25,6 @@ med_int MEDnProfil(med_idt fid) { int n; - med_err ret; _MEDmodeErreurVerrouiller(); diff --git a/src/MEDWrapper/V2_1/Core/MEDnumEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDnumEcr.cxx index d72b6ce9f..4d26d4cf9 100644 --- a/src/MEDWrapper/V2_1/Core/MEDnumEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDnumEcr.cxx @@ -86,7 +86,7 @@ MEDnumEcr(med_idt fid,char *maa, med_int *num, med_int n, med_mode_acces mode, else root = geoid; dimd[0] = n; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char*) num,mode)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDnumLire.cxx b/src/MEDWrapper/V2_1/Core/MEDnumLire.cxx index 938964060..632caa55c 100644 --- a/src/MEDWrapper/V2_1/Core/MEDnumLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDnumLire.cxx @@ -81,7 +81,7 @@ MEDnumLire(med_idt fid,char *maa, med_int *num, med_int n, root = entid; else root = geoid; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(root,MED_NOM_NUM,MED_INT64, MED_NO_INTERLACE,1,MED_ALL, MED_NOPF,0,MED_NOPG, diff --git a/src/MEDWrapper/V2_1/Core/MEDouvrir.cxx b/src/MEDWrapper/V2_1/Core/MEDouvrir.cxx index 0d259deb6..0d40f139e 100644 --- a/src/MEDWrapper/V2_1/Core/MEDouvrir.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDouvrir.cxx @@ -19,7 +19,9 @@ #include "med.hxx" #include "med_outils.hxx" -#ifdef PPRO_NT +//#ifdef PPRO_NT +#ifdef WIN32 +#include <io.h> #define F_OK 0 #else #include <unistd.h> @@ -44,10 +46,10 @@ MEDouvrir(char *nom, med_mode_acces mode_acces) { case MED_LECT : if (access(nom,F_OK)) - return -1; + return -1; else - if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0) - return -1; + if ((fid = _MEDfichierOuvrir(nom,mode_acces)) < 0) + return -1; break; case MED_ECRI : diff --git a/src/MEDWrapper/V2_1/Core/MEDpasdetempsInfo.cxx b/src/MEDWrapper/V2_1/Core/MEDpasdetempsInfo.cxx index e95f6019c..53a2e599d 100644 --- a/src/MEDWrapper/V2_1/Core/MEDpasdetempsInfo.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDpasdetempsInfo.cxx @@ -31,7 +31,6 @@ MEDpasdetempsInfo(med_idt fid,char *champ { med_err ret=0; - med_int gauss_size; med_idt gid; char chemin[(MED_TAILLE_CHA+MED_TAILLE_NOM+1)+(2*MED_TAILLE_NOM_ENTITE+2)+2*MED_MAX_PARA+1]; int num; diff --git a/src/MEDWrapper/V2_1/Core/MEDprofilEcr.cxx b/src/MEDWrapper/V2_1/Core/MEDprofilEcr.cxx index b2d1e97b8..dd2debfa0 100644 --- a/src/MEDWrapper/V2_1/Core/MEDprofilEcr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDprofilEcr.cxx @@ -27,7 +27,7 @@ namespace med_2_1{ med_err MEDprofilEcr(med_idt fid,med_int *pflval,med_int n,char *nom) { - med_idt root, pid, did; + med_idt root, pid; med_size dimd[1]; med_err ret; char chemin[MED_TAILLE_PROFILS+1]; @@ -65,7 +65,7 @@ MEDprofilEcr(med_idt fid,med_int *pflval,med_int n,char *nom) * On stocke le profil dans un dataset */ dimd[0] = n; -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumEcrire(pid,MED_NOM_PFL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,0,MED_NOPG,dimd, (unsigned char*) pflval,MED_REMP)) < 0) return -1; diff --git a/src/MEDWrapper/V2_1/Core/MEDprofilLire.cxx b/src/MEDWrapper/V2_1/Core/MEDprofilLire.cxx index 7621f82d8..f59841476 100644 --- a/src/MEDWrapper/V2_1/Core/MEDprofilLire.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDprofilLire.cxx @@ -28,7 +28,7 @@ med_err MEDprofilLire(med_idt fid,med_int *pflval, char *nom) { med_err ret = 0; - med_idt pid,did; + med_idt pid; char chemin[MED_TAILLE_PROFILS+MED_TAILLE_NOM+1]; /* @@ -47,7 +47,7 @@ MEDprofilLire(med_idt fid,med_int *pflval, char *nom) /* * Lecture du profil */ -#if defined(IRIX64)||defined(OSF1) +#if defined(HAVE_F77INT64) if ((ret = _MEDdatasetNumLire(pid,MED_NOM_PFL,MED_INT64, MED_NO_INTERLACE,1,MED_ALL, MED_NOPF,0,MED_NOPG, diff --git a/src/MEDWrapper/V2_1/Core/MEDunvCr.cxx b/src/MEDWrapper/V2_1/Core/MEDunvCr.cxx index a1bcd9843..489cdf1ab 100644 --- a/src/MEDWrapper/V2_1/Core/MEDunvCr.cxx +++ b/src/MEDWrapper/V2_1/Core/MEDunvCr.cxx @@ -25,7 +25,8 @@ #include <stdio.h> #include <time.h> -#ifdef PPRO_NT +//#ifdef PPRO_NT +#ifdef WIN32 // Windows Header Files: #include <windows.h> #include <Lmcons.h> @@ -43,7 +44,8 @@ MEDunvCr(med_idt fid, char *maa) char chemin [MED_TAILLE_MAA+MED_TAILLE_NOM+1]; char nomu [MED_TAILLE_LNOM+1]; time_t temps; -#ifdef PPRO_NT +//#ifdef PPRO_NT +#ifdef WIN32 struct timeb tp; char lpBuffer [UNLEN+1]; long nSize = UNLEN+1; @@ -69,15 +71,16 @@ MEDunvCr(med_idt fid, char *maa) * Creation/Ecriture de l'attribut nom universel */ -#ifdef PPRO_NT - if ( GetUserName(lpBuffer,&nSize) == 0 ) return -1; +//#ifdef PPRO_NT +#ifdef WIN32 + if ( GetUserName(lpBuffer,LPDWORD(&nSize)) == 0 ) return -1; if ( nSize > MED_TAILLE_NOM ) nSize = MED_TAILLE_NOM; strncpy(nomu,lpBuffer,nSize); strcat(nomu," "); temps=time(&temps); strcat(nomu,ctime(&temps)); ftime(&tp); - nSize = strlen(nomu)-1; + nSize = (long)strlen(nomu)-1; if ( sprintf(&nomu[nSize]," %hu",tp.millitm) < 0 ) return -1; #else if (cuserid(nomu) == (void*) NULL) return -1; diff --git a/src/MEDWrapper/V2_1/Core/Makefile.am b/src/MEDWrapper/V2_1/Core/Makefile.am new file mode 100644 index 000000000..3888cebbc --- /dev/null +++ b/src/MEDWrapper/V2_1/Core/Makefile.am @@ -0,0 +1,169 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : +# Author : +# Module : +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libmed_V2_1.la + +LIB_SRC_TOOLS_HDFI= \ +MEDattrFermer.cxx \ +MEDattrNumEcrire.cxx \ +MEDattrNumLire.cxx \ +MEDattrOuvrir.cxx \ +MEDattrStringEcrire.cxx \ +MEDattrStringLire.cxx \ +MEDdatagroupCreer.cxx \ +MEDdatagroupFermer.cxx \ +MEDdatagroupOuvrir.cxx \ +MEDdatasetFermer.cxx \ +MEDdatasetNumEcrire.cxx \ +MEDdatasetNumLire.cxx \ +MEDdatasetOuvrir.cxx \ +MEDdatasetStringEcrire.cxx \ +MEDdatasetStringLire.cxx \ +MEDfichierCreer.cxx \ +MEDfichierFermer.cxx \ +MEDfichierOuvrir.cxx \ +MEDindiceInfo.cxx \ +MEDindiceNum.cxx \ +MEDmodeErreurVerrouiller.cxx \ +MEDnObjets.cxx \ +MEDobjetIdentifer.cxx + +LIB_SRC_TOOLS_MISC= \ +MED1cstring.cxx MEDnomDataset.cxx \ +MED2cstring.cxx MEDnomEntite.cxx \ +MEDGeometrieElement.cxx MEDnomGeometrie.cxx \ +MEDcstringFree.cxx MEDparametresGeometrie.cxx \ +MEDfstring.cxx + +LIB_SRC_API_CI= \ +MEDchampCr.cxx \ +MEDchampEcr.cxx \ +MEDchampInfo.cxx \ +MEDchampLire.cxx \ +MEDconnEcr.cxx \ +MEDconnLire.cxx \ +MEDcoordEcr.cxx \ +MEDcoordLire.cxx \ +MEDdimLire.cxx \ +MEDelementsEcr.cxx \ +MEDelementsLire.cxx \ +MEDequivCr.cxx \ +MEDequivEcr.cxx \ +MEDequivInfo.cxx \ +MEDequivLire.cxx \ +MEDfam2groA.cxx \ +MEDfam2groB.cxx \ +MEDfamCr.cxx \ +MEDfamEcr.cxx \ +MEDfamInfo.cxx \ +MEDfamLire.cxx \ +MEDfamMaaCr.cxx \ +MEDfamMaaInfo.cxx \ +MEDfamMaaLire.cxx \ +MEDfermer.cxx \ +MEDfichDesEcr.cxx \ +MEDfichEntete.cxx \ +MEDgro2famA.cxx \ +MEDgro2famB.cxx \ +MEDlFichDes.cxx \ +MEDmaaCr.cxx \ +MEDmaaInfo.cxx \ +MEDnChamp.cxx \ +MEDnCorres.cxx \ +MEDnEntMaa.cxx \ +MEDnEntites.cxx \ +MEDnEquiv.cxx \ +MEDnFam.cxx \ +MEDnMaa.cxx \ +MEDnPasdetemps.cxx \ +MEDnProfil.cxx \ +MEDnVal.cxx \ +MEDnValProfil.cxx \ +MEDnbnoisEcr.cxx \ +MEDnbnoisLire.cxx \ +MEDnbnomaEcr.cxx \ +MEDnbnomaLire.cxx \ +MEDnbnosoEcr.cxx \ +MEDnbnosoLire.cxx \ +MEDnoeudsEcr.cxx \ +MEDnoeudsLire.cxx \ +MEDnomEcr.cxx \ +MEDnomLire.cxx \ +MEDnumEcr.cxx \ +MEDnumLire.cxx \ +MEDouvrir.cxx \ +MEDpasdetempsInfo.cxx \ +MEDprofilEcr.cxx \ +MEDprofilLire.cxx \ +MEDprofilInfo.cxx \ +MEDunvCr.cxx \ +MEDunvLire.cxx \ +MEDformatConforme.cxx \ +MEDversionConforme.cxx \ +MEDversionDonner.cxx \ +MEDversionLire.cxx \ +MEDbodyFittedEcr.cxx \ +MEDbodyFittedLire.cxx \ +MEDfamGridEcr.cxx \ +MEDfamGridLire.cxx \ +MEDgridCr.cxx \ +MEDgridEcr.cxx \ +MEDgridInfo.cxx \ +MEDgridLire.cxx \ +MEDnGrid.cxx + +dist_libmed_V2_1_la_SOURCES= \ + $(LIB_SRC_TOOLS_HDFI) \ + $(LIB_SRC_TOOLS_MISC) \ + $(LIB_SRC_API_CI) + +salomeinclude_HEADERS= \ + med.hxx \ + med_proto.hxx \ + hdf5_version2api.hxx + +EXTRA_DIST+= med_outils.hxx \ + med_misc.hxx \ + med_hdfi.hxx \ + med_utils.hxx + +libmed_V2_1_la_CPPFLAGS= -D@MACHINE@ $(HDF5_INCLUDES) $(MED_CPPFLAGS) +libmed_V2_1_la_LDFLAGS= $(HDF5_LIBS) + +# Executables targets +bin_PROGRAMS= mdump_V2_1 test1_V2_1 + +dist_mdump_V2_1_SOURCES= mdump_V2_1.cxx +mdump_V2_1_CPPFLAGS= $(libmed_V2_1_la_CPPFLAGS) +mdump_V2_1_LDADD= $(HDF5_LIBS) libmed_V2_1.la + +dist_test1_V2_1_SOURCES= test1_V2_1.cxx +test1_V2_1_CPPFLAGS= $(libmed_V2_1_la_CPPFLAGS) +test1_V2_1_LDADD= $(HDF5_LIBS) libmed_V2_1.la diff --git a/src/MEDWrapper/V2_1/Core/Makefile.in b/src/MEDWrapper/V2_1/Core/Makefile.in deleted file mode 100644 index 13e62dbe9..000000000 --- a/src/MEDWrapper/V2_1/Core/Makefile.in +++ /dev/null @@ -1,169 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -LIB_SRC_TOOLS_HDFI= \ -MEDattrFermer.cxx \ -MEDattrNumEcrire.cxx \ -MEDattrNumLire.cxx \ -MEDattrOuvrir.cxx \ -MEDattrStringEcrire.cxx \ -MEDattrStringLire.cxx \ -MEDdatagroupCreer.cxx \ -MEDdatagroupFermer.cxx \ -MEDdatagroupOuvrir.cxx \ -MEDdatasetFermer.cxx \ -MEDdatasetNumEcrire.cxx \ -MEDdatasetNumLire.cxx \ -MEDdatasetOuvrir.cxx \ -MEDdatasetStringEcrire.cxx \ -MEDdatasetStringLire.cxx \ -MEDfichierCreer.cxx \ -MEDfichierFermer.cxx \ -MEDfichierOuvrir.cxx \ -MEDindiceInfo.cxx \ -MEDindiceNum.cxx \ -MEDmodeErreurVerrouiller.cxx \ -MEDnObjets.cxx \ -MEDobjetIdentifer.cxx - -LIB_SRC_TOOLS_MISC= \ -MED1cstring.cxx MEDnomDataset.cxx \ -MED2cstring.cxx MEDnomEntite.cxx \ -MEDGeometrieElement.cxx MEDnomGeometrie.cxx \ -MEDcstringFree.cxx MEDparametresGeometrie.cxx \ -MEDfstring.cxx - -LIB_SRC_API_CI= \ -MEDchampCr.cxx \ -MEDchampEcr.cxx \ -MEDchampInfo.cxx \ -MEDchampLire.cxx \ -MEDconnEcr.cxx \ -MEDconnLire.cxx \ -MEDcoordEcr.cxx \ -MEDcoordLire.cxx \ -MEDdimLire.cxx \ -MEDelementsEcr.cxx \ -MEDelementsLire.cxx \ -MEDequivCr.cxx \ -MEDequivEcr.cxx \ -MEDequivInfo.cxx \ -MEDequivLire.cxx \ -MEDfam2groA.cxx \ -MEDfam2groB.cxx \ -MEDfamCr.cxx \ -MEDfamEcr.cxx \ -MEDfamInfo.cxx \ -MEDfamLire.cxx \ -MEDfamMaaCr.cxx \ -MEDfamMaaInfo.cxx \ -MEDfamMaaLire.cxx \ -MEDfermer.cxx \ -MEDfichDesEcr.cxx \ -MEDfichEntete.cxx \ -MEDgro2famA.cxx \ -MEDgro2famB.cxx \ -MEDlFichDes.cxx \ -MEDmaaCr.cxx \ -MEDmaaInfo.cxx \ -MEDnChamp.cxx \ -MEDnCorres.cxx \ -MEDnEntMaa.cxx \ -MEDnEntites.cxx \ -MEDnEquiv.cxx \ -MEDnFam.cxx \ -MEDnMaa.cxx \ -MEDnPasdetemps.cxx \ -MEDnProfil.cxx \ -MEDnVal.cxx \ -MEDnValProfil.cxx \ -MEDnbnoisEcr.cxx \ -MEDnbnoisLire.cxx \ -MEDnbnomaEcr.cxx \ -MEDnbnomaLire.cxx \ -MEDnbnosoEcr.cxx \ -MEDnbnosoLire.cxx \ -MEDnoeudsEcr.cxx \ -MEDnoeudsLire.cxx \ -MEDnomEcr.cxx \ -MEDnomLire.cxx \ -MEDnumEcr.cxx \ -MEDnumLire.cxx \ -MEDouvrir.cxx \ -MEDpasdetempsInfo.cxx \ -MEDprofilEcr.cxx \ -MEDprofilLire.cxx \ -MEDprofilInfo.cxx \ -MEDunvCr.cxx \ -MEDunvLire.cxx \ -MEDformatConforme.cxx \ -MEDversionConforme.cxx \ -MEDversionDonner.cxx \ -MEDversionLire.cxx \ -MEDbodyFittedEcr.cxx \ -MEDbodyFittedLire.cxx \ -MEDfamGridEcr.cxx \ -MEDfamGridLire.cxx \ -MEDgridCr.cxx \ -MEDgridEcr.cxx \ -MEDgridInfo.cxx \ -MEDgridLire.cxx \ -MEDnGrid.cxx - -# Libraries targets - -LIB = libmed_V2_1.la -LIB_SRC = \ - $(LIB_SRC_TOOLS_HDFI) \ - $(LIB_SRC_TOOLS_MISC) \ - $(LIB_SRC_API_CI) - -EXPORT_HEADERS = \ - med.hxx \ - med_proto.hxx \ - hdf5_version2api.hxx - -# Executables targets -BIN = mdump_V2_1 test1_V2_1 -BIN_SRC = - -CPPFLAGS+= -D@MACHINE@ $(HDF5_INCLUDES) - -LDFLAGS+= $(HDF5_LIBS) - -LDFLAGSFORBIN=$(LDFLAGS) - -@CONCLUDE@ diff --git a/src/MEDWrapper/V2_1/Core/mdump_V2_1.cxx b/src/MEDWrapper/V2_1/Core/mdump_V2_1.cxx index 6c959fde4..c211312b2 100644 --- a/src/MEDWrapper/V2_1/Core/mdump_V2_1.cxx +++ b/src/MEDWrapper/V2_1/Core/mdump_V2_1.cxx @@ -258,8 +258,8 @@ int main (int argc, char **argv) char version_hdf[10]; char version_med[10]; med_int nmaa,mdim,nnoe; - med_int nmai[MED_NBR_GEOMETRIE_MAILLE],nfac[MED_NBR_GEOMETRIE_FACE]; - med_int nare[MED_NBR_GEOMETRIE_ARETE]; + //med_int nmai[MED_NBR_GEOMETRIE_MAILLE],nfac[MED_NBR_GEOMETRIE_FACE]; + //med_int nare[MED_NBR_GEOMETRIE_ARETE]; /* nom du maillage */ char nommaa[MED_TAILLE_NOM+1]; /* noeuds */ @@ -945,7 +945,7 @@ int main (int argc, char **argv) /* affichage des resultats */ if (ret == 0) { - fprintf(stdout,"\n- Aretes de type %d : ", nomare[i]); + fprintf(stdout,"\n- Aretes de type %s : ", nomare[i]); fprintf(stdout,"\n - ConnectivitĂ© : \n"); for (j=0;j<naretes[i]*taille;j++) fprintf(stdout," %d ",*(connectivite+j)); diff --git a/src/MEDWrapper/V2_1/Core/med.hxx b/src/MEDWrapper/V2_1/Core/med.hxx index 2fe174f9a..7191ff9fe 100644 --- a/src/MEDWrapper/V2_1/Core/med.hxx +++ b/src/MEDWrapper/V2_1/Core/med.hxx @@ -19,11 +19,13 @@ #ifndef MED_H #define MED_H + extern "C"{ #include <hdf5.h> } namespace med_2_1{ + #define MED_NULL (void *) NULL #define MED_MAX_PARA 20 @@ -32,7 +34,7 @@ namespace med_2_1{ #define MED_TAILLE_IDENT 8 #define MED_TAILLE_NOM 32 #define MED_TAILLE_LNOM 80 -#define MED_TAILLE_PNOM 8 +#define MED_TAILLE_PNOM 8 /* Integration des developpements OCC */ typedef enum {MED_CARTESIAN, MED_POLAR, MED_BODY_FITTED} med_grid_type; @@ -87,37 +89,8 @@ typedef enum {MED_HDF_VERSION, MED_VERSION, MED_FICH_DES} med_fich_info; #define MED_DIM1 1 /* PAS */ #define MED_ALL 0 -#if defined(SUN4SOL2) || defined(PCLINUX) || defined(OSF1_32) || defined(IRIX64_32) || defined(RS6000) -/* interface C/FORTRAN */ -/* this true only with g77 and gcc : we must change it to use directly NOMF_... and INT32 or INT64 - - it will be more simple to understand and to use ! */ -#define NOMF_POST_UNDERSCORE - -/* correspondance des types avec HDF 5 */ -typedef hsize_t med_size; -typedef hssize_t med_ssize; -typedef hid_t med_idt; -typedef herr_t med_err; - -/* types elementaires */ -typedef int med_int; -typedef double med_float; -#endif - -#if defined(HP9000) -/* correspondance des types avec HDF 5 */ -typedef hsize_t med_size; -typedef hssize_t med_ssize; -typedef hid_t med_idt; -typedef herr_t med_err; -/* types elementaires */ -typedef int med_int; -typedef double med_float; -#endif -#if defined(IRIX64) || defined(OSF1) -#define NOMF_POST_UNDERSCORE /* correspondance des types avec HDF 5 */ typedef hsize_t med_size; @@ -126,35 +99,12 @@ typedef hid_t med_idt; typedef herr_t med_err; /* types elementaires */ -typedef long med_int; -typedef double med_float; -#endif - - -#if defined(PPRO_NT) -/* correspondance des types avec HDF 5 */ -typedef hsize_t med_size; -typedef hssize_t med_ssize; -typedef hid_t med_idt; -typedef herr_t med_err; -/* types elementaires */ -typedef int med_int; typedef double med_float; -#endif - - -#if defined(NOMF_PRE_UNDERSCORE) && defined(NOMF_POST_UNDERSCORE) -# define NOMF(x) _##x##_ -#endif -#if defined(NOMF_PRE_UNDERSCORE) && !defined(NOMF_POST_UNDERSCORE) -# define NOMF(x) _##x -#endif -#if !defined(NOMF_PRE_UNDERSCORE) && defined(NOMF_POST_UNDERSCORE) -# define NOMF(x) x##_ -#endif -#if !defined(NOMF_PRE_UNDERSCORE) && !defined(NOMF_POST_UNDERSCORE) -# define NOMF(x) x +#if defined(HAVE_F77INT64) + typedef long med_int; +#else + typedef int med_int; #endif } diff --git a/src/MEDWrapper/V2_1/Core/med_proto.hxx b/src/MEDWrapper/V2_1/Core/med_proto.hxx index 1847b56a8..408afcd4a 100644 --- a/src/MEDWrapper/V2_1/Core/med_proto.hxx +++ b/src/MEDWrapper/V2_1/Core/med_proto.hxx @@ -19,181 +19,199 @@ #ifndef MED_PROTO_H #define MED_PROTO_H +#ifdef WNT + #if defined MEDWRAPPER_V2_1_CORE_EXPORTS + #if defined WIN32 + #define MEDWRAPPER_V2_1_CORE_EXPORT __declspec( dllexport ) + #else + #define MEDWRAPPER_V2_1_CORE_EXPORT + #endif + #else + #if defined WIN32 + #define MEDWRAPPER_V2_1_CORE_EXPORT __declspec( dllimport ) + #else + #define MEDWRAPPER_V2_1_CORE_EXPORT + #endif + #endif +#else + #define MEDWRAPPER_V2_1_CORE_EXPORT +#endif + /* Interface de l'API MED */ namespace med_2_1{ /* Fichier */ -extern med_idt +MEDWRAPPER_V2_1_CORE_EXPORT extern med_idt MEDouvrir(char *nom, med_mode_acces mode_acces); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfermer(med_idt fid); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDlFichDes(med_idt fid); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfichEntete(med_idt fid, med_fich_info quoi, char str[]); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfichDesEcr(med_idt fid, char *des, med_mode_acces mode); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDunvCr(med_idt fid, char *maa); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDunvLire(med_idt fid, char *maa,char *nomu); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDformatConforme(const char * nomfich); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDversionConforme(const char *nom); -extern void +MEDWRAPPER_V2_1_CORE_EXPORT extern void MEDversionDonner(med_int *majeur, med_int *mineur, med_int *release); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDversionLire(med_idt fid, med_int *majeur, med_int *mineur, med_int *release); /* Maillage */ -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDmaaCr(med_idt fid, char *maillage, med_int dim); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDdimLire(med_idt fid, char *maillage); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDmaaInfo(med_idt fid, int indice, char *maillage, med_int *dim); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnMaa(med_idt fid); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnbnosoEcr(med_idt fid, char *nom_maillage,med_int n); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnbnosoLire(med_idt fid,char *nom_maillage); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnbnoisEcr(med_idt fid, char *nom_maillage,med_int n); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnbnoisLire(med_idt fid,char *nom_maillage); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnbnomaEcr(med_idt fid, char *nom_maillage,med_int n); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnbnomaLire(med_idt fid,char *nom_maillage); /* EntMaillage */ -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDconnEcr(med_idt fid,char *maa, med_int mdim, med_int *connectivite,med_mode_switch mode_switch, med_int nbre,med_mode_acces mode,med_entite_maillage type_ent, med_geometrie_element type_geo,med_connectivite type_conn); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDconnLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_switch mode_switch, med_int * pfltab, med_size psize, med_entite_maillage type_ent, med_geometrie_element type_geo,med_connectivite type_conn); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnomEcr(med_idt fid,char *maa, char *nom, med_int n, med_mode_acces mode, med_entite_maillage type_ent,med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnomLire(med_idt fid,char *maa, char *nom, med_int n, med_entite_maillage type_ent,med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnumLire(med_idt fid,char *maa, med_int *num, med_int n, med_entite_maillage type_ent,med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnumEcr(med_idt fid,char *maa, med_int *num, med_int n, med_mode_acces mode, med_entite_maillage type_ent,med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDcoordEcr(med_idt fid, char *maa, med_int mdim, med_float *coo, med_mode_switch mode_coo,med_int n, med_mode_acces mode, med_repere type_rep, char *nom, char *unit); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDcoordLire(med_idt fid, char *maa, med_int mdim, med_float *coo, med_mode_switch mode_coo,med_int numco, med_int * pfltab, med_size psize, med_repere *type_rep, char *nom, char *unit); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnEntMaa(med_idt fid, char *maa, med_table quoi, med_entite_maillage type_ent, med_geometrie_element type_geo, med_connectivite type_conn); /* Resultat */ -extern med_err MEDchampCr(med_idt fid, char *champ, med_type_champ type, char *comp, +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDchampCr(med_idt fid, char *champ, med_type_champ type, char *comp, char *unit,med_int ncomp); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDchampEcr(med_idt fid, char *maa, char *cha,unsigned char *val,med_mode_switch interlace,med_int nbelem,med_int ngauss, med_int numco, char * profil, med_mode_acces mode, med_entite_maillage type_ent, med_geometrie_element type_geo, med_int numdt,char * dt_unit, med_float dt, med_int numo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDchampLire(med_idt fid,char *maa, char *cha, unsigned char *val,med_mode_switch interlace,med_int numco, char *profil,med_entite_maillage type_ent, med_geometrie_element type_geo, med_int numdt, med_int numo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDchampInfo(med_idt fid,int indice,char *champ, med_type_champ *type,char *comp,char *unit, med_int ncomp); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnChamp(med_idt fid, int indice); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnVal(med_idt fid, char *champ, med_entite_maillage typ_ent, med_geometrie_element typ_geo,med_int numdt, med_int numo); /* Famille */ -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamEcr(med_idt fid,char *maa, med_int *fam, med_int n, med_mode_acces mode, med_entite_maillage type_ent, med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamLire(med_idt fid,char *maa, med_int *fam, med_int n, med_entite_maillage type_ent,med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamCr(med_idt fid,char* maa,char *famille,med_int numero, med_int *attr_ident, med_int *attr_val,char *attr_desc,med_int n_attr, char *groupe , med_int n_groupe); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnFam(med_idt fid,char *maa, int indice, med_dim_famille quoi); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamInfo(med_idt fid,char *maa,int indice, char *famille, med_int *numero, med_int *attr_ident, med_int *attr_val, char *attr_desc, med_int *n_attr,char *groupe ,med_int *n_groupe); /* Equivalence */ -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDequivCr(med_idt fid,char *maa, char *eq, char *desc); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDequivLire(med_idt fid, char *maa, char *eq, med_int *corr, med_int n, med_entite_maillage typ_ent,med_geometrie_element typ_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDequivEcr(med_idt fid, char *maa, char *eq, med_int *corr, med_int n, med_mode_acces mode, med_entite_maillage typ_ent, med_geometrie_element typ_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDequivInfo(med_idt fid, char *maa, int ind, char *eq, char *des); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnEquiv(med_idt fid, char *maa); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnCorres(med_idt fid,char *maa,char *eq,med_entite_maillage typ_ent, med_geometrie_element typ_geo); /* Routines de niveau intermediaire */ -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnEntites(med_idt fid,char *maa,med_entite_maillage typ_ent, med_connectivite typ_con); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnoeudsLire(med_idt fid,char *maa,med_int mdim, med_float *coord, med_mode_switch mode_coo, med_repere *repere,char *nomcoo, char *unicoo,char *nom, med_booleen *inom,med_int *num,med_booleen *inum,med_int *fam, med_int nnoeuds); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDnoeudsEcr(med_idt fid,char *maa,med_int mdim,med_float *coord, med_mode_switch mode_coo, med_repere repere,char *nomcoo, char *unicoo,char *nom, med_booleen inom,med_int *num,med_booleen inum,med_int *fam, med_int nnoeuds,med_mode_acces mode); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDelementsEcr(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_switch mode_switch, char *nom,med_booleen inom,med_int *num,med_booleen inum, med_int *fam,med_int nele,med_entite_maillage typ_ent, med_geometrie_element typ_geo,med_connectivite typ_conn,med_mode_acces mode); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDelementsLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_switch mode_switch, char *nom,med_booleen *inom,med_int *num,med_booleen *inum, med_int *fam,med_int nele,med_entite_maillage typ_ent, @@ -203,17 +221,17 @@ MEDelementsLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mod /*(? On enlève le reste ?)*/ -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamMaaInfo(med_idt fid,char *maa,med_int *nfam,med_int *nattc, med_int *ngroc); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamMaaLire(med_idt fid,char *maa, med_int *numfam,med_int *attide, med_int *attval,char *attdes,int *indatt,char *gro,int *indgro, med_int nfamilles); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDfamMaaCr(med_idt fid,char *maa, med_int *numfam,med_int *attide, med_int *attval,char *attdes,int *indatt,char *gro,int *indgro, @@ -221,28 +239,28 @@ MEDfamMaaCr(med_idt fid,char *maa, /* Routines concernant les profils */ -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDprofilInfo(med_idt fid, int indice, char *profil, med_int *n); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnProfil(med_idt fid); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDprofilEcr(med_idt fid,med_int *pflval,med_int n,char *nom); -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnValProfil(med_idt fid, char *nom); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDprofilLire(med_idt fid, med_int *pflval, char *nom); /* Routines concernant les pas de temps/ numĂ©ros d'ordre */ -extern med_int +MEDWRAPPER_V2_1_CORE_EXPORT extern med_int MEDnPasdetemps(med_idt fid,char *cha,med_entite_maillage type_ent, med_geometrie_element type_geo); -extern med_err +MEDWRAPPER_V2_1_CORE_EXPORT extern med_err MEDpasdetempsInfo(med_idt fid,char *champ ,med_entite_maillage type_ent, med_geometrie_element type_geo, int indice, char *maa, med_int * ngauss, med_int * numdt, char * dt_unit, med_float * dt, @@ -250,21 +268,21 @@ MEDpasdetempsInfo(med_idt fid,char *champ /* Grilles */ -med_int MEDnGrid(med_idt fid, char *maa, med_grid n); -med_err MEDgridCr(med_idt fid, char *maillage, med_int dim, med_grid_type typ); -med_err MEDgridInfo(med_idt fid, int indice, med_int *isAGrid, med_grid_type *typ); -med_err MEDgridEcr( +MEDWRAPPER_V2_1_CORE_EXPORT med_int MEDnGrid(med_idt fid, char *maa, med_grid n); +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDgridCr(med_idt fid, char *maillage, med_int dim, med_grid_type typ); +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDgridInfo(med_idt fid, int indice, med_int *isAGrid, med_grid_type *typ); +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDgridEcr( med_idt fid, char *maa, med_int mdim, med_float *coo, med_int nb, med_int dim, med_mode_switch mode_coo, med_repere repere, char *nomcoo, char *unicoo, med_mode_acces mode ); -med_err MEDgridLire( +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDgridLire( med_idt fid, char *maa, med_int mdim, med_float *coo, med_int dim, med_mode_switch mode_coo, med_repere *repere, char *nomcoo, char *unicoo ); -med_err MEDfamGridEcr(med_idt fid, char *maa, med_int *fam, med_int n, med_mode_acces mode, med_entite_maillage type_ent); -med_err MEDfamGridLire(med_idt fid, char *maa, med_int *fam, med_int n, med_entite_maillage type_ent); -med_err MEDbodyFittedEcr( +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDfamGridEcr(med_idt fid, char *maa, med_int *fam, med_int n, med_mode_acces mode, med_entite_maillage type_ent); +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDfamGridLire(med_idt fid, char *maa, med_int *fam, med_int n, med_entite_maillage type_ent); +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDbodyFittedEcr( med_idt fid, char *maa, med_int mdim, med_float *coo, med_int *nbr, med_mode_switch mode_coo, med_repere repere, char *nomcoo, char *unicoo, med_int *fam, med_int nnoeuds, med_mode_acces mode ); -med_err MEDbodyFittedLire( +MEDWRAPPER_V2_1_CORE_EXPORT med_err MEDbodyFittedLire( med_idt fid, char *maa, med_int mdim, med_float *coo, med_mode_switch mode_coo, med_repere *repere, char *nomcoo, char *unicoo, med_int *fam, med_int nnoeuds ); } diff --git a/src/MEDWrapper/V2_1/Makefile.am b/src/MEDWrapper/V2_1/Makefile.am new file mode 100644 index 000000000..984f31eec --- /dev/null +++ b/src/MEDWrapper/V2_1/Makefile.am @@ -0,0 +1,38 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : +# Author : +# Module : +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# if without KERNEL, build only med 2.1 library +if MED_ENABLE_KERNEL + SUBDIRS = Core Wrapper +else !MED_ENABLE_KERNEL + SUBDIRS = Core +endif + +DIST_SUBDIRS = Core Wrapper diff --git a/src/MEDWrapper/V2_1/Makefile.in b/src/MEDWrapper/V2_1/Makefile.in deleted file mode 100644 index 1ccdf813e..000000000 --- a/src/MEDWrapper/V2_1/Makefile.in +++ /dev/null @@ -1,44 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -# if without KERNEL, build only med 2.1 library -ifeq ($(MED_WITH_KERNEL),yes) - SUBDIRS = Core Wrapper -else - SUBDIRS = Core -endif - -@MODULE@ diff --git a/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.cxx b/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.cxx index 50bd0fdc0..eff67b417 100644 --- a/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.cxx +++ b/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.cxx @@ -79,6 +79,13 @@ namespace MED return 8; } + template<> + void + GetVersionRelease<eV2_1>(TInt& majeur, TInt& mineur, TInt& release) + { + MEDversionDonner(&majeur, &mineur, &release); + } + template<> TInt GetNbConn<eV2_1>(EGeometrieElement typmai, @@ -116,29 +123,34 @@ namespace MED myFileName(theFileName) {} - ~TFile(){ + ~TFile() + { Close(); } - void Open(EModeAcces theMode, TErr* theErr = NULL){ + void + Open(EModeAcces theMode, TErr* theErr = NULL) + { if(myCount++ == 0){ char* aFileName = const_cast<char*>(myFileName.c_str()); myFid = MEDouvrir(aFileName,med_mode_acces(theMode)); } if(theErr){ *theErr = TErr(myFid); - INITMSG(MYDEBUG && myFid < 0,"TFile::Open - MED_MODE_ACCES = "<<theMode<<"; myFid = "<<myFid<<endl); + INITMSG(MYDEBUG && myFid < 0,"TFile::Open - MED_MODE_ACCES = "<<theMode<<"; myFid = "<<myFid<<std::endl); }else if(myFid < 0) - EXCEPTION(runtime_error,"TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")"); + EXCEPTION(std::runtime_error, "TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")"); } - const TIdt& Id() const { + const TIdt& Id() const + { if(myFid < 0) - EXCEPTION(runtime_error,"TFile - GetFid() < 0"); + EXCEPTION(std::runtime_error, "TFile - GetFid() < 0"); return myFid; } - void Close(){ + void Close() + { if(--myCount == 0) MEDfermer(myFid); } @@ -151,7 +163,8 @@ namespace MED //--------------------------------------------------------------- - class TFileWrapper{ + class TFileWrapper + { PFile myFile; public: @@ -198,14 +211,17 @@ namespace MED if(theErr && *theErr < 0) return; + TValueHolder<TString, char> aMeshName(theInfo.myName); + TValueHolder<TInt, med_int> aDim(theInfo.myDim); + TErr aRet = MEDmaaInfo(myFile->Id(), theMeshId, - &theInfo.myName[0], - (med_int*)&theInfo.myDim); + &aMeshName, + &aDim); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetMeshInfo - MEDmaaInfo(...)"); + EXCEPTION(std::runtime_error,"GetMeshInfo - MEDmaaInfo(...)"); } @@ -221,15 +237,17 @@ namespace MED return; TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo); + TValueHolder<TString, char> aMeshName(anInfo.myName); + TValueHolder<TInt, med_int> aDim(anInfo.myDim); TErr aRet = MEDmaaCr(myFile->Id(), - &anInfo.myName[0], - anInfo.myDim); + &aMeshName, + aDim); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetMeshInfo - MEDmaaCr(...)"); + EXCEPTION(std::runtime_error,"SetMeshInfo - MEDmaaCr(...)"); } @@ -242,7 +260,10 @@ namespace MED SetMeshInfo(theInfo,eECRI,&aRet); if(aRet < 0) - SetMeshInfo(theInfo,eREMP,theErr); + SetMeshInfo(theInfo,eREMP,&aRet); + + if(theErr) + *theErr = aRet; } @@ -257,9 +278,10 @@ namespace MED return -1; TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo); + TValueHolder<TString, char> aMeshName(anInfo.myName); return MEDnFam(myFile->Id(), - &anInfo.myName[0], + &aMeshName, 0, MED_FAMILLE); } @@ -277,9 +299,10 @@ namespace MED return -1; TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo); + TValueHolder<TString, char> aMeshName(anInfo.myName); return MEDnFam(myFile->Id(), - &anInfo.myName[0], + &aMeshName, theFamId, MED_ATTR); } @@ -297,9 +320,10 @@ namespace MED return -1; TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo); + TValueHolder<TString, char> aMeshName(anInfo.myName); return MEDnFam(myFile->Id(), - &anInfo.myName[0], + &aMeshName, theFamId, MED_GROUPE); } @@ -318,30 +342,35 @@ namespace MED TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - med_int* anAttrId = theInfo.myNbAttr > 0? (med_int*)&theInfo.myAttrId[0]: NULL; - med_int* anAttrVal = theInfo.myNbAttr > 0? (med_int*)&theInfo.myAttrVal[0]: NULL; - char* anAttrDesc = theInfo.myNbAttr > 0? &theInfo.myAttrDesc[0]: NULL; - char* aGroupNames = theInfo.myNbGroup > 0? &theInfo.myGroupNames[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TString, char> aFamilyName(theInfo.myName); + TValueHolder<TInt, med_int> aFamilyId(theInfo.myId); + TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId); + TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal); + TValueHolder<TInt, med_int> aNbAttr(theInfo.myNbAttr); + TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc); + TValueHolder<TInt, med_int> aNbGroup(theInfo.myNbGroup); + TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames); TErr aRet = MEDfamInfo(myFile->Id(), - &aMeshInfo.myName[0], + &aMeshName, theFamId, - &theInfo.myName[0], - (med_int*)&theInfo.myId, - anAttrId, - anAttrVal, - anAttrDesc, - (med_int*)&theInfo.myNbAttr, - aGroupNames, - (med_int*)&theInfo.myNbGroup); + &aFamilyName, + &aFamilyId, + &anAttrId, + &anAttrVal, + &anAttrDesc, + &aNbAttr, + &aGroupNames, + &aNbGroup); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetFamilyInfo - MEDfamInfo - "<< - "&aMeshInfo.myName[0] = '"<<&aMeshInfo.myName[0]<<"'; "<< + EXCEPTION(std::runtime_error,"GetFamilyInfo - MEDfamInfo - "<< + "&aMeshInfo.myName[0] = '"<<&aMeshName<<"'; "<< "theFamId = "<<theFamId<<"; "<< - "&theInfo.myName[0] = '"<<&theInfo.myName[0]<<"'; "<< + "&theInfo.myName[0] = '"<<&aFamilyName<<"'; "<< "theInfo.myId = "<<theInfo.myId); } @@ -360,28 +389,33 @@ namespace MED TFamilyInfo& anInfo = const_cast<TFamilyInfo&>(theInfo); TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; - med_int* anAttrId = anInfo.myNbAttr > 0? (med_int*)&anInfo.myAttrId[0]: NULL; - med_int* anAttrVal = anInfo.myNbAttr > 0? (med_int*)&anInfo.myAttrVal[0]: NULL; - char* anAttrDesc = anInfo.myNbAttr > 0? &anInfo.myAttrDesc[0]: NULL; - char* aGroupNames = anInfo.myNbGroup > 0? &anInfo.myGroupNames[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TString, char> aFamilyName(anInfo.myName); + TValueHolder<TInt, med_int> aFamilyId(anInfo.myId); + TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId); + TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal); + TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr); + TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc); + TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup); + TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames); TErr aRet = MEDfamCr(myFile->Id(), - &aMeshInfo.myName[0], - &anInfo.myName[0], - anInfo.myId, - anAttrId, - anAttrVal, - anAttrDesc, - anInfo.myNbAttr, - aGroupNames, - anInfo.myNbGroup); - - INITMSG(MYDEBUG && aRet,"TVWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<endl); + &aMeshName, + &aFamilyName, + aFamilyId, + &anAttrId, + &anAttrVal, + &anAttrDesc, + aNbAttr, + &aGroupNames, + aNbGroup); + + INITMSG(MYDEBUG && aRet,"TVWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetFamilyInfo - MEDfamCr(...)"); + EXCEPTION(std::runtime_error,"SetFamilyInfo - MEDfamCr(...)"); } @@ -394,7 +428,10 @@ namespace MED SetFamilyInfo(theInfo,eECRI,&aRet); if(aRet < 0) - SetFamilyInfo(theInfo,eREMP,theErr); + SetFamilyInfo(theInfo,eREMP,&aRet); + + if(theErr) + *theErr = aRet; } @@ -410,9 +447,10 @@ namespace MED return -1; TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo); + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); TInt aRet = MEDnEntMaa(myFile->Id(), - &aMeshInfo.myName[0], + &aMeshName, MED_COOR, MED_NOEUD, med_geometrie_element(0), @@ -433,25 +471,39 @@ namespace MED TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch); + TValueHolder<ERepere, med_repere> aSystem(theInfo.mySystem); + TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames); + TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits); + TValueHolder<TString, char> anElemNames(theInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum); + TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem); + TErr aRet = MEDnoeudsLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &theInfo.myCoord[0], - med_mode_switch(theInfo.myModeSwitch), - (med_repere*)&theInfo.mySystem, - &theInfo.myCoordNames[0], - &theInfo.myCoordUnits[0], - &theInfo.myElemNames[0], - (med_booleen*)&theInfo.myIsElemNames, - (med_int*)&theInfo.myElemNum[0], - (med_booleen*)&theInfo.myIsElemNum, - (med_int*)&theInfo.myFamNum[0], - theInfo.myNbElem); + &aMeshName, + aDim, + &aCoord, + aModeSwitch, + &aSystem, + &aCoordNames, + &aCoordUnits, + &anElemNames, + &anIsElemNames, + &anElemNum, + &anIsElemNum, + &aFamNum, + aNbElem); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetNodeInfo - MEDnoeudsLire(...)"); + EXCEPTION(std::runtime_error,"GetNodeInfo - MEDnoeudsLire(...)"); } @@ -469,28 +521,39 @@ namespace MED MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; - char* anElemNames = theInfo.myIsElemNames? &anInfo.myElemNames[0]: NULL; - med_int* anElemNum = theInfo.myIsElemNum? &anInfo.myElemNum[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch); + TValueHolder<ERepere, med_repere> aSystem(anInfo.mySystem); + TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames); + TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits); + TValueHolder<TString, char> anElemNames(anInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum); + TValueHolder<TInt, med_int> aNbElem(anInfo.myNbElem); TErr aRet = MEDnoeudsEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &anInfo.myCoord[0], - med_mode_switch(theInfo.myModeSwitch), - med_repere(theInfo.mySystem), - &anInfo.myCoordNames[0], - &anInfo.myCoordUnits[0], - anElemNames, - med_booleen(theInfo.myIsElemNames), - anElemNum, - med_booleen(theInfo.myIsElemNum), - (med_int*)&anInfo.myFamNum[0], - anInfo.myNbElem, + &aMeshName, + aDim, + &aCoord, + aModeSwitch, + aSystem, + &aCoordNames, + &aCoordUnits, + &anElemNames, + anIsElemNames, + &anElemNum, + anIsElemNum, + &aFamNum, + aNbElem, MED_REMP); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)"); + EXCEPTION(std::runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)"); } @@ -503,7 +566,10 @@ namespace MED SetNodeInfo(theInfo,eECRI,&aRet); if(aRet < 0) - SetNodeInfo(theInfo,eREMP,theErr); + SetNodeInfo(theInfo,eREMP,&aRet); + + if(theErr) + *theErr = aRet; } @@ -557,9 +623,10 @@ namespace MED return -1; MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); return MEDnEntMaa(myFile->Id(), - &aMeshInfo.myName[0], + &aMeshName, MED_CONN, med_entite_maillage(theEntity), med_geometrie_element(theGeom), @@ -578,28 +645,41 @@ namespace MED return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - TInt aNbElem = theInfo.myElemNum.size(); + TInt aNbElem = theInfo.myElemNum->size(); + + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TElemNum, med_int> aConn(theInfo.myConn); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch); + TValueHolder<TString, char> anElemNames(theInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theInfo.myGeom); + TValueHolder<EConnectivite, med_connectivite> aConnMode(theInfo.myConnMode); TErr aRet; aRet = MEDelementsLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - (med_int*)&theInfo.myConn[0], - med_mode_switch(theInfo.myModeSwitch), - &theInfo.myElemNames[0], - (med_booleen*)&theInfo.myIsElemNames, - (med_int*)&theInfo.myElemNum[0], - (med_booleen*)&theInfo.myIsElemNum, - (med_int*)&theInfo.myFamNum[0], + &aMeshName, + aDim, + &aConn, + aModeSwitch, + &anElemNames, + &anIsElemNames, + &anElemNum, + &anIsElemNum, + &aFamNum, aNbElem, - med_entite_maillage(theInfo.myEntity), - med_geometrie_element(theInfo.myGeom), - med_connectivite(theInfo.myConnMode)); + anEntity, + aGeom, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)"); + EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)"); } @@ -617,30 +697,40 @@ namespace MED MED::TCellInfo& anInfo = const_cast<MED::TCellInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; - char* anElemNames = theInfo.myIsElemNames? &anInfo.myElemNames[0]: NULL; - med_int* anElemNum = theInfo.myIsElemNum? &anInfo.myElemNum[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TElemNum, med_int> aConn(anInfo.myConn); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch); + TValueHolder<TString, char> anElemNames(anInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(anInfo.myEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(anInfo.myGeom); + TValueHolder<EConnectivite, med_connectivite> aConnMode(anInfo.myConnMode); TErr aRet; aRet = MEDelementsEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - (med_int*)&anInfo.myConn[0], - med_mode_switch(theInfo.myModeSwitch), - anElemNames, - med_booleen(theInfo.myIsElemNames), - anElemNum, - med_booleen(theInfo.myIsElemNum), - (med_int*)&anInfo.myFamNum[0], + &aMeshName, + aDim, + &aConn, + aModeSwitch, + &anElemNames, + anIsElemNames, + &anElemNum, + anIsElemNum, + &aFamNum, anInfo.myNbElem, - med_entite_maillage(theInfo.myEntity), - med_geometrie_element(theInfo.myGeom), - med_connectivite(theInfo.myConnMode), + anEntity, + aGeom, + aConnMode, MED_REMP); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)"); + EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)"); } @@ -653,7 +743,10 @@ namespace MED SetCellInfo(theInfo,eECRI,&aRet); if(aRet < 0) - SetCellInfo(theInfo,eREMP,theErr); + SetCellInfo(theInfo,eREMP,&aRet); + + if(theErr) + *theErr = aRet; } @@ -695,18 +788,26 @@ namespace MED if(theErr && *theErr < 0) return; + TString aFieldName(256); // Protect from memory problems with too long names + TValueHolder<ETypeChamp, med_type_champ> aType(theInfo.myType); + TValueHolder<TString, char> aCompNames(theInfo.myCompNames); + TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames); + TErr aRet; aRet = MEDchampInfo(myFile->Id(), theFieldId, - &theInfo.myName[0], - (med_type_champ*)&theInfo.myType, - &theInfo.myCompNames[0], - &theInfo.myUnitNames[0], + &aFieldName[0], + &aType, + &aCompNames, + &anUnitNames, theInfo.myNbComp); + + theInfo.SetName(aFieldName); + if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetFieldInfo - MEDchampInfo(...)"); + EXCEPTION(std::runtime_error,"GetFieldInfo - MEDchampInfo(...)"); } @@ -723,18 +824,23 @@ namespace MED MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo); + TValueHolder<TString, char> aFieldName(anInfo.myName); + TValueHolder<ETypeChamp, med_type_champ> aType(anInfo.myType); + TValueHolder<TString, char> aCompNames(anInfo.myCompNames); + TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames); + TErr aRet; aRet = MEDchampCr(myFile->Id(), - &anInfo.myName[0], - med_type_champ(theInfo.myType), - &anInfo.myCompNames[0], - &anInfo.myUnitNames[0], + &aFieldName, + aType, + &aCompNames, + &anUnitNames, anInfo.myNbComp); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetFieldInfo - MEDchampCr(...)"); + EXCEPTION(std::runtime_error,"SetFieldInfo - MEDchampCr(...)"); } @@ -749,10 +855,13 @@ namespace MED SetFieldInfo(theInfo,eECRI,&aRet); if(aRet < 0) - SetFieldInfo(theInfo,eREMP,theErr); + SetFieldInfo(theInfo,eREMP,&aRet); + + if(theErr) + *theErr = aRet; }catch(const std::exception& theExc){ - EXCEPTION(runtime_error,"SetFieldInfo(...)"<<endl<< + EXCEPTION(std::runtime_error,"SetFieldInfo(...)"<<std::endl<< theExc.what()); }catch(...){ throw; @@ -783,7 +892,7 @@ namespace MED if(theErr && *theErr < 0) return TProfileInfo::TInfo("",-1); - TInt aSize = -1; + med_int aSize = -1; TVector<char> aName(GetNOMLength<eV2_1>()+1); TErr aRet; @@ -794,7 +903,7 @@ namespace MED if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetProfilePreInfo - MEDprofilInfo(...)"); + EXCEPTION(std::runtime_error,"GetProfilePreInfo - MEDprofilInfo(...)"); return TProfileInfo::TInfo(&aName[0],aSize); } @@ -811,16 +920,59 @@ namespace MED if(theErr && *theErr < 0) return; + TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum); + TValueHolder<TString, char> aProfileName(theInfo.myName); + TErr aRet; aRet = MEDprofilLire(myFile->Id(), - &theInfo.myElemNum[0], - &theInfo.myName[0]); + &anElemNum, + &aProfileName); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetNodeInfo - MEDprofilLire(...)"); + EXCEPTION(std::runtime_error,"GetProfileInfo - MEDprofilLire(...)"); + } + + void + TVWrapper + ::SetProfileInfo(const TProfileInfo& theInfo, + EModeAcces theMode, + TErr* theErr) + { + TFileWrapper aFileWrapper(myFile,theMode,theErr); + + if(theErr && *theErr < 0) + return; + + TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<TString, char> aProfileName(anInfo.myName); + + TErr aRet; + aRet = MEDprofilEcr(myFile->Id(), // descripteur du fichier. + &anElemNum, // tableau de valeurs du profil. + theInfo.GetSize(), // taille du profil. + &aProfileName); // nom profil. + if(theErr) + *theErr = aRet; + else if(aRet < 0) + EXCEPTION(std::runtime_error,"SetProfileInfo - MEDprofilEcr(...)"); } + void + TVWrapper + ::SetProfileInfo(const TProfileInfo& theInfo, + TErr* theErr) + { + TErr aRet; + SetProfileInfo(theInfo,eECRI,&aRet); + + if(aRet < 0) + SetProfileInfo(theInfo,eREMP,&aRet); + + if(theErr) + *theErr = aRet; + } //----------------------------------------------------------------- TInt @@ -839,7 +991,7 @@ namespace MED if(*theErr < 0) return -1; }else if(theEntityInfo.empty()) - EXCEPTION(runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh"); + EXCEPTION(std::runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh"); bool anIsPerformAdditionalCheck = GetNbMeshes() > 1; #ifdef _DEBUG_ @@ -853,6 +1005,7 @@ namespace MED TIdt anId = myFile->Id(); MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo); + TValueHolder<TString, char> aFieldName(anInfo.myName); MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo; TEntityInfo::const_iterator anIter = theEntityInfo.begin(); @@ -863,7 +1016,7 @@ namespace MED for(; anGeomIter != aGeom2Size.end(); anGeomIter++){ med_geometrie_element aGeom = med_geometrie_element(anGeomIter->first); TInt aNbStamps = MEDnPasdetemps(anId, - &anInfo.myName[0], + &aFieldName, anEntity, aGeom); bool anIsSatisfied = aNbStamps > 0; @@ -881,7 +1034,7 @@ namespace MED med_int aNumOrd; med_float aDt; TErr aRet = MEDpasdetempsInfo(anId, - &anInfo.myName[0], + &aFieldName, anEntity, aGeom, iTimeStamp, @@ -931,11 +1084,19 @@ namespace MED if(*theErr < 0) return; }else if(aGeom2Size.empty()) - EXCEPTION(runtime_error,"GetTimeStampInfo - There is no any cell"); + EXCEPTION(std::runtime_error,"GetTimeStampInfo - There is no any cell"); MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo; MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo; + TValueHolder<TString, char> aFieldName(aFieldInfo.myName); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity); + TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt); + TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd); + TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt); + TValueHolder<TFloat, med_float> aDt(theInfo.myDt); + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss; TGeom2Size::const_iterator anIter = aGeom2Size.begin(); @@ -945,16 +1106,16 @@ namespace MED TErr aRet; aRet = MEDpasdetempsInfo(myFile->Id(), - &aFieldInfo.myName[0], - med_entite_maillage(theInfo.myEntity), + &aFieldName, + anEntity, med_geometrie_element(aGeom), theTimeStampId, - &aMeshInfo.myName[0], + &aMeshName, &aNbGauss, - (med_int*)&theInfo.myNumDt, - &theInfo.myUnitDt[0], - &theInfo.myDt, - (med_int*)&theInfo.myNumOrd); + &aNumDt, + &anUnitDt, + &aDt, + &aNumOrd); static TInt MAX_NB_GAUSS_POINTS = 32; @@ -966,17 +1127,17 @@ namespace MED if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)"); + EXCEPTION(std::runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)"); } } void TVWrapper - ::GetTimeStampVal(TTimeStampVal& theVal, - const TMKey2Profile& theMKey2Profile, - const TKey2Gauss& theKey2Gauss, - TErr* theErr) + ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr) { TFileWrapper aFileWrapper(myFile,eLECT,theErr); @@ -985,94 +1146,77 @@ namespace MED TIdt anId = myFile->Id(); - MED::TTimeStampInfo& aTimeStampInfo = *theVal.myTimeStampInfo; - MED::TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo; - MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo; + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch); + MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile; + + MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo; + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity); + TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt); + TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd); + + MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo; + TValueHolder<TString, char> aFieldName(aFieldInfo->myName); + + MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo->myName); MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile); TVector<char> aProfileName(GetNOMLength<eV2_1>()+1); - TGeom2Size& aGeom2Size = aTimeStampInfo.myGeom2Size; + TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size; TGeom2Size::iterator anIter = aGeom2Size.begin(); for(; anIter != aGeom2Size.end(); anIter++){ EGeometrieElement aGeom = anIter->first; + TInt aNbElem = anIter->second; + TInt aNbVal = MEDnVal(anId, - &aFieldInfo.myName[0], - med_entite_maillage(aTimeStampInfo.myEntity), + &aFieldName, + anEntity, med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd); + aNumDt, + aNumOrd); if(aNbVal <= 0){ if(theErr){ *theErr = -1; return; } - EXCEPTION(runtime_error,"GetTimeStampVal - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0"); } - TMeshValue& aMeshValue = theVal.GetMeshValue(aGeom); - TInt aNbGauss = aTimeStampInfo.GetNbGauss(aGeom); - TInt aNbElem = aNbVal / aNbGauss; - aMeshValue.Init(aNbElem, - aNbGauss, - aFieldInfo.myNbComp); - TValue& aValue = aMeshValue.myValue; - TInt anEnd = aValue.size(); + TInt aNbGauss = aTimeStampInfo->GetNbGauss(aGeom); + TInt aNbComp = aFieldInfo->myNbComp; + TInt aNbValue = aNbVal / aNbGauss; + theTimeStampValue->AllocateValue(aGeom, + aNbValue, + aNbGauss, + aNbComp); + TInt aValueSize = theTimeStampValue->GetValueSize(aGeom); INITMSG(MYDEBUG, - "TVWrapper::GetTimeStampVal - aGeom = "<<aGeom<< + "TVWrapper::GetTimeStampValue - aGeom = "<<aGeom<< "; aNbVal = "<<aNbVal<< - "; anEnd = "<<anEnd<< - "; aNbElem = "<<aNbElem<< + "; aNbValue = "<<aNbValue<< "; aNbGauss = "<<aNbGauss<< - "; aFieldInfo.myNbComp = "<<aFieldInfo.myNbComp<< - endl); - - TErr aRet; - switch(aFieldInfo.myType){ - case eFLOAT64: { - TVector<TFloat> anArray(anEnd); - aRet = MEDchampLire(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - MED_ALL, - &aProfileName[0], - med_entite_maillage(aTimeStampInfo.myEntity), - med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd); - if(aRet >= 0) - for(TInt anId = 0; anId < anEnd; anId++) - aValue[anId] = anArray[anId]; - break; - } - default: { - TVector<TInt> anArray(anEnd); - aRet = MEDchampLire(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - MED_ALL, - &aProfileName[0], - med_entite_maillage(aTimeStampInfo.myEntity), - med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd); - if(aRet >= 0) - for(TInt anId = 0; anId < anEnd; anId++) - aValue[anId] = anArray[anId]; - break; - }} - + "; aNbComp = "<<aNbComp<< + std::endl); + + TErr aRet = MEDchampLire(anId, + &aMeshName, + &aFieldName, + theTimeStampValue->GetValuePtr(aGeom), + aModeSwitch, + MED_ALL, + &aProfileName[0], + anEntity, + med_geometrie_element(aGeom), + aNumDt, + aNumOrd); if(aRet < 0){ if(theErr){ *theErr = aRet; return; } - EXCEPTION(runtime_error,"GetTimeStampVal - MEDchampLire(...)"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDchampLire(...)"); } MED::PProfileInfo aProfileInfo; @@ -1080,35 +1224,45 @@ namespace MED MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]); if(anIter != aKey2Profile.end()){ aProfileInfo = anIter->second; - theVal.myGeom2Profile[aGeom] = aProfileInfo; + aGeom2Profile[aGeom] = aProfileInfo; } } if(aProfileInfo && aProfileInfo->IsPresent()){ - TInt aSize = aProfileInfo->GetSize()*aFieldInfo.myNbComp*aNbGauss; - if(aSize > aValue.size()){ + TInt aNbSubElem = aProfileInfo->GetSize(); + TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss; + if(aProfileSize > aValueSize){ if(theErr){ *theErr = -1; return; } - EXCEPTION(runtime_error, - "GetTimeStampVal - aSize("<<aSize<< - ") > aValue.size()("<<aValue.size()<< + EXCEPTION(std::runtime_error, + "GetTimeStampValue - aProfileSize("<<aProfileSize<< + ") != aValueSize("<<aValueSize<< "); aNbVal = "<<aNbVal<< - "; anEntity = "<<aTimeStampInfo.myEntity<< - "; aGeom = "<<aGeom); + "; anEntity = "<<anEntity<< + "; aGeom = "<<aGeom<< + "; aNbElem = "<<aNbElem<< + "; aNbSubElem = "<<aNbSubElem<< + "; aNbComp = "<<aNbComp<< + "; aNbGauss = "<<aNbGauss<< + ""); }else{ - if(anEnd != aValue.size()){ + if(aNbElem != aNbValue){ if(theErr){ *theErr = -1; return; } - EXCEPTION(runtime_error, - "GetTimeStampVal - anEnd("<<anEnd<< - ") != aValue.size()("<<aValue.size()<< + EXCEPTION(std::runtime_error, + "GetTimeStampValue - aNbElem("<<aNbElem<< + ") != aNbValue("<<aNbValue<< "); aNbVal = "<<aNbVal<< - "; anEntity = "<<aTimeStampInfo.myEntity<< - "; aGeom = "<<aGeom); + "; anEntity = "<<anEntity<< + "; aGeom = "<<aGeom<< + "; aNbElem = "<<aNbElem<< + "; aNbComp = "<<aNbComp<< + "; aNbGauss = "<<aNbGauss<< + ""); } } } @@ -1118,9 +1272,9 @@ namespace MED void TVWrapper - ::SetTimeStamp(const MED::TTimeStampVal& theVal, - EModeAcces theMode, - TErr* theErr) + ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue, + EModeAcces theMode, + TErr* theErr) { TFileWrapper aFileWrapper(myFile,theMode,theErr); @@ -1130,96 +1284,80 @@ namespace MED TErr aRet; TIdt anId = myFile->Id(); - MED::TTimeStampVal& aVal = const_cast<MED::TTimeStampVal&>(theVal); - MED::TGeom2Profile& aGeom2Profile = aVal.myGeom2Profile; - MED::TTimeStampInfo& aTimeStampInfo = *aVal.myTimeStampInfo; - MED::TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo; - MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo; - MED::TGeom2Value& aGeom2Value = aVal.myGeom2Value; - - med_entite_maillage& anEntity = (med_entite_maillage&)(aTimeStampInfo.myEntity); - TGeom2Value::iterator anIter = aGeom2Value.begin(); - for(; anIter != aGeom2Value.end(); anIter++){ - EGeometrieElement aGeom = anIter->first; - TMeshValue& aMeshValue = anIter->second; + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch); + MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile; - med_geometrie_element aMEDGeom = med_geometrie_element(aGeom); + MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo; + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity); + TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt); + TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd); + TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt); + TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt); - MED::TProfileInfo& aProfileInfo = aGeom2Profile[aGeom]; - med_int aNbGauss = aTimeStampInfo.GetNbGauss(aGeom); + MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo; + TValueHolder<TString, char> aFieldName(aFieldInfo->myName); - med_int aNbVal = aMeshValue.myNbElem * aMeshValue.myNbGauss; - TValue& aValue = aMeshValue.myValue; - TInt anEnd = aValue.size(); - - switch(aFieldInfo.myType){ - case eFLOAT64: { - TVector<TFloat>& anArray = aValue; - - aRet = MEDchampEcr(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - aNbVal, - aNbGauss, - MED_ALL, - &aProfileInfo.myName[0], - MED_ECRI, - anEntity, - aMEDGeom, - aTimeStampInfo.myNumDt, - &aTimeStampInfo.myUnitDt[0], - aTimeStampInfo.myDt, - aTimeStampInfo.myNumOrd); - break; + MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo->myName); + + const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet; + TGeomSet::const_iterator anIter = aGeomSet.begin(); + for(; anIter != aGeomSet.end(); anIter++){ + EGeometrieElement aGeom = *anIter; + + TVector<char> aProfileName(GetNOMLength<eV2_1>()+1); + MED::TGeom2Profile::iterator aProfileIter = aGeom2Profile.find(aGeom); + if(aProfileIter != aGeom2Profile.end()){ + MED::TProfileInfo& aProfileInfo = aProfileIter->second; + aProfileName = aProfileInfo.myName; } - default: { - vector<TInt> anArray(anEnd); - for(TInt anID = 0; anID < anEnd; anID++) - anArray[anID] = TInt(aValue[anID]); - - aRet = MEDchampEcr(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - aNbVal, - aNbGauss, - MED_ALL, - &aProfileInfo.myName[0], - MED_ECRI, - anEntity, - aMEDGeom, - aTimeStampInfo.myNumDt, - &aTimeStampInfo.myUnitDt[0], - aTimeStampInfo.myDt, - aTimeStampInfo.myNumOrd); - break; - }} + + med_int aNbGauss = aTimeStampInfo->GetNbGauss(aGeom); + med_int aNbVal = theTimeStampValue->GetNbVal(aGeom); + aRet = MEDchampEcr(anId, + &aMeshName, + &aFieldName, + theTimeStampValue->GetValuePtr(aGeom), + aModeSwitch, + aNbVal, + aNbGauss, + MED_ALL, + &aProfileName[0], + MED_ECRI, + anEntity, + med_geometrie_element(aGeom), + aNumDt, + &anUnitDt, + aDt, + aNumOrd); if(aRet < 0){ if(theErr){ *theErr = aRet; break; } - EXCEPTION(runtime_error,"SetTimeStamp - MEDchampEcr(...)"); + EXCEPTION(std::runtime_error,"SetTimeStampValue - MEDchampEcr(...)"); } } - INITMSG(MYDEBUG,"TVWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<endl); + INITMSG(MYDEBUG,"TVWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl); } - void TVWrapper::SetTimeStamp(const MED::TTimeStampVal& theVal, - TErr* theErr) + void + TVWrapper + ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + TErr* theErr) { TErr aRet; - SetTimeStamp(theVal,eECRI,&aRet); + SetTimeStampValue(theTimeStampValue,eECRI,&aRet); if(aRet < 0) - SetTimeStamp(theVal,eREMP,theErr); + SetTimeStampValue(theTimeStampValue,eREMP,&aRet); + + if(theErr) + *theErr = aRet; } } diff --git a/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.hxx b/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.hxx index 5e5269c8b..74e88beb9 100644 --- a/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.hxx +++ b/src/MEDWrapper/V2_1/Wrapper/MED_V2_1_Wrapper.hxx @@ -29,60 +29,68 @@ #ifndef MED_V2_1_Wrapper_HeaderFile #define MED_V2_1_Wrapper_HeaderFile +#ifdef WNT + #if defined MEDWRAPPER_V2_1_EXPORTS + #if defined WIN32 + #define MED_V21_WRAPPER_EXPORT __declspec( dllexport ) + #else + #define MED_V21_WRAPPER_EXPORT + #endif + #else + #if defined WIN32 + #define MED_V21_WRAPPER_EXPORT __declspec( dllimport ) + #else + #define MED_V21_WRAPPER_EXPORT + #endif + #endif +#else + #define MED_V21_WRAPPER_EXPORT +#endif + #include "MED_TWrapper.hxx" namespace MED { template<> - TInt + TInt MED_V21_WRAPPER_EXPORT GetDESCLength<eV2_1>(); template<> - TInt + TInt MED_V21_WRAPPER_EXPORT GetIDENTLength<eV2_1>(); template<> - TInt + TInt MED_V21_WRAPPER_EXPORT GetNOMLength<eV2_1>(); template<> - TInt + TInt MED_V21_WRAPPER_EXPORT GetLNOMLength<eV2_1>(); template<> - TInt + TInt MED_V21_WRAPPER_EXPORT GetPNOMLength<eV2_1>(); template<> - TInt + void MED_V21_WRAPPER_EXPORT + GetVersionRelease<eV2_1>(TInt& majeur, TInt& mineur, TInt& release); + + template<> + TInt MED_V21_WRAPPER_EXPORT GetNbConn<eV2_1>(EGeometrieElement typmai, EEntiteMaillage typent, TInt mdim); namespace V2_1 { - typedef MED::TTMeshInfo<eV2_1> TVMeshInfo; - - typedef MED::TTFamilyInfo<eV2_1> TVFamilyInfo; - - typedef MED::TTNodeInfo<eV2_1> TVNodeInfo; - - typedef MED::TTCellInfo<eV2_1> TVCellInfo; - - typedef MED::TTFieldInfo<eV2_1> TVFieldInfo; - - typedef MED::TTTimeStampInfo<eV2_1> TVTimeStampInfo; - - typedef MED::TTTimeStampVal<eV2_1> TVTimeStampVal; - - //--------------------------------------------------------------- + //---------------------------------------------------------------------------- class TFile; typedef boost::shared_ptr<TFile> PFile; typedef enum {eLECT, eECRI, eREMP} EModeAcces; - //--------------------------------------------------------------- - class TVWrapper: public MED::TTWrapper<eV2_1> + //---------------------------------------------------------------------------- + class MED_V21_WRAPPER_EXPORT TVWrapper: public MED::TTWrapper<eV2_1> { TVWrapper(); TVWrapper(const TVWrapper&); @@ -92,7 +100,7 @@ namespace MED TVWrapper(const std::string& theFileName); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbMeshes(TErr* theErr = NULL); @@ -113,7 +121,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbFamilies(const MED::TMeshInfo& theMeshInfo, @@ -146,7 +154,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbNodes(const MED::TMeshInfo& theMeshInfo, @@ -168,7 +176,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TEntityInfo GetEntityInfo(const MED::TMeshInfo& theMeshInfo, @@ -199,7 +207,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbFields(TErr* theErr = NULL); @@ -226,7 +234,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbProfiles(TErr* theErr = NULL); @@ -242,8 +250,17 @@ namespace MED TProfileInfo& theInfo, TErr* theErr = NULL); + virtual + void + SetProfileInfo(const TProfileInfo& theInfo, + TErr* theErr = NULL); + + void + SetProfileInfo(const TProfileInfo& theInfo, + EModeAcces theMode, + TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbTimeStamps(const MED::TFieldInfo& theInfo, @@ -260,20 +277,20 @@ namespace MED virtual void - GetTimeStampVal(TTimeStampVal& theVal, - const TMKey2Profile& theMKey2Profile, - const TKey2Gauss& theKey2Gauss, - TErr* theErr = NULL); + GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr = NULL); virtual void - SetTimeStamp(const MED::TTimeStampVal& theTimeStampVal, - TErr* theErr = NULL); + SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + TErr* theErr = NULL); void - SetTimeStamp(const MED::TTimeStampVal& theTimeStampVal, - EModeAcces theMode, - TErr* theErr = NULL); + SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + EModeAcces theMode, + TErr* theErr = NULL); protected: PFile myFile; diff --git a/src/MEDWrapper/V2_1/Wrapper/Makefile.am b/src/MEDWrapper/V2_1/Wrapper/Makefile.am new file mode 100644 index 000000000..ebe5acbbe --- /dev/null +++ b/src/MEDWrapper/V2_1/Wrapper/Makefile.am @@ -0,0 +1,42 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : +# Author : +# Module : +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDWrapper_V2_1.la + +salomeinclude_HEADERS = \ + MED_V2_1_Wrapper.hxx + +dist_libMEDWrapper_V2_1_la_SOURCES= \ + MED_V2_1_Wrapper.cxx + +libMEDWrapper_V2_1_la_CPPFLAGS= -D@MACHINE@ $(BOOST_CPPFLAGS) $(HDF5_INCLUDES) \ + -I$(srcdir)/../../Base -I$(srcdir)/../Core -I$(top_builddir)/salome_adm/unix +libMEDWrapper_V2_1_la_LDFLAGS= $(HDF5_LIBS) +libMEDWrapper_V2_1_la_LIBADD= ../../Base/libMEDWrapperBase.la ../Core/libmed_V2_1.la diff --git a/src/MEDWrapper/V2_1/Wrapper/Makefile.in b/src/MEDWrapper/V2_1/Wrapper/Makefile.in deleted file mode 100644 index 1e39322ca..000000000 --- a/src/MEDWrapper/V2_1/Wrapper/Makefile.in +++ /dev/null @@ -1,56 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -# Libraries targets - -LIB = libMEDWrapper_V2_1.la -LIB_SRC = \ - MED_V2_1_Wrapper.cxx - -EXPORT_HEADERS = \ - MED_V2_1_Wrapper.hxx - -# Executables targets -BIN = -BIN_SRC = - -CPPFLAGS+= -D@MACHINE@ $(BOOST_CPPFLAGS) $(HDF5_INCLUDES) - -LDFLAGS+= $(HDF5_LIBS) -lMEDWrapperBase -lmed_V2_1 - -LDFLAGSFORBIN=$(LDFLAGS) - -@CONCLUDE@ diff --git a/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.cxx b/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.cxx index f1409f9a7..c4e2cc7dd 100644 --- a/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.cxx +++ b/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.cxx @@ -30,6 +30,11 @@ #include "MED_Algorithm.hxx" #include "MED_Utilities.hxx" + + +//#include <med.h> +//using namespace med_2_2; + extern "C" { #include <med.h> @@ -37,6 +42,10 @@ extern "C" med_err MEDgaussInfo(med_idt fid, int indice, char * locname, med_geometrie_element * type_geo, med_int * ngauss ); + +med_int +MEDnMaa(med_idt fid); + } #ifdef _DEBUG_ @@ -84,6 +93,13 @@ namespace MED return 16; } + template<> + void + GetVersionRelease<eV2_2>(TInt& majeur, TInt& mineur, TInt& release) + { + MEDversionDonner(&majeur, &mineur, &release); + } + template<> TInt GetNbConn<eV2_2>(EGeometrieElement typmai, @@ -108,28 +124,33 @@ namespace MED myFileName(theFileName) {} - ~TFile(){ + ~TFile() + { Close(); } - void Open(EModeAcces theMode, TErr* theErr = NULL){ + void + Open(EModeAcces theMode, TErr* theErr = NULL) + { if(myCount++ == 0){ char* aFileName = const_cast<char*>(myFileName.c_str()); myFid = MEDouvrir(aFileName,med_mode_acces(theMode)); } if(theErr) - *theErr = TErr(myFid > 0); + *theErr = TErr(myFid); else if(myFid < 0) - EXCEPTION(runtime_error,"TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")"); + EXCEPTION(std::runtime_error,"TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")"); } - const TIdt& Id() const { + const TIdt& Id() const + { if(myFid < 0) - EXCEPTION(runtime_error,"TFile - GetFid() < 0"); + EXCEPTION(std::runtime_error,"TFile - GetFid() < 0"); return myFid; } - void Close(){ + void Close() + { if(--myCount == 0) MEDfermer(myFid); } @@ -142,7 +163,8 @@ namespace MED //--------------------------------------------------------------- - class TFileWrapper{ + class TFileWrapper + { PFile myFile; public: @@ -152,7 +174,8 @@ namespace MED myFile->Open(theMode,theErr); } - ~TFileWrapper(){ + ~TFileWrapper() + { myFile->Close(); } }; @@ -161,23 +184,24 @@ namespace MED //--------------------------------------------------------------- TVWrapper::TVWrapper(const std::string& theFileName): myFile(new TFile(theFileName)) - { - } + {} + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbMeshes(TErr* theErr) { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; return MEDnMaa(myFile->Id()); } + //---------------------------------------------------------------------------- void TVWrapper ::GetMeshInfo(TInt theMeshId, @@ -186,22 +210,27 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; + TValueHolder<TString, char> aMeshName(theInfo.myName); + TValueHolder<TInt, med_int> aDim(theInfo.myDim); + TValueHolder<EMaillage, med_maillage> aType(theInfo.myType); + TErr aRet = MEDmaaInfo(myFile->Id(), theMeshId, - &theInfo.myName[0], - (med_int*)&theInfo.myDim, - (med_maillage*)&theInfo.myType, + &aMeshName, + &aDim, + &aType, &theInfo.myDesc[0]); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetMeshInfo - MEDmaaInfo(...)"); + EXCEPTION(std::runtime_error,"GetMeshInfo - MEDmaaInfo(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetMeshInfo(const MED::TMeshInfo& theInfo, @@ -210,30 +239,36 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo); + TValueHolder<TString, char> aMeshName(anInfo.myName); + TValueHolder<TInt, med_int> aDim(anInfo.myDim); + TValueHolder<EMaillage, med_maillage> aType(anInfo.myType); + TValueHolder<TString, char> aDesc(anInfo.myDesc); + TErr aRet = MEDmaaCr(myFile->Id(), - &anInfo.myName[0], - med_int(anInfo.myDim), - med_maillage(theInfo.myType), - &anInfo.myDesc[0]); + &aMeshName, + aDim, + aType, + &aDesc); if(aRet == 0){ aRet = MEDunvCr(myFile->Id(), - &anInfo.myName[0]); + &aMeshName); } - INITMSG(MYDEBUG,"TVWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<endl); + INITMSG(MYDEBUG,"TVWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetMeshInfo - MEDmaaCr(...)"); + EXCEPTION(std::runtime_error,"SetMeshInfo - MEDmaaCr(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetMeshInfo(const MED::TMeshInfo& theInfo, @@ -246,10 +281,14 @@ namespace MED SetMeshInfo(theInfo,eLECTURE_AJOUT,&aRet); if(aRet < 0) - SetMeshInfo(theInfo,eCREATION,theErr); + SetMeshInfo(theInfo,eCREATION,&aRet); + + if(theErr) + *theErr = aRet; } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbFamilies(const MED::TMeshInfo& theInfo, @@ -257,15 +296,17 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo); + TValueHolder<TString, char> aName(anInfo.myName); return MEDnFam(myFile->Id(), - &anInfo.myName[0]); + &aName); } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbFamAttr(TInt theFamId, @@ -274,16 +315,20 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo); + + TValueHolder<TString, char> aName(anInfo.myName); + return MEDnAttribut(myFile->Id(), - &anInfo.myName[0], + &aName, theFamId); } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbFamGroup(TInt theFamId, @@ -292,16 +337,20 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo); + + TValueHolder<TString, char> aName(anInfo.myName); + return MEDnGroupe(myFile->Id(), - &anInfo.myName[0], + &aName, theFamId); } + //---------------------------------------------------------------------------- void TVWrapper ::GetFamilyInfo(TInt theFamId, @@ -310,39 +359,45 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - med_int* anAttrId = theInfo.myNbAttr > 0? (med_int*)&theInfo.myAttrId[0]: NULL; - med_int* anAttrVal = theInfo.myNbAttr > 0? (med_int*)&theInfo.myAttrVal[0]: NULL; - char* anAttrDesc = theInfo.myNbAttr > 0? &theInfo.myAttrDesc[0]: NULL; - char* aGroupNames = theInfo.myNbGroup > 0? &theInfo.myGroupNames[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TString, char> aFamilyName(theInfo.myName); + TValueHolder<TInt, med_int> aFamilyId(theInfo.myId); + TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId); + TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal); + TValueHolder<TInt, med_int> aNbAttr(theInfo.myNbAttr); + TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc); + TValueHolder<TInt, med_int> aNbGroup(theInfo.myNbGroup); + TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames); TErr aRet = MEDfamInfo(myFile->Id(), - &aMeshInfo.myName[0], + &aMeshName, theFamId, - &theInfo.myName[0], - (med_int*)&theInfo.myId, - anAttrId, - anAttrVal, - anAttrDesc, - (med_int*)&theInfo.myNbAttr, - aGroupNames, - (med_int*)&theInfo.myNbGroup); + &aFamilyName, + &aFamilyId, + &anAttrId, + &anAttrVal, + &anAttrDesc, + &aNbAttr, + &aGroupNames, + &aNbGroup); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetFamilyInfo - MEDfamInfo(...) - "<< - " aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<< + EXCEPTION(std::runtime_error,"GetFamilyInfo - MEDfamInfo(...) - "<< + " aMeshInfo.myName = '"<<&aMeshName<< "'; theFamId = "<<theFamId<< - "; theInfo.myNbGroup = "<<theInfo.myNbGroup<< - "; theInfo.myNbAttr = "<<theInfo.myNbAttr); + "; theInfo.myNbGroup = "<<aNbGroup()<< + "; theInfo.myNbAttr = "<<aNbAttr()); } + //---------------------------------------------------------------------------- void TVWrapper ::SetFamilyInfo(const MED::TFamilyInfo& theInfo, @@ -351,37 +406,43 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TFamilyInfo& anInfo = const_cast<MED::TFamilyInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; - med_int* anAttrId = anInfo.myNbAttr > 0? (med_int*)&anInfo.myAttrId[0]: NULL; - med_int* anAttrVal = anInfo.myNbAttr > 0? (med_int*)&anInfo.myAttrVal[0]: NULL; - char* anAttrDesc = anInfo.myNbAttr > 0? &anInfo.myAttrDesc[0]: NULL; - char* aGroupNames = anInfo.myNbGroup > 0? &anInfo.myGroupNames[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TString, char> aFamilyName(anInfo.myName); + TValueHolder<TInt, med_int> aFamilyId(anInfo.myId); + TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId); + TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal); + TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr); + TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc); + TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup); + TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames); TErr aRet = MEDfamCr(myFile->Id(), - &aMeshInfo.myName[0], - &anInfo.myName[0], - anInfo.myId, - anAttrId, - anAttrVal, - anAttrDesc, - anInfo.myNbAttr, - aGroupNames, - anInfo.myNbGroup); - - INITMSG(MYDEBUG,"TVWrapper::GetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<endl); + &aMeshName, + &aFamilyName, + aFamilyId, + &anAttrId, + &anAttrVal, + &anAttrDesc, + aNbAttr, + &aGroupNames, + aNbGroup); + + INITMSG(MYDEBUG,"TVWrapper::GetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetFamilyInfo - MEDfamCr(...)"); + EXCEPTION(std::runtime_error,"SetFamilyInfo - MEDfamCr(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetFamilyInfo(const MED::TFamilyInfo& theInfo, @@ -391,10 +452,13 @@ namespace MED SetFamilyInfo(theInfo,eLECTURE_ECRITURE,&aRet); if(aRet < 0) - SetFamilyInfo(theInfo,eLECTURE_AJOUT,theErr); + SetFamilyInfo(theInfo,eLECTURE_AJOUT,&aRet); + + if(theErr) + *theErr = aRet; } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- void TVWrapper ::GetNames(TElemInfo& theInfo, @@ -405,21 +469,30 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TString, char> anElemNames(theInfo.myElemNames); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theGeom); + TErr aRet = MEDnomLire(myFile->Id(), - &aMeshInfo.myName[0], - &theInfo.myElemNames[0], + &aMeshName, + &anElemNames, theNb, - med_entite_maillage(theEntity), - med_geometrie_element(theGeom)); + anEntity, + aGeom); theInfo.myIsElemNames = aRet != 0? eFAUX : eVRAI ; + + if(theErr) + *theErr = aRet; } + //---------------------------------------------------------------------------- void TVWrapper ::GetNumeration(TElemInfo& theInfo, @@ -430,24 +503,30 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - med_entite_maillage& anEntity = (med_entite_maillage&)(theEntity); - med_geometrie_element& aGeom = (med_geometrie_element&)(theGeom); - + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theGeom); + TErr aRet = MEDnumLire(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&theInfo.myElemNum[0], + &aMeshName, + &anElemNum, theNb, anEntity, aGeom); theInfo.myIsElemNum = aRet != 0? eFAUX : eVRAI; + + if(theErr) + *theErr = aRet; } + //---------------------------------------------------------------------------- void TVWrapper ::GetFamilies(TElemInfo& theInfo, @@ -458,24 +537,31 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; + + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theGeom); TErr aRet = MEDfamLire(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&theInfo.myFamNum[0], + &aMeshName, + &aFamNum, theNb, - med_entite_maillage(theEntity), - med_geometrie_element(theGeom)); + anEntity, + aGeom); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetFamilies - MEDfamLire(...)"); + EXCEPTION(std::runtime_error,"GetFamilies - MEDfamLire(...)"); } + + //---------------------------------------------------------------------------- void TVWrapper ::SetNames(const TElemInfo& theInfo, @@ -486,6 +572,8 @@ namespace MED SetNames(theInfo,eLECTURE_ECRITURE,theEntity,theGeom,theErr); } + + //---------------------------------------------------------------------------- void TVWrapper ::SetNames(const TElemInfo& theInfo, @@ -496,7 +584,7 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo); @@ -504,19 +592,26 @@ namespace MED TErr aRet = 0; if(theInfo.myIsElemNames){ + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TString, char> anElemNames(anInfo.myElemNames); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theGeom); + aRet = MEDnomEcr(myFile->Id(), - &aMeshInfo.myName[0], - &anInfo.myElemNames[0], - anInfo.myElemNames.size(), - med_entite_maillage(theEntity), - med_geometrie_element(theGeom)); + &aMeshName, + &anElemNames, + (TInt)anInfo.myElemNames->size(), + anEntity, + aGeom); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetNames - MEDnomEcr(...)"); + EXCEPTION(std::runtime_error,"SetNames - MEDnomEcr(...)"); } } + + //---------------------------------------------------------------------------- void TVWrapper ::SetNumeration(const TElemInfo& theInfo, @@ -527,6 +622,8 @@ namespace MED SetNumeration(theInfo,eLECTURE_ECRITURE,theEntity,theGeom,theErr); } + + //---------------------------------------------------------------------------- void TVWrapper ::SetNumeration(const TElemInfo& theInfo, @@ -537,7 +634,7 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo); @@ -545,19 +642,25 @@ namespace MED TErr aRet = 0; if(theInfo.myIsElemNum){ + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theGeom); + aRet = MEDnumEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&anInfo.myElemNum[0], - anInfo.myElemNum.size(), - med_entite_maillage(theEntity), - med_geometrie_element(theGeom)); + &aMeshName, + &anElemNum, + (TInt)anInfo.myElemNum->size(), + anEntity, + aGeom); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetNumeration - MEDnumEcr(...)"); + EXCEPTION(std::runtime_error,"SetNumeration - MEDnumEcr(...)"); } } + //---------------------------------------------------------------------------- void TVWrapper ::SetFamilies(const TElemInfo& theInfo, @@ -568,6 +671,7 @@ namespace MED SetFamilies(theInfo,eLECTURE_ECRITURE,theEntity,theGeom,theErr); } + //---------------------------------------------------------------------------- void TVWrapper ::SetFamilies(const TElemInfo& theInfo, @@ -578,26 +682,31 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theGeom); + TErr aRet = MEDfamEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&anInfo.myFamNum[0], - anInfo.myFamNum.size(), - med_entite_maillage(theEntity), - med_geometrie_element(theGeom)); + &aMeshName, + &aFamNum, + (TInt)anInfo.myFamNum->size(), + anEntity, + aGeom); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetFamilies - MEDfamEcr(...)"); + EXCEPTION(std::runtime_error,"SetFamilies - MEDfamEcr(...)"); } - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbNodes(const MED::TMeshInfo& theMeshInfo, @@ -606,20 +715,24 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<ETable, med_table> aTable(theTable); + return MEDnEntMaa(myFile->Id(), - &aMeshInfo.myName[0], - (med_table)theTable, + &aMeshName, + aTable, MED_NOEUD, med_geometrie_element(0), med_connectivite(0)); } + //---------------------------------------------------------------------------- void TVWrapper ::GetNodeInfo(MED::TNodeInfo& theInfo, @@ -627,35 +740,47 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - char* anElemNames = theInfo.myIsElemNames? &theInfo.myElemNames[0]: NULL; - med_int* anElemNum = theInfo.myIsElemNum? &theInfo.myElemNum[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch); + TValueHolder<ERepere, med_repere> aSystem(theInfo.mySystem); + TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames); + TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits); + TValueHolder<TString, char> anElemNames(theInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum); + TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem); TErr aRet = MEDnoeudsLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &theInfo.myCoord[0], - med_mode_switch(theInfo.myModeSwitch), - (med_repere*)&theInfo.mySystem, - &theInfo.myCoordNames[0], - &theInfo.myCoordUnits[0], - anElemNames, - (med_booleen*)&theInfo.myIsElemNames, - anElemNum, - (med_booleen*)&theInfo.myIsElemNum, - (med_int*)&theInfo.myFamNum[0], - theInfo.myNbElem); + &aMeshName, + aDim, + &aCoord, + aModeSwitch, + &aSystem, + &aCoordNames, + &aCoordUnits, + &anElemNames, + &anIsElemNames, + &anElemNum, + &anIsElemNum, + &aFamNum, + aNbElem); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetNodeInfo - MEDnoeudsLire(...)"); + EXCEPTION(std::runtime_error,"GetNodeInfo - MEDnoeudsLire(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetNodeInfo(const MED::TNodeInfo& theInfo, @@ -664,36 +789,48 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; - char* anElemNames = theInfo.myIsElemNames? &anInfo.myElemNames[0]: NULL; - med_int* anElemNum = theInfo.myIsElemNum? &anInfo.myElemNum[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch); + TValueHolder<ERepere, med_repere> aSystem(anInfo.mySystem); + TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames); + TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits); + TValueHolder<TString, char> anElemNames(anInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum); + TValueHolder<TInt, med_int> aNbElem(anInfo.myNbElem); TErr aRet = MEDnoeudsEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &anInfo.myCoord[0], - med_mode_switch(theInfo.myModeSwitch), - med_repere(theInfo.mySystem), - &anInfo.myCoordNames[0], - &anInfo.myCoordUnits[0], - anElemNames, - med_booleen(theInfo.myIsElemNames), - anElemNum, - med_booleen(theInfo.myIsElemNum), - (med_int*)&anInfo.myFamNum[0], - anInfo.myNbElem); + &aMeshName, + aDim, + &aCoord, + aModeSwitch, + aSystem, + &aCoordNames, + &aCoordUnits, + &anElemNames, + anIsElemNames, + &anElemNum, + anIsElemNum, + &aFamNum, + aNbElem); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)"); + EXCEPTION(std::runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetNodeInfo(const MED::TNodeInfo& theInfo, @@ -703,7 +840,10 @@ namespace MED SetNodeInfo(theInfo,eLECTURE_ECRITURE,&aRet); if(aRet < 0) - SetNodeInfo(theInfo,eLECTURE_AJOUT,theErr); + SetNodeInfo(theInfo,eLECTURE_AJOUT,&aRet); + + if(theErr) + *theErr = aRet; } @@ -715,25 +855,31 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - TInt aNbElem = theInfo.myElemNum.size(); + + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex); + TInt aNbElem = (TInt)theInfo.myElemNum->size(); + TValueHolder<TElemNum, med_int> aConn(theInfo.myConn); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity); + TValueHolder<EConnectivite, med_connectivite> aConnMode(theInfo.myConnMode); TErr aRet; aRet = MEDpolygoneConnLire(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&theInfo.myIndex[0], + &aMeshName, + &anIndex, aNbElem+1, - (med_int*)&theInfo.myConn[0], - med_entite_maillage(theInfo.myEntity), - med_connectivite(theInfo.myConnMode)); + &aConn, + anEntity, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetPolygoneInfo - MEDpolygoneInfo(...)"); + EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDpolygoneInfo(...)"); if(theInfo.myIsElemNames){ GetNames(theInfo,aNbElem,theInfo.myEntity,ePOLYGONE,&aRet); @@ -752,6 +898,7 @@ namespace MED *theErr = aRet; } + //---------------------------------------------------------------------------- void TVWrapper ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo, @@ -760,6 +907,7 @@ namespace MED SetPolygoneInfo(theInfo,eLECTURE_ECRITURE,theErr); } + //---------------------------------------------------------------------------- void TVWrapper ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo, @@ -768,24 +916,30 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TPolygoneInfo& anInfo = const_cast<MED::TPolygoneInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex); + TValueHolder<TElemNum, med_int> aConn(anInfo.myConn); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(anInfo.myEntity); + TValueHolder<EConnectivite, med_connectivite> aConnMode(anInfo.myConnMode); + TErr aRet = MEDpolygoneConnEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&anInfo.myIndex[0], - anInfo.myNbElem+1, - (med_int*)&anInfo.myConn[0], - med_entite_maillage(theInfo.myEntity), - med_connectivite(theInfo.myConnMode)); + &aMeshName, + &anIndex, + anInfo.myNbElem + 1, + &aConn, + anEntity, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetPolygoneInfo - MEDpolygoneConnEcr(...)"); + EXCEPTION(std::runtime_error,"SetPolygoneInfo - MEDpolygoneConnEcr(...)"); SetNames(anInfo,theInfo.myEntity,ePOLYGONE,&aRet); if(theErr) @@ -800,6 +954,7 @@ namespace MED *theErr = aRet; } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbPolygones(const MED::TMeshInfo& theMeshInfo, @@ -811,6 +966,7 @@ namespace MED return GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode,theErr); } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetPolygoneConnSize(const MED::TMeshInfo& theMeshInfo, @@ -821,26 +977,27 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return 0; MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); - med_int taille = 0; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + med_int aTaille = 0; TErr aRet; aRet = MEDpolygoneInfo(myFile->Id(), - &aMeshInfo.myName[0], + &aMeshName, med_entite_maillage(theEntity), med_connectivite(theConnMode), - &taille); + &aTaille); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetPolygoneInfo - MEDpolygoneInfo(...)"); + EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDpolygoneInfo(...)"); - return TInt(taille); + return TInt(aTaille); } //----------------------------------------------------------------- @@ -851,26 +1008,32 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - TInt aNbElem = theInfo.myElemNum.size(); + + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TInt aNbElem = (TInt)theInfo.myElemNum->size(); + TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex); + TValueHolder<TElemNum, med_int> aFaces(theInfo.myFaces); + TValueHolder<TElemNum, med_int> aConn(theInfo.myConn); + TValueHolder<EConnectivite, med_connectivite> aConnMode(theInfo.myConnMode); TErr aRet; aRet = MEDpolyedreConnLire(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&theInfo.myIndex[0], + &aMeshName, + &anIndex, aNbElem + 1, - (med_int*)&theInfo.myFaces[0], - theInfo.myFaces.size(), - (med_int*)&theInfo.myConn[0], - med_connectivite(theInfo.myConnMode)); + &aFaces, + (TInt)theInfo.myFaces->size(), + &aConn, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetPolygoneInfo - MEDpolyedreConnLire(...)"); + EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDpolyedreConnLire(...)"); if(theInfo.myIsElemNames){ GetNames(theInfo,aNbElem,theInfo.myEntity,ePOLYEDRE,&aRet); @@ -889,6 +1052,7 @@ namespace MED *theErr = aRet; } + //---------------------------------------------------------------------------- void TVWrapper ::SetPolyedreInfo(const TPolyedreInfo& theInfo, @@ -897,6 +1061,7 @@ namespace MED SetPolyedreInfo(theInfo,eLECTURE_ECRITURE,theErr); } + //---------------------------------------------------------------------------- void TVWrapper ::SetPolyedreInfo(const MED::TPolyedreInfo& theInfo, @@ -905,67 +1070,79 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TPolyedreInfo& anInfo = const_cast<MED::TPolyedreInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex); + TValueHolder<TElemNum, med_int> aFaces(anInfo.myFaces); + TValueHolder<TElemNum, med_int> aConn(anInfo.myConn); + TValueHolder<EConnectivite, med_connectivite> aConnMode(anInfo.myConnMode); + TErr aRet; aRet = MEDpolyedreConnEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&anInfo.myIndex[0], - anInfo.myNbElem+1, - (med_int*)&anInfo.myFaces[0], - anInfo.myFaces.size(), - (med_int*)&anInfo.myConn[0], - med_connectivite(theInfo.myConnMode)); + &aMeshName, + &anIndex, + anInfo.myNbElem + 1, + &aFaces, + (TInt)anInfo.myFaces->size(), + &aConn, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetPolyedreInfo - MEDpolyedreConnEcr(...)"); + EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDpolyedreConnEcr(...)"); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(anInfo.myEntity); + if(theInfo.myIsElemNames){ + TValueHolder<TString, char> anElemNames(anInfo.myElemNames); aRet = MEDnomEcr(myFile->Id(), - &aMeshInfo.myName[0], - &anInfo.myElemNames[0], - anInfo.myElemNames.size(), - med_entite_maillage(theInfo.myEntity), + &aMeshName, + &anElemNames, + (TInt)anInfo.myElemNames->size(), + anEntity, MED_POLYEDRE); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetPolyedreInfo - MEDnomEcr(...)"); + EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDnomEcr(...)"); } if(theInfo.myIsElemNum){ + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); aRet = MEDnumEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&anInfo.myElemNum[0], - anInfo.myElemNum.size(), - med_entite_maillage(theInfo.myEntity), + &aMeshName, + &anElemNum, + (TInt)anInfo.myElemNum->size(), + anEntity, MED_POLYEDRE); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetPolyedreInfo - MEDnumEcr(...)"); + EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDnumEcr(...)"); } + TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum); aRet = MEDfamEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_int*)&anInfo.myFamNum[0], - anInfo.myFamNum.size(), - med_entite_maillage(theInfo.myEntity), + &aMeshName, + &aFamNum, + (TInt)anInfo.myFamNum->size(), + anEntity, MED_POLYEDRE); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetPolyedreInfo - MEDfamEcr(...)"); + EXCEPTION(std::runtime_error,"SetPolyedreInfo - MEDfamEcr(...)"); } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbPolyedres(const MED::TMeshInfo& theMeshInfo, @@ -977,6 +1154,7 @@ namespace MED return GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode,theErr); } + //---------------------------------------------------------------------------- void TVWrapper ::GetPolyedreConnSize(const TMeshInfo& theMeshInfo, @@ -987,21 +1165,26 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) - EXCEPTION(runtime_error,"GetPolyedreInfo - (...)"); + if(theErr && *theErr < 0) + EXCEPTION(std::runtime_error,"GetPolyedreConnSize - (...)"); MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<EConnectivite, med_connectivite> aConnMode(theConnMode); + TValueHolder<TInt, med_int> aNbFaces(theNbFaces); + TValueHolder<TInt, med_int> aConnSize(theConnSize); + TErr aRet = MEDpolyedreInfo(myFile->Id(), - &aMeshInfo.myName[0], - med_connectivite(theConnMode), - (med_int*)&theNbFaces, - (med_int*)&theConnSize); + &aMeshName, + aConnMode, + &aNbFaces, + &aConnSize); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetPolygoneInfo - MEDpolyedreInfo(...)"); + EXCEPTION(std::runtime_error,"GetPolygoneInfo - MEDpolyedreInfo(...)"); } @@ -1020,26 +1203,25 @@ namespace MED return anInfo; if(theMeshInfo.GetType() == eNON_STRUCTURE) { - - TInt aNbElem = GetNbNodes(theMeshInfo); - if(aNbElem > 0){ - anInfo[eNOEUD][ePOINT1] = aNbElem; - const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet(); - TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin(); - TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end(); - for(; anIter != anIterEnd; anIter++){ - const EEntiteMaillage& anEntity = anIter->first; - const TGeomSet& aGeomSet = anIter->second; - TGeomSet::const_iterator anIter2 = aGeomSet.begin(); - TGeomSet::const_iterator anIterEnd2 = aGeomSet.end(); - for(; anIter2 != anIterEnd2; anIter2++){ - const EGeometrieElement& aGeom = *anIter2; - aNbElem = GetNbCells(theMeshInfo,anEntity,aGeom,theConnMode,theErr); - if(aNbElem > 0) - anInfo[anEntity][aGeom] = aNbElem; + TInt aNbElem = GetNbNodes(theMeshInfo); + if(aNbElem > 0){ + anInfo[eNOEUD][ePOINT1] = aNbElem; + const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet(); + TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin(); + TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end(); + for(; anIter != anIterEnd; anIter++){ + const EEntiteMaillage& anEntity = anIter->first; + const TGeomSet& aGeomSet = anIter->second; + TGeomSet::const_iterator anIter2 = aGeomSet.begin(); + TGeomSet::const_iterator anIterEnd2 = aGeomSet.end(); + for(; anIter2 != anIterEnd2; anIter2++){ + const EGeometrieElement& aGeom = *anIter2; + aNbElem = GetNbCells(theMeshInfo,anEntity,aGeom,theConnMode,theErr); + if(aNbElem > 0) + anInfo[anEntity][aGeom] = aNbElem; + } } } - } } else { // eSTRUCTURE EGrilleType aGrilleType; TInt aNbNodes = 1; @@ -1059,41 +1241,36 @@ namespace MED break; } - GetGrilleType(theMeshInfo,aGrilleType); + GetGrilleType(theMeshInfo, aGrilleType); - if (aGrilleType == eGRILLE_STANDARD){ - TIntVector theStruct; - theStruct.resize(aDim); - GetGrilleStruct(theMeshInfo,theStruct,theErr); - for(med_int i=0;i<aDim;i++){ - aNbNodes = aNbNodes * theStruct[i]; - aNbElem = aNbElem * (theStruct[i]-1); + if(aGrilleType == eGRILLE_STANDARD){ + TIntVector aStruct(aDim); + GetGrilleStruct(theMeshInfo, aStruct, theErr); + for(med_int i = 0; i < aDim; i++){ + aNbNodes = aNbNodes * aStruct[i]; + aNbElem = aNbElem * (aStruct[i] - 1); } - anInfo[eNOEUD][ePOINT1] = aNbNodes; - anInfo[anEntity][aGeom] = aNbElem; - - } else { // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE - med_table quoi; - for(int aAxe=1;aAxe<=aDim;aAxe++) - { - switch(aAxe) { + }else{ // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE + ETable aTable; + for(med_int anAxis = 1; anAxis <= aDim; anAxis++){ + switch(anAxis){ case 1 : - quoi = MED_COOR_IND1; + aTable = eCOOR_IND1; break; case 2 : - quoi = MED_COOR_IND2; + aTable = eCOOR_IND2; break; case 3 : - quoi = MED_COOR_IND3; + aTable = eCOOR_IND3; break; } - TInt nbn = GetNbNodes(theMeshInfo,(ETable)quoi); - aNbNodes = aNbNodes * nbn; - aNbElem = aNbElem * (nbn-1); + TInt aNbNodes = GetNbNodes(theMeshInfo, aTable); + aNbNodes = aNbNodes * aNbNodes; + aNbElem = aNbElem * (aNbNodes - 1); } - anInfo[eNOEUD][ePOINT1] = aNbNodes; - anInfo[anEntity][aGeom] = aNbElem; } + anInfo[eNOEUD][ePOINT1] = aNbNodes; + anInfo[anEntity][aGeom] = aNbElem; } return anInfo; } @@ -1110,13 +1287,14 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); - + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + return MEDnEntMaa(myFile->Id(), - &aMeshInfo.myName[0], + &aMeshName, MED_CONN, med_entite_maillage(theEntity), med_geometrie_element(theGeom), @@ -1124,6 +1302,7 @@ namespace MED } + //---------------------------------------------------------------------------- void TVWrapper ::GetCellInfo(MED::TCellInfo& theInfo, @@ -1131,37 +1310,48 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - TInt aNbElem = theInfo.myElemNum.size(); - - char* anElemNames = theInfo.myIsElemNames? &theInfo.myElemNames[0]: NULL; - med_int* anElemNum = theInfo.myIsElemNum? &theInfo.myElemNum[0]: NULL; + TInt aNbElem = (TInt)theInfo.myElemNum->size(); + + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TElemNum, med_int> aConn(theInfo.myConn); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch); + TValueHolder<TString, char> anElemNames(theInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(theInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(theInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(theInfo.myGeom); + TValueHolder<EConnectivite, med_connectivite> aConnMode(theInfo.myConnMode); TErr aRet; aRet = MEDelementsLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - (med_int*)&theInfo.myConn[0], - med_mode_switch(theInfo.myModeSwitch), - anElemNames, - (med_booleen*)&theInfo.myIsElemNames, - anElemNum, - (med_booleen*)&theInfo.myIsElemNum, - (med_int*)&theInfo.myFamNum[0], + &aMeshName, + aDim, + &aConn, + aModeSwitch, + &anElemNames, + &anIsElemNames, + &anElemNum, + &anIsElemNum, + &aFamNum, aNbElem, - med_entite_maillage(theInfo.myEntity), - med_geometrie_element(theInfo.myGeom), - med_connectivite(theInfo.myConnMode)); + anEntity, + aGeom, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)"); + EXCEPTION(std::runtime_error,"GetCellInfo - MEDelementsLire(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetCellInfo(const MED::TCellInfo& theInfo, @@ -1170,38 +1360,49 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TCellInfo& anInfo = const_cast<MED::TCellInfo&>(theInfo); MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; - char* anElemNames = theInfo.myIsElemNames? &anInfo.myElemNames[0]: NULL; - med_int* anElemNum = theInfo.myIsElemNum? &anInfo.myElemNum[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TElemNum, med_int> aConn(anInfo.myConn); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch); + TValueHolder<TString, char> anElemNames(anInfo.myElemNames); + TValueHolder<EBooleen, med_booleen> anIsElemNames(anInfo.myIsElemNames); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<EBooleen, med_booleen> anIsElemNum(anInfo.myIsElemNum); + TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(anInfo.myEntity); + TValueHolder<EGeometrieElement, med_geometrie_element> aGeom(anInfo.myGeom); + TValueHolder<EConnectivite, med_connectivite> aConnMode(anInfo.myConnMode); TErr aRet; aRet = MEDelementsEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - (med_int*)&anInfo.myConn[0], - med_mode_switch(theInfo.myModeSwitch), - anElemNames, - med_booleen(theInfo.myIsElemNames), - anElemNum, - med_booleen(theInfo.myIsElemNum), - (med_int*)&anInfo.myFamNum[0], + &aMeshName, + aDim, + &aConn, + aModeSwitch, + &anElemNames, + anIsElemNames, + &anElemNum, + anIsElemNum, + &aFamNum, anInfo.myNbElem, - med_entite_maillage(theInfo.myEntity), - med_geometrie_element(theInfo.myGeom), - med_connectivite(theInfo.myConnMode)); + anEntity, + aGeom, + aConnMode); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetCellInfo - MEDelementsLire(...)"); + EXCEPTION(std::runtime_error,"SetCellInfo - MEDelementsLire(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetCellInfo(const MED::TCellInfo& theInfo, @@ -1218,13 +1419,14 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; return MEDnChamp(myFile->Id(),0); } + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbComp(TInt theFieldId, @@ -1232,39 +1434,49 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return -1; return MEDnChamp(myFile->Id(),theFieldId); } + //---------------------------------------------------------------------------- void TVWrapper ::GetFieldInfo(TInt theFieldId, MED::TFieldInfo& theInfo, - TErr* theErr) + TErr* theErr) { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; + TString aFieldName(256); // Protect from memory problems with too long names + TValueHolder<ETypeChamp, med_type_champ> aType(theInfo.myType); + TValueHolder<TString, char> aCompNames(theInfo.myCompNames); + TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames); + TErr aRet; aRet = MEDchampInfo(myFile->Id(), theFieldId, - &theInfo.myName[0], - (med_type_champ*)&theInfo.myType, - &theInfo.myCompNames[0], - &theInfo.myUnitNames[0], + &aFieldName[0], + &aType, + &aCompNames, + &anUnitNames, theInfo.myNbComp); - if(theErr) + + theInfo.SetName(aFieldName); + + if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetFieldInfo - MEDchampInfo(...)"); + EXCEPTION(std::runtime_error,"GetFieldInfo - MEDchampInfo(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetFieldInfo(const MED::TFieldInfo& theInfo, @@ -1273,25 +1485,31 @@ namespace MED { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo); + TValueHolder<TString, char> aFieldName(anInfo.myName); + TValueHolder<ETypeChamp, med_type_champ> aType(anInfo.myType); + TValueHolder<TString, char> aCompNames(anInfo.myCompNames); + TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames); + TErr aRet; aRet = MEDchampCr(myFile->Id(), - &anInfo.myName[0], - med_type_champ(theInfo.myType), - &anInfo.myCompNames[0], - &anInfo.myUnitNames[0], + &aFieldName, + aType, + &aCompNames, + &anUnitNames, anInfo.myNbComp); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetFieldInfo - MEDchampEcr(...)"); + EXCEPTION(std::runtime_error,"SetFieldInfo - MEDchampEcr(...)"); } + //---------------------------------------------------------------------------- void TVWrapper ::SetFieldInfo(const MED::TFieldInfo& theInfo, @@ -1301,11 +1519,14 @@ namespace MED SetFieldInfo(theInfo,eLECTURE_ECRITURE,&aRet); if(aRet < 0) - SetFieldInfo(theInfo,eLECTURE_AJOUT,theErr); + SetFieldInfo(theInfo,eLECTURE_AJOUT,&aRet); + + if(theErr) + *theErr = aRet; } - //----------------------------------------------------------------- + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbGauss(TErr* theErr) @@ -1319,6 +1540,7 @@ namespace MED } + //---------------------------------------------------------------------------- TGaussInfo::TInfo TVWrapper ::GetGaussPreInfo(TInt theId, @@ -1327,7 +1549,7 @@ namespace MED TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); if(theErr && *theErr < 0) - return TGaussInfo::TInfo(); + return TGaussInfo::TInfo( TGaussInfo::TKey(ePOINT1,""),0 ); med_int aNbGaussPoints = med_int(); TVector<char> aName(GetNOMLength<eV2_2>()+1); @@ -1342,13 +1564,14 @@ namespace MED if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetGaussPreInfo - MEDgaussInfo(...)"); + EXCEPTION(std::runtime_error,"GetGaussPreInfo - MEDgaussInfo(...)"); return TGaussInfo::TInfo(TGaussInfo::TKey(EGeometrieElement(aGeom),&aName[0]), TInt(aNbGaussPoints)); } + //---------------------------------------------------------------------------- void TVWrapper ::GetGaussInfo(TInt theId, @@ -1360,22 +1583,28 @@ namespace MED if(theErr && *theErr < 0) return; + TValueHolder<TNodeCoord, med_float> aRefCoord(theInfo.myRefCoord); + TValueHolder<TNodeCoord, med_float> aGaussCoord(theInfo.myGaussCoord); + TValueHolder<TWeight, med_float> aWeight(theInfo.myWeight); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch); + TValueHolder<TString, char> aGaussName(theInfo.myName); + TErr aRet; aRet = MEDgaussLire(myFile->Id(), - &theInfo.myRefCoord[0], - &theInfo.myGaussCoord[0], - &theInfo.myWeight[0], - med_mode_switch(theInfo.myModeSwitch), - &theInfo.myName[0]); + &aRefCoord, + &aGaussCoord, + &aWeight, + aModeSwitch, + &aGaussName); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetGaussInfo - MEDgaussLire(...)"); + EXCEPTION(std::runtime_error,"GetGaussInfo - MEDgaussLire(...)"); } - //----------------------------------------------------------------- + //---------------------------------------------------------------------------- TInt TVWrapper ::GetNbProfiles(TErr* theErr) @@ -1388,7 +1617,6 @@ namespace MED return MEDnProfil(myFile->Id()); } - TProfileInfo::TInfo TVWrapper ::GetProfilePreInfo(TInt theId, @@ -1399,7 +1627,7 @@ namespace MED if(theErr && *theErr < 0) return TProfileInfo::TInfo(); - TInt aSize = -1; + med_int aSize = -1; TVector<char> aName(GetNOMLength<eV2_2>()+1); TErr aRet; @@ -1410,12 +1638,11 @@ namespace MED if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetProfilePreInfo - MEDprofilInfo(...)"); + EXCEPTION(std::runtime_error,"GetProfilePreInfo - MEDprofilInfo(...)"); return TProfileInfo::TInfo(&aName[0],aSize); } - void TVWrapper ::GetProfileInfo(TInt theId, @@ -1427,16 +1654,63 @@ namespace MED if(theErr && *theErr < 0) return; + TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<TString, char> aProfileName(anInfo.myName); + TErr aRet; aRet = MEDprofilLire(myFile->Id(), - &theInfo.myElemNum[0], - &theInfo.myName[0]); + &anElemNum, + &aProfileName); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetProfileInfo - MEDprofilLire(...)"); + EXCEPTION(std::runtime_error,"GetProfileInfo - MEDprofilLire(...)"); } + void + TVWrapper + ::SetProfileInfo(const TProfileInfo& theInfo, + EModeAcces theMode, + TErr* theErr) + { + TFileWrapper aFileWrapper(myFile,theMode,theErr); + + if(theErr && *theErr < 0) + return; + + TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo); + TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum); + TValueHolder<TString, char> aProfileName(anInfo.myName); + + TErr aRet; + aRet = MEDprofilEcr(myFile->Id(), // descripteur du fichier. + &anElemNum, // tableau de valeurs du profil. + theInfo.GetSize(), // taille du profil. + &aProfileName); // nom profil. + if(theErr) + *theErr = aRet; + else if(aRet < 0) + EXCEPTION(std::runtime_error,"SetProfileInfo - MEDprofilEcr(...)"); + } + + void + TVWrapper + ::SetProfileInfo(const TProfileInfo& theInfo, + TErr* theErr) + { + TErr aRet; + SetProfileInfo(theInfo,eLECTURE_ECRITURE,&aRet); + + if(aRet < 0) + SetProfileInfo(theInfo,eLECTURE_AJOUT,&aRet); + + if(aRet < 0) + SetProfileInfo(theInfo,eCREATION,&aRet); + + if(theErr) + *theErr = aRet; + } //----------------------------------------------------------------- TInt @@ -1456,20 +1730,16 @@ namespace MED if(*theErr < 0) return -1; }else if(theEntityInfo.empty()) - EXCEPTION(runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh"); + EXCEPTION(std::runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh"); bool anIsPerformAdditionalCheck = GetNbMeshes() > 1; -#ifdef _DEBUG_ - static bool anIsCheckOnlyFirstTimeStamp = false; -#else - static bool anIsCheckOnlyFirstTimeStamp = true; -#endif theGeom2Size.clear(); TInt aNbTimeStamps = 0; TIdt anId = myFile->Id(); MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo); + TValueHolder<TString, char> aFieldName(anInfo.myName); MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo; TEntityInfo::const_iterator anIter = theEntityInfo.begin(); @@ -1480,7 +1750,7 @@ namespace MED for(; anGeomIter != aGeom2Size.end(); anGeomIter++){ med_geometrie_element aGeom = med_geometrie_element(anGeomIter->first); TInt aNbStamps = MEDnPasdetemps(anId, - &anInfo.myName[0], + &aFieldName, anEntity, aGeom); bool anIsSatisfied = aNbStamps > 0; @@ -1489,7 +1759,7 @@ namespace MED "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<< "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n"); if(anIsPerformAdditionalCheck){ - TInt iTimeStampEnd = anIsCheckOnlyFirstTimeStamp? 1: aNbStamps; + TInt iTimeStampEnd = aNbStamps; for(TInt iTimeStamp = 1; iTimeStamp <= iTimeStampEnd; iTimeStamp++){ TVector<char> aMeshName(GetNOMLength<eV2_2>()+1); TVector<char> aDtUnit(GetPNOMLength<eV2_2>()+1); @@ -1500,7 +1770,7 @@ namespace MED med_booleen anIsLocal; med_int aNbRef; TErr aRet = MEDpasdetempsInfo(anId, - &anInfo.myName[0], + &aFieldName, anEntity, aGeom, iTimeStamp, @@ -1536,6 +1806,7 @@ namespace MED } + //---------------------------------------------------------------------------- void TVWrapper ::GetTimeStampInfo(TInt theTimeStampId, @@ -1552,11 +1823,21 @@ namespace MED if(*theErr < 0) return; }else if(aGeom2Size.empty()) - EXCEPTION(runtime_error,"GetTimeStampInfo - There is no any cell"); + EXCEPTION(std::runtime_error,"GetTimeStampInfo - There is no any cell"); MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo; MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo; + TValueHolder<TString, char> aFieldName(aFieldInfo.myName); + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(theInfo.myEntity); + TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt); + TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd); + TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt); + TValueHolder<TFloat, med_float> aDt(theInfo.myDt); + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<EBooleen, med_booleen> anIsLocal(aFieldInfo.myIsLocal); + TValueHolder<TInt, med_int> aNbRef(aFieldInfo.myNbRef); + TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss; TGeom2Size::const_iterator anIter = aGeom2Size.begin(); @@ -1566,18 +1847,18 @@ namespace MED TErr aRet; aRet = MEDpasdetempsInfo(myFile->Id(), - &aFieldInfo.myName[0], - med_entite_maillage(theInfo.myEntity), + &aFieldName, + anEntity, med_geometrie_element(aGeom), theTimeStampId, &aNbGauss, - (med_int*)&theInfo.myNumDt, - (med_int*)&theInfo.myNumOrd, - &theInfo.myUnitDt[0], - &theInfo.myDt, - &aMeshInfo.myName[0], - (med_booleen*)&aFieldInfo.myIsLocal, - (med_int*)&aFieldInfo.myNbRef); + &aNumDt, + &aNumOrd, + &anUnitDt, + &aDt, + &aMeshName, + &anIsLocal, + &aNbRef); static TInt MAX_NB_GAUSS_POINTS = 32; if(aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS) @@ -1588,68 +1869,79 @@ namespace MED if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)"); + EXCEPTION(std::runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)"); } } + //---------------------------------------------------------------------------- void TVWrapper - ::GetTimeStampVal(TTimeStampVal& theVal, - const TMKey2Profile& theMKey2Profile, - const TKey2Gauss& theKey2Gauss, - TErr* theErr) + ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr) { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; TIdt anId = myFile->Id(); - MED::TTimeStampInfo& aTimeStampInfo = *theVal.myTimeStampInfo; - MED::TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo; - MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo; + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch); + MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile; + + MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo; + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity); + TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt); + TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd); + + MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo; + TValueHolder<TString, char> aFieldName(aFieldInfo->myName); + TValueHolder<EBooleen, med_booleen> anIsLocal(aFieldInfo->myIsLocal); + + MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo->myName); - TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.myGeom2Gauss; + TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss; TVector<char> aGaussName(GetNOMLength<eV2_2>()+1); med_mode_profil aProfileMode = med_mode_profil(boost::get<0>(theMKey2Profile)); MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile); - MED::TGeom2Profile& aGeom2Profile = theVal.myGeom2Profile; TVector<char> aProfileName(GetNOMLength<eV2_2>()+1); - TGeom2Size& aGeom2Size = aTimeStampInfo.myGeom2Size; + TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size; TGeom2Size::iterator anIter = aGeom2Size.begin(); for(; anIter != aGeom2Size.end(); anIter++){ EGeometrieElement aGeom = anIter->first; - TInt aNbCells = anIter->second; + TInt aNbElem = anIter->second; TInt aNbMeshRef = MEDnChampRef(anId, - &aFieldInfo.myName[0], - med_entite_maillage(aTimeStampInfo.myEntity), + &aFieldName, + anEntity, med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd); + aNumDt, + aNumOrd); if(aNbMeshRef < 1){ if(theErr){ *theErr = MED_FAUX; return; } - EXCEPTION(runtime_error,"GetTimeStampVal - MEDnChampRef(...) < 1"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDnChampRef(...) < 1"); } TErr aRet; med_int aNbGauss = -1; aRet = MEDchampRefInfo(anId, - &aFieldInfo.myName[0], - med_entite_maillage(aTimeStampInfo.myEntity), + &aFieldName, + anEntity, med_geometrie_element(aGeom), aNbMeshRef, - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd, - &aMeshInfo.myName[0], - (med_booleen*)&aFieldInfo.myIsLocal, + aNumDt, + aNumOrd, + &aMeshName, + &anIsLocal, &aNbGauss); if(aRet < 0){ @@ -1657,81 +1949,60 @@ namespace MED *theErr = MED_FAUX; return; } - EXCEPTION(runtime_error,"GetTimeStampVal - MEDchampRefInfo(...)"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDchampRefInfo(...)"); } TInt aNbVal = MEDnVal(anId, - &aFieldInfo.myName[0], - med_entite_maillage(aTimeStampInfo.myEntity), + &aFieldName, + anEntity, med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd, - &aMeshInfo.myName[0], + aNumDt, + aNumOrd, + &aMeshName, aProfileMode); if(aNbVal <= 0){ if(theErr){ *theErr = -1; return; } - EXCEPTION(runtime_error,"GetTimeStampInfo - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0"); } - TMeshValue& aMeshValue = theVal.GetMeshValue(aGeom); - TInt aNbElem = aNbVal / aNbGauss; - aMeshValue.Init(aNbElem, - aNbGauss, - aFieldInfo.myNbComp); - TValue& aValue = aMeshValue.myValue; - TInt anEnd = aValue.size(); - - switch(aFieldInfo.myType){ - case eFLOAT64: { - TVector<TFloat> anArray(anEnd); - aRet = MEDchampLire(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - MED_ALL, - &aGaussName[0], - &aProfileName[0], - aProfileMode, - med_entite_maillage(aTimeStampInfo.myEntity), - med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd); - if(aRet >= 0) - for(TInt anId = 0; anId < anEnd; anId++) - aValue[anId] = anArray[anId]; - break; - } - default: { - TVector<TInt> anArray(anEnd); - aRet = MEDchampLire(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - MED_ALL, - &aGaussName[0], - &aProfileName[0], - aProfileMode, - med_entite_maillage(aTimeStampInfo.myEntity), - med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - aTimeStampInfo.myNumOrd); - if(aRet >= 0) - for(TInt anId = 0; anId < anEnd; anId++) - aValue[anId] = anArray[anId]; - break; - }} - + TInt aNbComp = aFieldInfo->myNbComp; + TInt aNbValue = aNbVal / aNbGauss; + theTimeStampValue->AllocateValue(aGeom, + aNbValue, + aNbGauss, + aNbComp); + TInt aValueSize = theTimeStampValue->GetValueSize(aGeom); + + INITMSG(MYDEBUG, + "TVWrapper::GetTimeStampValue - aGeom = "<<aGeom<< + "; aNbVal = "<<aNbVal<< + "; aNbValue = "<<aNbValue<< + "; aNbGauss = "<<aNbGauss<< + "; aNbComp = "<<aNbComp<< + std::endl); + + aRet = MEDchampLire(anId, + &aMeshName, + &aFieldName, + theTimeStampValue->GetValuePtr(aGeom), + aModeSwitch, + MED_ALL, + &aGaussName[0], + &aProfileName[0], + aProfileMode, + anEntity, + med_geometrie_element(aGeom), + aNumDt, + aNumOrd); if(aRet < 0){ if(theErr){ *theErr = MED_FAUX; return; } - EXCEPTION(runtime_error,"GetValTimeStamp - MEDchampLire(...)"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - MEDchampLire(...)"); } MED::PGaussInfo aGaussInfo; @@ -1758,7 +2029,7 @@ namespace MED *theErr = MED_FAUX; return; } - EXCEPTION(runtime_error,"GetValTimeStamp "<< + EXCEPTION(std::runtime_error,"GetTimeStampValue "<< "- aNbGauss("<<aNbGauss<<") > 1 && !aGaussInfo"<< "; aGaussName = '"<<&aGaussName[0]<<"'"<< "; aGeom = "<<aGeom<< @@ -1770,44 +2041,43 @@ namespace MED *theErr = MED_FAUX; return; } - EXCEPTION(runtime_error,"GetValTimeStamp - aNbGauss != aGaussInfo->GetNbGauss()"); + EXCEPTION(std::runtime_error,"GetTimeStampValue - aNbGauss != aGaussInfo->GetNbGauss()"); } if(aProfileInfo && aProfileInfo->IsPresent()){ - TInt aNbSubCells = aProfileInfo->GetSize(); - - TInt aSize = aNbSubCells*aFieldInfo.myNbComp*aNbGauss; - if(aSize != aValue.size()){ + TInt aNbSubElem = aProfileInfo->GetSize(); + TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss; + if(aProfileSize != aValueSize){ if(theErr){ *theErr = -1; return; } - EXCEPTION(runtime_error, - "GetTimeStampInfo - aSize("<<aSize<< - ") != aValue.size()("<<aValue.size()<< + EXCEPTION(std::runtime_error, + "GetTimeStampValue - aProfileSize("<<aProfileSize<< + ") != aValueSize("<<aValueSize<< "); aNbVal = "<<aNbVal<< - "; anEntity = "<<aTimeStampInfo.myEntity<< + "; anEntity = "<<anEntity<< "; aGeom = "<<aGeom<< - "; aNbCells = "<<aNbCells<< - "; aNbSubCells = "<<aNbSubCells<< - "; aNbComp = "<<aFieldInfo.myNbComp<< + "; aNbElem = "<<aNbElem<< + "; aNbSubElem = "<<aNbSubElem<< + "; aNbComp = "<<aNbComp<< "; aNbGauss = "<<aNbGauss<< ""); } }else{ - if(anEnd != aValue.size()){ + if(aNbElem != aNbValue){ if(theErr){ *theErr = -1; return; } - EXCEPTION(runtime_error, - "GetTimeStampInfo - anEnd("<<anEnd<< - ") != aValue.size()("<<aValue.size()<< + EXCEPTION(std::runtime_error, + "GetTimeStampValue - aNbElem("<<aNbElem<< + ") != aNbValue("<<aNbValue<< "); aNbVal = "<<aNbVal<< - "; anEntity = "<<aTimeStampInfo.myEntity<< + "; anEntity = "<<anEntity<< "; aGeom = "<<aGeom<< - "; aNbCells = "<<aNbCells<< - "; aNbComp = "<<aFieldInfo.myNbComp<< + "; aNbElem = "<<aNbElem<< + "; aNbComp = "<<aNbComp<< "; aNbGauss = "<<aNbGauss<< ""); } @@ -1816,34 +2086,42 @@ namespace MED } + //---------------------------------------------------------------------------- void TVWrapper - ::SetTimeStamp(const MED::TTimeStampVal& theVal, - EModeAcces theMode, - TErr* theErr) + ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue, + EModeAcces theMode, + TErr* theErr) { TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr && !*theErr) + if(theErr && *theErr < 0) return; TErr aRet; TIdt anId = myFile->Id(); - MED::TTimeStampVal& aVal = const_cast<MED::TTimeStampVal&>(theVal); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theTimeStampValue->myModeSwitch); + MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile; - MED::TTimeStampInfo& aTimeStampInfo = *aVal.myTimeStampInfo; - MED::TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo; - MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo; - MED::TGeom2Value& aGeom2Value = aVal.myGeom2Value; - - MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo.myGeom2Gauss; - MED::TGeom2Profile& aGeom2Profile = aVal.myGeom2Profile; + MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo; + TValueHolder<EEntiteMaillage, med_entite_maillage> anEntity(aTimeStampInfo->myEntity); + TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt); + TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd); + TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt); + TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt); + MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss; - TGeom2Value::iterator anIter = aGeom2Value.begin(); - for(; anIter != aGeom2Value.end(); anIter++){ - EGeometrieElement aGeom = anIter->first; - TMeshValue& aMeshValue = anIter->second; + MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo; + TValueHolder<TString, char> aFieldName(aFieldInfo->myName); + + MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo->myName); + + const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet; + TGeomSet::const_iterator anIter = aGeomSet.begin(); + for(; anIter != aGeomSet.end(); anIter++){ + EGeometrieElement aGeom = *anIter; TVector<char> aGaussName(GetNOMLength<eV2_2>()+1); MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aGeom); @@ -1861,82 +2139,55 @@ namespace MED strcpy(&aProfileName[0],&aProfileInfo->myName[0]); } - med_int aNbVal = aMeshValue.myNbElem * aMeshValue.myNbGauss; - TValue& aValue = aMeshValue.myValue; - TInt anEnd = aValue.size(); - - switch(aFieldInfo.myType){ - case eFLOAT64: { - TVector<TFloat>& anArray = aValue; - - aRet = MEDchampEcr(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - aNbVal, - &aGaussName[0], - MED_ALL, - &aProfileName[0], - aProfileMode, - med_entite_maillage(aTimeStampInfo.myEntity), - med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - &aTimeStampInfo.myUnitDt[0], - aTimeStampInfo.myDt, - aTimeStampInfo.myNumOrd); - break; - } - default: { - vector<TInt> anArray(anEnd); - for(TInt anID = 0; anID < anEnd; anID++) - anArray[anID] = TInt(aValue[anID]); - - aRet = MEDchampEcr(anId, - &aMeshInfo.myName[0], - &aFieldInfo.myName[0], - (unsigned char*)&anArray[0], - med_mode_switch(theVal.myModeSwitch), - aNbVal, - &aGaussName[0], - MED_ALL, - &aProfileName[0], - aProfileMode, - med_entite_maillage(aTimeStampInfo.myEntity), - med_geometrie_element(aGeom), - aTimeStampInfo.myNumDt, - &aTimeStampInfo.myUnitDt[0], - aTimeStampInfo.myDt, - aTimeStampInfo.myNumOrd); - break; - }} - + med_int aNbVal = theTimeStampValue->GetNbVal(aGeom); + + aRet = MEDchampEcr(anId, + &aMeshName, + &aFieldName, + theTimeStampValue->GetValuePtr(aGeom), + aModeSwitch, + aNbVal, + &aGaussName[0], + MED_ALL, + &aProfileName[0], + aProfileMode, + anEntity, + med_geometrie_element(aGeom), + aNumDt, + &anUnitDt, + aDt, + aNumOrd); if(aRet < 0){ if(theErr){ *theErr = MED_FAUX; break; } - EXCEPTION(runtime_error,"SetTimeStamp - MEDchampEcr(...)"); + EXCEPTION(std::runtime_error,"SetTimeStampValue - MEDchampEcr(...)"); } } - INITMSG(MYDEBUG,"TVWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<endl); + INITMSG(MYDEBUG,"TVWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl); } + //---------------------------------------------------------------------------- void TVWrapper - ::SetTimeStamp(const MED::TTimeStampVal& theVal, - TErr* theErr) + ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + TErr* theErr) { TErr aRet; - SetTimeStamp(theVal,eLECTURE_ECRITURE,&aRet); + SetTimeStampValue(theTimeStampValue,eLECTURE_ECRITURE,&aRet); if(aRet < 0) - SetTimeStamp(theVal,eLECTURE_AJOUT,theErr); + SetTimeStampValue(theTimeStampValue,eLECTURE_AJOUT,&aRet); + + if(theErr) + *theErr = aRet; } + //---------------------------------------------------------------------------- void TVWrapper ::SetGrilleInfo(const MED::TGrilleInfo& theInfo, @@ -1945,6 +2196,7 @@ namespace MED SetGrilleInfo(theInfo,eLECTURE_ECRITURE,theErr); } + //---------------------------------------------------------------------------- void TVWrapper ::SetGrilleInfo(const MED::TGrilleInfo& theInfo, @@ -1955,56 +2207,67 @@ namespace MED return; TFileWrapper aFileWrapper(myFile,theMode,theErr); - if(theErr) - if(!*theErr) + if(theErr && *theErr < 0) return; MED::TGrilleInfo& anInfo = const_cast<MED::TGrilleInfo&>(theInfo); + MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + + TValueHolder<EGrilleType, med_type_grille> aGrilleType(anInfo.myGrilleType); TErr aRet = 0; aRet = MEDnatureGrilleEcr(myFile->Id(), - &aMeshInfo.myName[0], - (med_type_grille)anInfo.myGrilleType); + &aMeshName, + aGrilleType); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"SetGrilleInfo - MEDnatureGrilleEcr(...)"); + EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDnatureGrilleEcr(...)"); if(anInfo.myGrilleType == eGRILLE_STANDARD){ - med_int nnoeuds = (med_int)(anInfo.myCoord.size()/aMeshInfo.myDim); + TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(anInfo.myModeSwitch); + TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames); + TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits); + med_int aNbNoeuds = med_int(anInfo.myCoord.size() / aMeshInfo.myDim); + med_repere aRepere = MED_CART; + aRet = MEDcoordEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &anInfo.myCoord[0], - med_mode_switch(anInfo.myModeSwitch), - nnoeuds, - (med_repere)theInfo.myGrilleType, - &anInfo.myCoordNames[0], - &anInfo.myCoordUnits[0]); + &aMeshName, + aDim, + &aCoord, + aModeSwitch, + aNbNoeuds, + aRepere, + &aCoordNames, + &aCoordUnits); if(aRet < 0) - EXCEPTION(runtime_error,"SetGrilleInfo - MEDcoordEcr(...)"); + EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDcoordEcr(...)"); + TValueHolder<TIntVector, med_int> aGrilleStructure(anInfo.myGrilleStructure); aRet = MEDstructureCoordEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &anInfo.myGrilleStructure[0]); + &aMeshName, + aDim, + &aGrilleStructure); if(aRet < 0) - EXCEPTION(runtime_error,"SetGrilleInfo - MEDstructureCoordEcr(...)"); + EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDstructureCoordEcr(...)"); } else { - for(int aAxe=0;aAxe<aMeshInfo.myDim;aAxe++){ + for(med_int aAxis = 0; aAxis < aMeshInfo.myDim; aAxis++){ aRet = MEDindicesCoordEcr(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &anInfo.GetIndexes(aAxe)[0], - anInfo.GetIndexes(aAxe).size(), - aAxe+1, - &anInfo.GetCoordName(aAxe)[0], - &anInfo.GetCoordUnit(aAxe)[0]); + &aMeshName, + aDim, + &anInfo.GetIndexes(aAxis)[0], + anInfo.GetIndexes(aAxis).size(), + aAxis + 1, + &anInfo.GetCoordName(aAxis)[0], + &anInfo.GetCoordUnit(aAxis)[0]); if(aRet < 0) - EXCEPTION(runtime_error,"SetGrilleInfo - MEDindicesCoordEcr(...)"); + EXCEPTION(std::runtime_error,"SetGrilleInfo - MEDindicesCoordEcr(...)"); } } @@ -2012,6 +2275,7 @@ namespace MED return; } + //---------------------------------------------------------------------------- void TVWrapper ::GetGrilleInfo(TGrilleInfo& theInfo, @@ -2019,119 +2283,157 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr) - if(!*theErr) + if(theErr && *theErr < 0) return; - MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; - - EMaillage type_maillage = aMeshInfo.myType; + MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + EMaillage aMaillageType = aMeshInfo.myType; - GetGrilleType(aMeshInfo,theInfo.myGrilleType,theErr); - EGrilleType type = theInfo.myGrilleType; + GetGrilleType(aMeshInfo, theInfo.myGrilleType, theErr); + EGrilleType aGrilleType = theInfo.myGrilleType; + + TErr aRet = 0; + if(aMaillageType == eSTRUCTURE && aGrilleType == eGRILLE_STANDARD){ + GetGrilleStruct(aMeshInfo, theInfo.myGrilleStructure, theErr); + + TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord); + TValueHolder<EModeSwitch, med_mode_switch> aModeSwitch(theInfo.myModeSwitch); + TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames); + TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits); + med_repere aRepere; - TErr aRet; - if(type_maillage == eSTRUCTURE && type == eGRILLE_STANDARD){ - - GetGrilleStruct(aMeshInfo,theInfo.myGrilleStructure,theErr); - aRet = MEDcoordLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - &theInfo.myCoord[0], - med_mode_switch(theInfo.myModeSwitch), + &aMeshName, + aDim, + &aCoord, + aModeSwitch, MED_ALL, // all coordinates must be return NULL, 0, - (med_repere*)&theInfo.myGrilleType, - &theInfo.myCoordNames[0], - &theInfo.myCoordUnits[0]); + &aRepere, + &aCoordNames, + &aCoordUnits); + + if(theErr) + *theErr = aRet; + else if(aRet < 0) + EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDcoordLire(...)"); + + TInt aNbNodes = theInfo.GetNbNodes();//GetNbFamilies(aMeshInfo); + TValueHolder<TElemNum, med_int> aFamNumNode(theInfo.myFamNumNode); + + aRet = MEDfamLire(myFile->Id(), + &aMeshName, + &aFamNumNode, + aNbNodes, + med_entite_maillage(eNOEUD), + med_geometrie_element(ePOINT1)); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetGrilleInfo - MEDcoordLire(...)"); + EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDfamLire(...) of NODES"); + //============================ } - if(type_maillage == eSTRUCTURE && type != eGRILLE_STANDARD){ - med_table quoi; - for(int aAxe=1;aAxe<=aMeshInfo.myDim;aAxe++) - { - switch(aAxe) { - case 1 : - quoi = MED_COOR_IND1; - break; - case 2 : - quoi = MED_COOR_IND2; - break; - case 3 : - quoi = MED_COOR_IND3; - break; - - default : - aRet = -1; - } - - if(theErr) - *theErr = aRet; - else if(aRet < 0) - EXCEPTION(runtime_error,"GetGrilleInfo - Axe number out of range(...)"); - - TInt nind = GetNbNodes(aMeshInfo,(ETable)quoi); - if(nind < 0) - EXCEPTION(runtime_error,"GetGrilleInfo - Erreur a la lecture de la taille de l'indice"); + if(aMaillageType == eSTRUCTURE && aGrilleType != eGRILLE_STANDARD){ + ETable aTable; + for(med_int anAxis = 1; anAxis <= aMeshInfo.myDim; anAxis++){ + switch(anAxis){ + case 1 : + aTable = eCOOR_IND1; + break; + case 2 : + aTable = eCOOR_IND2; + break; + case 3 : + aTable = eCOOR_IND3; + break; + default : + aRet = -1; + } - med_float* indices = (med_float*)&theInfo.myIndixes[aAxe-1][0]; + if(theErr) + *theErr = aRet; + else if(aRet < 0) + EXCEPTION(std::runtime_error,"GetGrilleInfo - anAxis number out of range(...)"); + + TInt aNbIndexes = GetNbNodes(aMeshInfo,aTable); + if(aNbIndexes < 0) + EXCEPTION(std::runtime_error,"GetGrilleInfo - Erreur a la lecture de la taille de l'indice"); - char comp[MED_TAILLE_PNOM+1]; - char unit[MED_TAILLE_PNOM+1]; + TValueHolder<TFloatVector, med_float> anIndexes(theInfo.GetIndexes(anAxis-1)); + char aCompNames[MED_TAILLE_PNOM+1]; + char anUnitNames[MED_TAILLE_PNOM+1]; - aRet = MEDindicesCoordLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - indices, - (med_int)nind, - (med_int)aAxe, - comp, - unit); - theInfo.SetCoordName(aAxe-1,comp); - theInfo.SetCoordUnit(aAxe-1,unit); - if(theErr) - *theErr = aRet; - else if(aRet < 0) - EXCEPTION(runtime_error,"GetGrilleInfo - MEDindicesCoordLire(...)"); - } + aRet = MEDindicesCoordLire(myFile->Id(), + &aMeshName, + aDim, + &anIndexes, + aNbIndexes, + anAxis, + aCompNames, + anUnitNames); + + theInfo.SetCoordName(anAxis-1, aCompNames); + theInfo.SetCoordUnit(anAxis-1, anUnitNames); + + if(theErr) + *theErr = aRet; + else if(aRet < 0) + EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDindicesCoordLire(...)"); + } + } + + EGeometrieElement aGeom = theInfo.GetGeom(); + EEntiteMaillage aEntity = theInfo.GetEntity(); + TInt aNbCells = theInfo.GetNbCells(); + + theInfo.myFamNum.resize(aNbCells); + TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum); + + aRet = MEDfamLire(myFile->Id(), + &aMeshName, + &aFamNum, + aNbCells, + med_entite_maillage(aEntity), + med_geometrie_element(aGeom)); + + if(theErr) + *theErr = aRet; + else if(aRet < 0){ + //EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDfamLire(...) of CELLS"); + aRet = 0; + theInfo.myFamNum.resize(0); } + } void TVWrapper ::GetGrilleType(const MED::TMeshInfo& theMeshInfo, - EGrilleType& type, + EGrilleType& theGrilleType, TErr* theErr) { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr) - if(!*theErr) - EXCEPTION(runtime_error," GetGrilleType - aFileWrapper (...)"); + if(theErr && *theErr < 0) + EXCEPTION(std::runtime_error," GetGrilleType - aFileWrapper (...)"); MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); - EMaillage type_maillage = aMeshInfo.myType; - - TErr aRet; - if(type_maillage == eSTRUCTURE){ - med_type_grille Mtype; - aRet = MEDnatureGrilleLire(myFile->Id(), - &aMeshInfo.myName[0], - &Mtype); - if(aRet < 0) - EXCEPTION(runtime_error,"GetGrilleInfo - MEDnatureGrilleLire(...)"); - - type = (EGrilleType)Mtype; + if(aMeshInfo.myType == eSTRUCTURE){ + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<EGrilleType, med_type_grille> aGrilleType(theGrilleType); + TErr aRet = MEDnatureGrilleLire(myFile->Id(), + &aMeshName, + &aGrilleType); + if(aRet < 0) + EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDnatureGrilleLire(...)"); } } @@ -2143,23 +2445,24 @@ namespace MED { TFileWrapper aFileWrapper(myFile,eLECTURE,theErr); - if(theErr) - if(!*theErr) + if(theErr && *theErr < 0) return; TErr aRet; MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo); - med_int* anGrilleStruct = aMeshInfo.myDim > 0? (med_int*)&theStruct[0]: NULL; + TValueHolder<TString, char> aMeshName(aMeshInfo.myName); + TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim); + TValueHolder<TIntVector, med_int> aGrilleStructure(theStruct); aRet = MEDstructureCoordLire(myFile->Id(), - &aMeshInfo.myName[0], - aMeshInfo.myDim, - anGrilleStruct); + &aMeshName, + aDim, + &aGrilleStructure); if(theErr) *theErr = aRet; else if(aRet < 0) - EXCEPTION(runtime_error,"GetGrilleInfo - MEDstructureCoordLire(...)"); + EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDstructureCoordLire(...)"); } } diff --git a/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.hxx b/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.hxx index 6eeebd573..6b7b22212 100644 --- a/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.hxx +++ b/src/MEDWrapper/V2_2/MED_V2_2_Wrapper.hxx @@ -29,64 +29,69 @@ #ifndef MED_V2_2_Wrapper_HeaderFile #define MED_V2_2_Wrapper_HeaderFile +#ifdef WNT + #if defined MEDWRAPPER_V2_2_EXPORTS + #if defined WIN32 + #define MED_V22_WRAPPER_EXPORT __declspec( dllexport ) + #else + #define MED_V22_WRAPPER_EXPORT + #endif + #else + #if defined WIN32 + #define MED_V22_WRAPPER_EXPORT __declspec( dllimport ) + #else + #define MED_V22_WRAPPER_EXPORT + #endif + #endif +#else + #define MED_V22_WRAPPER_EXPORT +#endif + #include "MED_Structures.hxx" #include "MED_TWrapper.hxx" namespace MED { template<> - TInt + TInt MED_V22_WRAPPER_EXPORT GetDESCLength<eV2_2>(); template<> - TInt + TInt MED_V22_WRAPPER_EXPORT GetIDENTLength<eV2_2>(); template<> - TInt + TInt MED_V22_WRAPPER_EXPORT GetNOMLength<eV2_2>(); template<> - TInt + TInt MED_V22_WRAPPER_EXPORT GetLNOMLength<eV2_2>(); template<> - TInt + TInt MED_V22_WRAPPER_EXPORT GetPNOMLength<eV2_2>(); template<> - TInt + void MED_V22_WRAPPER_EXPORT + GetVersionRelease<eV2_2>(TInt& majeur, TInt& mineur, TInt& release); + + template<> + TInt MED_V22_WRAPPER_EXPORT GetNbConn<eV2_2>(EGeometrieElement typmai, EEntiteMaillage typent, TInt mdim); namespace V2_2 { - - typedef MED::TTMeshInfo<eV2_2> TVMeshInfo; - - typedef MED::TTFamilyInfo<eV2_2> TVFamilyInfo; - - typedef MED::TTNodeInfo<eV2_2> TVNodeInfo; - - typedef MED::TTCellInfo<eV2_2> TVCellInfo; - - typedef MED::TTFieldInfo<eV2_2> TVFieldInfo; - - typedef MED::TTTimeStampInfo<eV2_2> TVTimeStampInfo; - - typedef MED::TTTimeStampVal<eV2_2> TVTimeStampVal; - - typedef MED::TTGrilleInfo<eV2_2> TVGrilleInfo; - - //--------------------------------------------------------------- + //---------------------------------------------------------------------------- class TFile; typedef boost::shared_ptr<TFile> PFile; typedef enum {eLECTURE, eLECTURE_ECRITURE, eLECTURE_AJOUT, eCREATION} EModeAcces; - //--------------------------------------------------------------- - class TVWrapper: public MED::TTWrapper<eV2_2> + //---------------------------------------------------------------------------- + class MED_V22_WRAPPER_EXPORT TVWrapper: public MED::TTWrapper<eV2_2> { TVWrapper(); TVWrapper(const TVWrapper&); @@ -95,7 +100,7 @@ namespace MED public: TVWrapper(const std::string& theFileName); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbMeshes(TErr* theErr = NULL); @@ -115,7 +120,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbFamilies(const MED::TMeshInfo& theMeshInfo, @@ -150,7 +155,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual void GetNames(TElemInfo& theInfo, @@ -215,7 +220,7 @@ namespace MED EGeometrieElement theGeom, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbNodes(const MED::TMeshInfo& theMeshInfo, @@ -244,7 +249,7 @@ namespace MED EModeAcces theMode, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual void GetPolygoneInfo(TPolygoneInfo& theInfo, @@ -276,7 +281,7 @@ namespace MED EConnectivite theConnMode = eNOD, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual void GetPolyedreInfo(TPolyedreInfo& theInfo, @@ -308,7 +313,7 @@ namespace MED EConnectivite theConnMode = eNOD, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TEntityInfo GetEntityInfo(const MED::TMeshInfo& theMeshInfo, @@ -339,7 +344,7 @@ namespace MED TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbFields(TErr* theErr = NULL); @@ -365,7 +370,7 @@ namespace MED EModeAcces theMode, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbGauss(TErr* theErr = NULL); @@ -381,7 +386,7 @@ namespace MED TGaussInfo& theInfo, TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbProfiles(TErr* theErr = NULL); @@ -397,8 +402,17 @@ namespace MED TProfileInfo& theInfo, TErr* theErr = NULL); + virtual + void + SetProfileInfo(const TProfileInfo& theInfo, + TErr* theErr = NULL); + + void + SetProfileInfo(const TProfileInfo& theInfo, + EModeAcces theMode, + TErr* theErr = NULL); - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + //---------------------------------------------------------------------------- virtual TInt GetNbTimeStamps(const MED::TFieldInfo& theInfo, @@ -415,21 +429,23 @@ namespace MED virtual void - GetTimeStampVal(MED::TTimeStampVal& theVal, - const TMKey2Profile& theMKey2Profile, - const TKey2Gauss& theKey2Gauss, - TErr* theErr = NULL); + GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + const TMKey2Profile& theMKey2Profile, + const TKey2Gauss& theKey2Gauss, + TErr* theErr = NULL); virtual void - SetTimeStamp(const MED::TTimeStampVal& theTimeStampVal, - TErr* theErr = NULL); + SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + TErr* theErr = NULL); void - SetTimeStamp(const MED::TTimeStampVal& theTimeStampVal, - EModeAcces theMode, - TErr* theErr = NULL); + SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue, + EModeAcces theMode, + TErr* theErr = NULL); + + //---------------------------------------------------------------------------- virtual void GetGrilleInfo(TGrilleInfo& theGrilleInfo, diff --git a/src/MEDWrapper/V2_2/Makefile.am b/src/MEDWrapper/V2_2/Makefile.am new file mode 100644 index 000000000..36dfbfedb --- /dev/null +++ b/src/MEDWrapper/V2_2/Makefile.am @@ -0,0 +1,41 @@ +# +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : +# Author : +# Module : +# $Header$ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMEDWrapper_V2_2.la + +salomeinclude_HEADERS = \ + MED_V2_2_Wrapper.hxx + +dist_libMEDWrapper_V2_2_la_SOURCES = \ + MED_V2_2_Wrapper.cxx + +libMEDWrapper_V2_2_la_CPPFLAGS= $(BOOST_CPPFLAGS) $(MED2_INCLUDES) -I$(srcdir)/../Base -I$(top_builddir)/salome_adm/unix +libMEDWrapper_V2_2_la_LDFLAGS= $(MED2_LIBS) $(HDF5_LIBS) +libMEDWrapper_V2_2_la_LIBADD= ../Base/libMEDWrapperBase.la diff --git a/src/MEDWrapper/V2_2/Makefile.in b/src/MEDWrapper/V2_2/Makefile.in deleted file mode 100644 index 69d4d3d69..000000000 --- a/src/MEDWrapper/V2_2/Makefile.in +++ /dev/null @@ -1,54 +0,0 @@ -# -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : -# Author : -# Module : -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -# Libraries targets - -LIB = libMEDWrapper_V2_2.la -LIB_SRC = \ - MED_V2_2_Wrapper.cxx - -EXPORT_HEADERS = \ - MED_V2_2_Wrapper.hxx - -# Executables targets -BIN = -BIN_SRC = - -CPPFLAGS+= $(BOOST_CPPFLAGS) $(MED2_INCLUDES) - -LDFLAGS+= $(MED2_LIBS) $(HDF5_LIBS) -lMEDWrapperBase - -@CONCLUDE@ diff --git a/src/MED_SWIG/MED_shared_modules.py b/src/MED_SWIG/MED_shared_modules.py index cea30c26b..3144240a2 100644 --- a/src/MED_SWIG/MED_shared_modules.py +++ b/src/MED_SWIG/MED_shared_modules.py @@ -24,8 +24,11 @@ # see salome_shared_modules.py # (avoids incomplete import at run time) -print "============== import MED_idl =======================" -print "============== import MED_Gen_idl =======================" +from launchConfigureParser import verbose + +if verbose(): + print "============== import MED_idl =======================" + print "============== import MED_Gen_idl =======================" import MED_idl import MED_Gen_idl diff --git a/src/MED_SWIG/Makefile.am b/src/MED_SWIG/Makefile.am new file mode 100644 index 000000000..949a25e60 --- /dev/null +++ b/src/MED_SWIG/Makefile.am @@ -0,0 +1,25 @@ +# MED MED_SWIG : binding of C++ implementaion with Python +# +# Copyright (C) 2003 OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +dist_sharedpkgpython_DATA= MED_shared_modules.py diff --git a/src/MED_SWIG/Makefile.in b/src/MED_SWIG/Makefile.in deleted file mode 100644 index 187f07369..000000000 --- a/src/MED_SWIG/Makefile.in +++ /dev/null @@ -1,39 +0,0 @@ -# MED MED_SWIG : binding of C++ implementaion with Python -# -# Copyright (C) 2003 OPEN CASCADE -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nicolas REJNERI -# Module : MED -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl - - -@COMMENCE@ - -EXPORT_SHAREDPYSCRIPTS=\ - MED_shared_modules.py - -@CONCLUDE@ diff --git a/src/MULTIPR/MULTIPR_API.cxx b/src/MULTIPR/MULTIPR_API.cxx new file mode 100755 index 000000000..aa8c04b01 --- /dev/null +++ b/src/MULTIPR/MULTIPR_API.cxx @@ -0,0 +1,260 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_API.cxx + * + * \brief see MULTIPR_API.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_API.hxx" +#include "MULTIPR_Globals.hxx" +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_MeshDis.hxx" +#include "MULTIPR_Utils.hxx" +#include "MULTIPR_Exceptions.hxx" + +extern "C" +{ + #include "med.h" +} + +#include "MEDSPLITTER_API.hxx" + +#include <iostream> +#include <fstream> +#include <string> + +using namespace std; + + +//***************************************************************************** +// Implementation +//***************************************************************************** + +const char* multipr::getVersion() +{ + return "2.0.1"; +} + + +void multipr::partitionneDomaine(const char* pMEDfilename, const char* pMeshName) +{ + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read the sequential mesh + //--------------------------------------------------------------------- + cout << "Read sequential MED file: " << + pMEDfilename << ": please wait... " << endl; + + multipr::Mesh mesh; + mesh.readSequentialMED(pMEDfilename, pMeshName, false); + std::vector<Group*>* lGroups = mesh.getGroups(); + cout << mesh << endl; + + //--------------------------------------------------------------------- + // Build distributed mesh from groups + //--------------------------------------------------------------------- + cout << "Build distributed mesh: please wait... " << endl; + + multipr::MeshDis* meshDis = NULL; + + try + { + GaussIndexList* lGaussList; + meshDis = mesh.splitGroupsOfElements(); + lGaussList = mesh.editGaussIndex(); + std::vector<Profil*>& lProfils = mesh.getProfils(); + //------------------------------------------------------------- + // Write distributed mesh + //------------------------------------------------------------- + cout << "Write distributed mesh: please wait... " << endl; + string strPrefix = removeExtension(pMEDfilename, ".med"); + meshDis->writeDistributedMED(strPrefix.c_str()); + meshDis->readAndWriteFields(pMeshName, lGroups, lGaussList, lProfils); + // need to delete some garb + lGaussList->clear(); + delete meshDis; + } + catch (RuntimeException& e) + { + delete meshDis; + throw e; + } +} + + +void multipr::partitionneGroupe( + const char* pMEDfilename, + const char* pGroupName, + int pNbParts, + int pPartitionner) +{ + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pGroupName == NULL) throw NullArgumentException("pGroupName should not be NULL", __FILE__, __LINE__); + if (pNbParts < 2) throw IllegalArgumentException("pNbParts should be >= 2", __FILE__, __LINE__); + if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw NullArgumentException("pPartitionner should be METIS (0) or SCOTCH (1)", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl); + + int ret = MEDformatConforme(pMEDfilename); + if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); + + multipr::MeshDis meshDis; + meshDis.readDistributedMED(pMEDfilename); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Split the given part (pGroupName) + //--------------------------------------------------------------------- + if (pPartitionner == MULTIPR_METIS) + { + cout << "Use METIS" << endl; + } + else if (pPartitionner == MULTIPR_SCOTCH) + { + cout << "Use SCOTCH" << endl; + } + + meshDis.splitPart(pGroupName, pNbParts, pPartitionner); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Write new distributed mesh + //--------------------------------------------------------------------- + string strPrefix = multipr::removeExtension(pMEDfilename, ".med"); + meshDis.writeDistributedMED(strPrefix.c_str()); +} + + +void multipr::decimePartition( + const char* pMEDfilename, + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pPartName == NULL) throw NullArgumentException("pPartName should not be NULL", __FILE__, __LINE__); + if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); + if (pFieldIt < 1) throw IllegalArgumentException("pFieldIt: invalid field iteration; should be >= 1", __FILE__, __LINE__); + /* + if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__); + if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__); + if (pRadius <= 0.0) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__); + if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__); + */ + + //cout << "--decim file=" << pMEDfilename << " part=" << pPartName << " filter=" << pFilterName << " tmed=" << pTMed << " tlow=" << pTLow << " radius=" << pRadius << endl; + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl); + + int ret = MEDformatConforme(pMEDfilename); + if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); + + multipr::MeshDis meshDis; + meshDis.readDistributedMED(pMEDfilename); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Create 3 resolutions of the given part + //--------------------------------------------------------------------- + meshDis.decimatePart( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Write new distributed mesh + //--------------------------------------------------------------------- + string strPrefix = removeExtension(pMEDfilename, ".med"); // get prefix from the original MED filename + meshDis.writeDistributedMED(strPrefix.c_str()); +} + + +int multipr::merge( + std::vector<std::string> pMEDFilenameSrc, + const char* pMeshName, + const char* pFieldName, + const char* pMEDFilenameDst) +{ + if (pMEDFilenameSrc.size() < 2) throw IllegalArgumentException("list must contain two files at least", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); + if (pMEDFilenameDst == NULL) throw NullArgumentException("pMEDFilenameDst should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read sources + //--------------------------------------------------------------------- + std::vector<multipr::Mesh*> meshes; + for (unsigned i = 0 ; i < pMEDFilenameSrc.size() ; i++) + { + multipr::Mesh* mesh = new multipr::Mesh(); + mesh->readSequentialMED(pMEDFilenameSrc[i].c_str(), 1); + + if (mesh->getNumberOfElements() != 0) + { + meshes.push_back(mesh); + } + else + { + delete mesh; + } + } + + // if no mesh (all meshes are empty) => return + if (meshes.size() == 0) return 0; + + // if only one non-empty mesh + if (meshes.size() == 1) + { + multipr::Mesh* mesh = meshes[0]; + mesh->writeMED(pMEDFilenameDst); + delete mesh; + return 1; + } + + //--------------------------------------------------------------------- + // Merge sources and write resulting mesh to disk + //--------------------------------------------------------------------- + multipr::Mesh* meshFirst = meshes.back(); + meshes.pop_back(); + multipr::Mesh* meshMerged = meshFirst->mergePartial(meshes, pFieldName, -1); + //meshMerged->setPrintAll(true); + //cout << (*meshMerged) << endl; + + meshMerged->writeMED(pMEDFilenameDst, pMeshName); + + delete meshMerged; + delete meshFirst; + for (unsigned i = 0 ; i < meshes.size(); i++) + { + delete meshes[i]; + } + return 1; +} + + +// EOF diff --git a/src/MULTIPR/MULTIPR_API.hxx b/src/MULTIPR/MULTIPR_API.hxx new file mode 100755 index 000000000..23a34341c --- /dev/null +++ b/src/MULTIPR/MULTIPR_API.hxx @@ -0,0 +1,125 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_API.hxx + * + * \brief Main header of the high level MULTIPR API. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_API_HXX +#define MULTIPR_API_HXX + +#include <vector> +#include <string> + +namespace multipr +{ + + +enum Partitionner +{ + MULTIPR_METIS = 0, + MULTIPR_SCOTCH = 1 + +}; // enum Partitionner + + +/** + * \fn const char* getVersion() + * \brief returns the current version of the MULTIPR API. + * \return the current version of the MULTIPR API. + */ +const char* getVersion(); + + +/** + * \fn void partitionneDomaine(const char* medFilename, const char* meshName) + * \brief creates a distributed MED file (v2.3) by extracting all the groups from the mesh of a sequential MED file. + * Assumes: + * - the file is in MED format and can be read using MED file v2.3. + * - the file is sequential (not a distributed MED). + * - the file only contains TETRA10 elements (dimension of space and mesh is 3). + * - the file have no profil. + * \param medFilename filename of any valid sequential MED file with TETRA10 elements only. + * \param meshName name of the mesh to be distributed. + * \throw RuntimeException if any error occurs. + */ +void partitionneDomaine( + const char* medFilename, + const char* meshName); + + +/** + * \fn void partitionneGroupe(const char* medFilename, const char* groupName, int nbParts, int partitionner) + * \brief creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * - nbPart > 1 + * \param medFilename filename of any valid distributed MED file previously created by partitionneDomaine(). + * \param partName name of the part to be splitted. + * \param nbParts number of parts; must be > 1. + * \param partitionner use value MULTIPR_METIS for Metis or MULTIPR_SCOTCH for Scotch. + * \throw RuntimeException if any error occurs. + */ + void partitionneGroupe( + const char* medFilename, + const char* partName, + int nbParts, + int partitionner=MULTIPR_METIS); + + +/** + * \fn void decimePartition(const char* medFilename, const char* partName, const char* fieldName, int fieldIt, const char* filterName, double tmed, double tlow, double radius); + * \brief creates 3 resolutions of the given part of a distributed MED file (V2.3). + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGroupe() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * \param medFilename filename of any valid distributed MED file previously created by partitionneDomaine or partitionneGroupe. + * \param partName name of the part to be decimated. + * \param fieldName name of the field used for decimation. + * \param fieldIt iteration (time step) of the field. + * \param filterName name of the filter to be used. + * \param tmed threshold used for medium resolution. + * \param tlow threshold used for low resolution; tmed must be less than tlow + * \param radius radius used to determine the neighbourhood. + * \param boxing number of cells along each axis; must be >= 1; e.g. if 100 then acceleration grid will have 100*100*100 = 10**6 cells. + * \throw RuntimeException if any error occurs. + */ +void decimePartition( + const char* medFilename, + const char* partName, + const char* fieldName, + int fieldIt, + const char* filterName, + const char* filterParams); + + +/** + * \fn void merge(...); + * \brief merge a list of sequential MED file if possible. + * \param medFilenameSrc list of source file (sequential MED files). + * \param meshName name of the mesh (all mesh must have the same name). + * \param fieldName name of the field to merge (if NULL, merge all fields). + * \param medFilenameDst destination file. + * \return 1 if a mesh has been generated, 0 otherwise (e.g. if all the sources are empty meshes). + * \throw RuntimeException if any error occurs. + */ +int merge( + std::vector<std::string> medFilenameSrc, + const char* meshName, + const char* fieldName, + const char* medFilenameDst); + + +} // namespace MULTIPR + + +#endif // MULTIPR_API_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_DecimationAccel.cxx b/src/MULTIPR/MULTIPR_DecimationAccel.cxx new file mode 100755 index 000000000..c5f825fda --- /dev/null +++ b/src/MULTIPR/MULTIPR_DecimationAccel.cxx @@ -0,0 +1,323 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_DecimationAccel.cxx + * + * \brief see MULTIPR_DecimationAccel.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_DecimationAccel.hxx" +#include "MULTIPR_PointOfField.hxx" +#include "MULTIPR_Exceptions.hxx" + +#include <cmath> +#include <iostream> + +using namespace std; + + +namespace multipr +{ + + +//***************************************************************************** +// Class DecimationAccel implementation +//***************************************************************************** + + +ostream& operator<<(ostream& pOs, DecimationAccel& pA) +{ + pOs << "DecimationAccel:" << endl; + return pOs; +} + + +//***************************************************************************** +// Class DecimationAccelGrid +//***************************************************************************** + +DecimationAccelGrid::DecimationAccelGrid() +{ + mGrid = NULL; + + reset(); +} + + +DecimationAccelGrid::~DecimationAccelGrid() +{ + reset(); +} + + +void DecimationAccelGrid::reset() +{ + mNum = 0; + + mMin[0] = numeric_limits<med_float>::quiet_NaN(); + mMin[1] = numeric_limits<med_float>::quiet_NaN(); + mMin[2] = numeric_limits<med_float>::quiet_NaN(); + + mMax[0] = numeric_limits<med_float>::quiet_NaN(); + mMax[1] = numeric_limits<med_float>::quiet_NaN(); + mMax[2] = numeric_limits<med_float>::quiet_NaN(); + + mInvLen[0] = numeric_limits<med_float>::quiet_NaN(); + mInvLen[1] = numeric_limits<med_float>::quiet_NaN(); + mInvLen[2] = numeric_limits<med_float>::quiet_NaN(); + + mSize[0] = 0; + mSize[1] = 0; + mSize[2] = 0; + + if (mGrid != NULL) + { + delete[] mGrid; + mGrid = NULL; + } + + mFlagPrintAll = false; +} + + +void DecimationAccelGrid::create(const std::vector<PointOfField>& pPts) +{ + // check if grid have been initialized + if (mSize[0] == 0) throw IllegalStateException("call setSize() before", __FILE__, __LINE__); + + // compute bbox of the grid + computeBBox(pPts); + + // allocate the grid + int size = mSize[0] * mSize[1] * mSize[2]; + mGrid = new vector<PointOfField>[size]; + + // fill the grid + mNum = pPts.size(); + for (int i = 0 ; i < mNum ; i++) + { + vector<PointOfField>& cell = getCell(pPts[i]); + cell.push_back(pPts[i]); + } +} + + +void DecimationAccelGrid::configure(const char* pArgv) +{ + // check arguments + if (pArgv == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + int sizeX = 0; + int sizeY = 0; + int sizeZ = 0; + + int ret = sscanf(pArgv, "%d %d %d", &sizeX, &sizeY, &sizeZ); + + if (ret != 3) throw IllegalArgumentException("expected 3 parameters", __FILE__, __LINE__); + if (sizeX <= 0) throw IllegalArgumentException("number of cells along X-axis must be > 0", __FILE__, __LINE__); + if (sizeY <= 0) throw IllegalArgumentException("number of cells along Y-axis must be > 0", __FILE__, __LINE__); + if (sizeZ <= 0) throw IllegalArgumentException("number of cells along Z-axis must be > 0", __FILE__, __LINE__); + + reset(); + + mSize[0] = sizeX; + mSize[1] = sizeY; + mSize[2] = sizeZ; +} + + +void DecimationAccelGrid::getCellCoord( + med_float pX, med_float pY, med_float pZ, + int* pIx, int* pIy, int* pIz) const +{ + med_float cx = (pX - mMin[0]) * mInvLen[0]; + med_float cy = (pY - mMin[1]) * mInvLen[1]; + med_float cz = (pZ - mMin[2]) * mInvLen[2]; + + // clamp all indices to avoid overflow + *pIx = med_int(cx); + if (*pIx >= mSize[0]) *pIx = mSize[0] - 1; + else if (*pIx < 0) *pIx = 0; + + *pIy = med_int(cy); + if (*pIy >= mSize[1]) *pIy = mSize[1] - 1; + else if (*pIy < 0) *pIy = 0; + + *pIz = med_int(cz); + if (*pIz >= mSize[2]) *pIz = mSize[2] - 1; + else if (*pIz < 0) *pIz = 0; +} + + +int DecimationAccelGrid::getCellIndex(int pI, int pJ, int pK) const +{ + int index = pK * (mSize[0] * mSize[1]) + pJ * mSize[0] + pI; + + return index; +} + + +vector<PointOfField>& DecimationAccelGrid::getCell(const PointOfField& pPt) +{ + int ix, iy, iz; + + getCellCoord( + pPt.mXYZ[0], pPt.mXYZ[1], pPt.mXYZ[2], + &ix, &iy, &iz); + + int index = getCellIndex(ix, iy, iz); + + return mGrid[index]; +} + + +vector<PointOfField> DecimationAccelGrid::findNeighbours( + med_float pCenterX, + med_float pCenterY, + med_float pCenterZ, + med_float pRadius) const +{ + //--------------------------------------------------------------------- + // Determine the axis aligned bounding box of the sphere ((x, y, z), r) + //--------------------------------------------------------------------- + med_float sphereBBoxMin[3]; + med_float sphereBBoxMax[3]; + + sphereBBoxMin[0] = pCenterX - pRadius; + sphereBBoxMin[1] = pCenterY - pRadius; + sphereBBoxMin[2] = pCenterZ - pRadius; + + sphereBBoxMax[0] = pCenterX + pRadius; + sphereBBoxMax[1] = pCenterY + pRadius; + sphereBBoxMax[2] = pCenterZ + pRadius; + + //--------------------------------------------------------------------- + // Determine the cells of the grid intersected by the sphere ((x, y, z), r) + // => range of cells are [iMinCell[0], iMaxCell[0]] x [iMinCell[1], iMaxCell[1]] x [iMinCell[2], iMaxCell[2]] + //--------------------------------------------------------------------- + int iMinCell[3]; + int iMaxCell[3]; + + getCellCoord(sphereBBoxMin[0], sphereBBoxMin[1], sphereBBoxMin[2], + &iMinCell[0], &iMinCell[1], &iMinCell[2]); + + getCellCoord(sphereBBoxMax[0], sphereBBoxMax[1], sphereBBoxMax[2], + &iMaxCell[0], &iMaxCell[1], &iMaxCell[2]); + + //--------------------------------------------------------------------- + // Collect points of the field which are in the sphere + //--------------------------------------------------------------------- + vector<PointOfField> res; + + if (isnan(pCenterX) || isnan(pCenterY) || isnan(pCenterZ)) + { + return res; + } + + // for all the cells in the grid intersected by the sphere ((x, y, z), r) + for (int i = iMinCell[0] ; i <= iMaxCell[0] ; i++) + { + for (int j = iMinCell[1] ; j <= iMaxCell[1] ; j++) + { + for (int k = iMinCell[2] ; k <= iMaxCell[2] ; k++) + { + int idCell = getCellIndex(i, j, k); + + vector<PointOfField>& cell = mGrid[idCell]; + + // for all the points in the current cell + for (vector<PointOfField>::const_iterator itPoint = cell.begin() ; itPoint != cell.end() ; itPoint++) + { + const PointOfField& currentPt = *itPoint; + + // test if currentPt is in the sphere ((x, y, z), r) + med_float vecX = currentPt.mXYZ[0] - pCenterX; + med_float vecY = currentPt.mXYZ[1] - pCenterY; + med_float vecZ = currentPt.mXYZ[2] - pCenterZ; + + med_float norm = med_float( sqrt( vecX*vecX + vecY*vecY + vecZ*vecZ ) ); + if (norm < pRadius) + { + // only add the point if it is different from (x, y, z) + if ((currentPt.mXYZ[0] != pCenterX) || + (currentPt.mXYZ[1] != pCenterY) || + (currentPt.mXYZ[2] != pCenterZ)) + { + res.push_back(currentPt); + } + } + } + } + } + } + + return res; +} + + +void DecimationAccelGrid::computeBBox(const std::vector<PointOfField>& pPts) +{ + for (int itDim = 0 ; itDim < 3 ; itDim++) + { + mMin[itDim] = numeric_limits<med_float>::max(); + mMax[itDim] = -mMin[itDim]; + } + + for (unsigned i = 0 ; i < pPts.size() ; i++) + { + for (int itDim = 0 ; itDim < 3 ; itDim++) + { + med_float coord = pPts[i].mXYZ[itDim]; + if (coord < mMin[itDim]) mMin[itDim] = coord; + if (coord > mMax[itDim]) mMax[itDim] = coord; + } + } + + mInvLen[0] = med_float(mSize[0]) / (mMax[0] - mMin[0]); + mInvLen[1] = med_float(mSize[1]) / (mMax[1] - mMin[1]); + mInvLen[2] = med_float(mSize[2]) / (mMax[2] - mMin[2]); +} + + +ostream& operator<<(ostream& pOs, DecimationAccelGrid& pG) +{ + pOs << "DecimationAccelGrid:" << endl; + pOs << " Num=" << pG.mNum << endl; + pOs << " Size=" << pG.mSize[0] << " x " << pG.mSize[1] << " x " << pG.mSize[2] << endl; + pOs << " BBox=[" << pG.mMin[0] << " ; " << pG.mMax[0] << "] x [" << pG.mMin[1] << " ; " << pG.mMax[1] << "] x [" << pG.mMin[2] << " ; " << pG.mMax[2] << "]" << endl; + pOs << " Inv len.=" << pG.mInvLen[0] << " ; " << pG.mInvLen[1] << " ; " << pG.mInvLen[2] << endl; + + if (pG.mFlagPrintAll) + { + int checkNumCells = 0; + int numCells = pG.mSize[0] * pG.mSize[1] * pG.mSize[2]; + for (int i = 0 ; i < numCells ; i++) + { + vector<PointOfField>& cell = pG.mGrid[i]; + cout << " Cell " << i << ": #=" << cell.size() << ": " << endl; + for (unsigned j = 0 ; j < cell.size() ; j++) + { + cout << " " << cell[j] << endl; + } + checkNumCells += cell.size(); + } + + if (pG.mNum != checkNumCells) throw IllegalStateException("", __FILE__, __LINE__); + } + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_DecimationAccel.hxx b/src/MULTIPR/MULTIPR_DecimationAccel.hxx new file mode 100755 index 000000000..d82472a0e --- /dev/null +++ b/src/MULTIPR/MULTIPR_DecimationAccel.hxx @@ -0,0 +1,258 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_DecimationAccel.hxx + * + * \brief Interface DecimationAccel: acceleration structure used for decimation. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_DECIMATION_ACCEL_HXX +#define MULTIPR_DECIMATION_ACCEL_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <iostream> +#include <vector> +#include <math.h> + +namespace multipr +{ + +//***************************************************************************** +// Predeclaration +//***************************************************************************** + +class PointOfField; + + +//***************************************************************************** +// Interface DecimationAccel +//***************************************************************************** + +class DecimationAccel +{ +public: + + /** + * Builds an empty DecimationAccel (default constructor). + */ + DecimationAccel() { /* do nothing */ } + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationAccel() { /* do nothing */ } + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Interface. Configures this acceleration structure. String is used for genericity. + * \param pArgv all the configuration parameters in a string. + */ + virtual void configure(const char* pArgv) = 0; + + /** + * Interface. Creates a new acceleration structure and fills it with the given list of points. + * \param pPts list of points to be inserted in the acceleration structure. + */ + virtual void create(const std::vector<PointOfField>& pPts) = 0; + + /** + * Interface. Finds all the points in a sphere defined by its center (x,y,z) and its radius. + * \param pCenterX x-coordinates of the center of the sphere. + * \param pCenterY y-coordinates of the center of the sphere. + * \param pCenterZ z-coordinates of the center of the sphere. + * \param pRadius radius of the sphere. + * \return all the points in a sphere defined by its center (x,y,z) and its radius. + */ + virtual std::vector<PointOfField> findNeighbours( + med_float pCenterX, + med_float pCenterY, + med_float pCenterZ, + med_float pRadius) const = 0; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any GaussLoc to the given output stream. + * \param pOs any output stream. + * \param pA any DecimationAccel. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, DecimationAccel& pA); + +protected: + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + +private: + + // do not allow copy constructor + DecimationAccel(const DecimationAccel&); + + // do not allow copy + DecimationAccel& operator=(const DecimationAccel&); + + // do not allow operator == + bool operator==(const DecimationAccel&); + +}; // class DecimationAccel + + +//***************************************************************************** +// Interface DecimationFilter and factory to build filters. +//***************************************************************************** + +class DecimationAccelGrid : public DecimationAccel +{ +public: + + /** + * Builds an empty DecimationAccelGrid (default constructor). + */ + DecimationAccelGrid(); + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationAccelGrid(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Configures this acceleration structure. String is used for genericity. + * \param pArgv assumes "size_x size_y size_z": number of cells along each axis. + */ + virtual void configure(const char* pArgv); + + /** + * Creates a new acceleration structure and fills it with the given list of points. + * setSize() must have been called before. + * \param pPts list of points to be inserted in the acceleration structure. + * \throw IllegalStateException if setSize() has not been called before. + */ + virtual void create(const std::vector<PointOfField>& pPts); + + /** + * Finds all the points in a sphere defined by its center (x,y,z) and its radius. + * \param pCenterX x-coordinates of the center of the sphere. + * \param pCenterY y-coordinates of the center of the sphere. + * \param pCenterZ z-coordinates of the center of the sphere. + * \param pRadius radius of the sphere. + * \return all the points in a sphere defined by its center (x,y,z) and its radius. + */ + virtual std::vector<PointOfField> findNeighbours( + med_float pCenterX, + med_float pCenterY, + med_float pCenterZ, + med_float pRadius) const; + + /** + * Returns the coordinates of the cell which contain the point (x,y,z). + * Clamping is performed on (pIx, pIy, pIz) to avoid out of bounds. + * \param pX (in) X-coordinates of the point. + * \param pY (in) Y-coordinates of the point. + * \param pZ (in) Z-coordinates of the point. + * \param pIx (out) X-index of the cell which contain the point (x,y,z). + * \param pIy (out) Y-index. + * \param pIz (out) Z-index. + */ + void getCellCoord( + med_float pX, med_float pY, med_float pZ, + int* pIx, int* pIy, int* pIz) const; + + /** + * Returns the index of the cell whose coordinates are (i, j, k). + * \param pI + * \param pJ + * \param pK + * \return the index of the cell (i, j, k). + */ + int getCellIndex(int pI, int pJ, int pK) const; + + /** + * Returns the list of points contained in the cell of pPt. + * \param pPt any point which coordinates are in the bbox of this acceleration structure. + * \return the list of points contained in the cell of pPt. + */ + std::vector<PointOfField>& getCell(const PointOfField& pPt); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Dumps any GaussLoc to the given output stream. + * \param pOs any output stream. + * \param pG any DecimationAccelGrid. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, DecimationAccelGrid& pG); + +private: + + /** + * Computes the axis-aligned bounding box of a set of points. + * Sets the fields mMin/mMax. + * \param pPts list of points. + */ + void computeBBox(const std::vector<PointOfField>& pPts); + +private: + + int mNum; /**< Number of points in the grid. */ + med_float mMin[3]; /**< Bounding box, min corner. */ + med_float mMax[3]; /**< Bounding box, max corner. */ + med_float mInvLen[3]; /**< 1/length of cells, along each dimension; used to accelerate getCellCoord(). */ + med_int mSize[3]; /**< Number of cells along each dimension. */ + std::vector<PointOfField>* mGrid; /**< Flatten grid structure; each cell is a vector of PointOfField. */ + +private: + + // do not allow copy constructor + DecimationAccelGrid(const DecimationAccelGrid&); + + // do not allow copy + DecimationAccelGrid& operator=(const DecimationAccelGrid&); + + // do not allow operator == + bool operator==(const DecimationAccelGrid&); + +}; // class DecimationAccelGrid + + +} // namespace MULTIPR + + +#endif // MULTIPR_DECIMATION_ACCEL_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_DecimationFilter.cxx b/src/MULTIPR/MULTIPR_DecimationFilter.cxx new file mode 100755 index 000000000..d3d1f8d25 --- /dev/null +++ b/src/MULTIPR/MULTIPR_DecimationFilter.cxx @@ -0,0 +1,523 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_DecimationFilter.cxx + * + * \brief see MULTIPR_DecimationFilter.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_DecimationFilter.hxx" +#include "MULTIPR_Field.hxx" +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_Nodes.hxx" +#include "MULTIPR_Elements.hxx" +#include "MULTIPR_Profil.hxx" +#include "MULTIPR_PointOfField.hxx" +#include "MULTIPR_DecimationAccel.hxx" +#include "MULTIPR_Exceptions.hxx" + +#include <cmath> +#include <iostream> + +using namespace std; + + +namespace multipr +{ + +//***************************************************************************** +// Class DecimationFilter implementation +//***************************************************************************** + +// Factory used to build all filters from their name. +DecimationFilter* DecimationFilter::create(const char* pFilterName) +{ + if (pFilterName == NULL) throw NullArgumentException("filter name should not be NULL", __FILE__, __LINE__); + + if (strcmp(pFilterName, "Filtre_GradientMoyen") == 0) + { + return new DecimationFilterGradAvg(); + } + else if (strcmp(pFilterName, "Filtre_Direct") == 0) + { + return new DecimationFilterTreshold(); + } + else + { + throw IllegalArgumentException("unknown filter", __FILE__, __LINE__); + } +} + + +//***************************************************************************** +// Class DecimationFilterGradAvg +//***************************************************************************** + +DecimationFilterGradAvg::DecimationFilterGradAvg() +{ + // do nothing +} + + +DecimationFilterGradAvg::~DecimationFilterGradAvg() +{ + // do nothing +} + + +Mesh* DecimationFilterGradAvg::apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) +{ + //--------------------------------------------------------------------- + // Retrieve and check parameters + //--------------------------------------------------------------------- + if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); + if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); + if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); + + char fieldName[MED_TAILLE_NOM + 1]; + int fieldIt; + int meshIt; + double threshold; + double radius; + int boxing; // number of cells along axis (if 100 then grid will have 100*100*100 = 10**6 cells) + set<med_int> elementsToKeep[eMaxMedMesh]; + Field* field = NULL; + + int ret = sscanf(pArgv, "%s %d %lf %lf %d", + fieldName, + &fieldIt, + &threshold, + &radius, + &boxing); + if (ret != 5) throw IllegalArgumentException("wrong number of arguments for filter GradAvg; expected 5 parameters", __FILE__, __LINE__); + + for (meshIt = 0; meshIt < eMaxMedMesh; ++meshIt) + { + + //--------------------------------------------------------------------- + // Retrieve field = for each point: get its coordinate and the value of the field + //--------------------------------------------------------------------- + field = pMesh->getFieldByName(fieldName, (eMeshType)meshIt); + + if (field == NULL) continue; + if ((fieldIt < 1) || (fieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); + + vector<PointOfField> points; + pMesh->getAllPointsOfField(field, fieldIt, points, (eMeshType)meshIt); + + //--------------------------------------------------------------------- + // Creates acceleration structure used to compute gradient + //--------------------------------------------------------------------- + DecimationAccel* accel = new DecimationAccelGrid(); + char strCfg[256]; // a string is used for genericity + sprintf(strCfg, "%d %d %d", boxing, boxing, boxing); + accel->configure(strCfg); + accel->create(points); + + //--------------------------------------------------------------------- + // Collects elements of the mesh to be kept + //--------------------------------------------------------------------- + int numElements = 0; + if (field->isFieldOnNodes()) + { + numElements = pMesh->getNodes()->getNumberOfNodes(); + } + else + { + numElements = pMesh->getNumberOfElements((eMeshType)meshIt); + } + if (field->getProfil(fieldIt).size() != 0) + { + Profil* profil = pMesh->getProfil(field->getProfil(fieldIt)); + if (profil == NULL) throw IllegalStateException("Can't find the profile in the mesh.", __FILE__, __LINE__); + numElements = profil->getSet().size(); + } + + int numGaussPointsByElt = 0; + if (field->isFieldOnNodes()) + { + numGaussPointsByElt = 1; + } + else + { + numGaussPointsByElt = points.size() / numElements; + } + + // for each element + for (int itElt = 0 ; itElt < numElements ; itElt++) + { + bool keepElement = false; + + // for each Gauss point of the current element + for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) + { + const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; + + vector<PointOfField> neighbours = accel->findNeighbours( + currentPt.mXYZ[0], + currentPt.mXYZ[1], + currentPt.mXYZ[2], + radius); + + // if no neighbours => keep element + if (neighbours.size() == 0) + { + keepElement = true; + break; + } + + // otherwise compute gradient... + med_float normGrad = computeNormGrad(currentPt, neighbours); + + // debug + //cout << (itElt * numGaussPointsByElt + j) << ": " << normGrad << endl; + + if ((normGrad >= threshold) || isnan(normGrad)) + { + keepElement = true; + break; + } + } + + if (keepElement) + { + // add index of the element to keep (index must start at 1) + elementsToKeep[meshIt].insert(med_int(itElt + 1)); + } + } + + //--------------------------------------------------------------------- + // Cleans + //--------------------------------------------------------------------- + delete accel; + + if (field->isFieldOnNodes()) + { + break; + } + } + + //--------------------------------------------------------------------- + // Create the final mesh by extracting elements to keep from the current mesh + //--------------------------------------------------------------------- + Mesh* newMesh = NULL; + if (field && field->isFieldOnNodes()) + { + std::set<med_int> setOfElts[eMaxMedMesh]; + + for (meshIt = 0; meshIt < eMaxMedMesh; ++meshIt) + { + if (pMesh->getElements(meshIt) != NULL) + { + pMesh->getElements(meshIt)->extractSubSetFromNodes(elementsToKeep[0], setOfElts[meshIt]); + } + } + newMesh = pMesh->createFromSetOfElements(setOfElts, pNameNewMesh); + } + else + { + newMesh = pMesh->createFromSetOfElements(elementsToKeep, pNameNewMesh); + } + + return newMesh; +} + + +void DecimationFilterGradAvg::getGradientInfo( + Mesh* pMesh, + const char* pFieldName, + int pFieldIt, + double pRadius, + int pBoxing, + double* pOutGradMin, + double* pOutGradAvg, + double* pOutGradMax) +{ + if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); + if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); + + for (int meshIt = 0; meshIt < eMaxMedMesh; ++meshIt) + { + + //--------------------------------------------------------------------- + // Retrieve field = for each point: get its coordinate and the value of the field + //--------------------------------------------------------------------- + Field* field = pMesh->getFieldByName(pFieldName, (eMeshType)meshIt); + + if (field == NULL) continue; + if ((pFieldIt < 1) || (pFieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); + + vector<PointOfField> points; + pMesh->getAllPointsOfField(field, pFieldIt, points, (eMeshType)meshIt); + + //--------------------------------------------------------------------- + // Creates acceleration structure used to compute gradient + //--------------------------------------------------------------------- + DecimationAccel* accel = new DecimationAccelGrid(); + char strCfg[256]; // a string is used for genericity + sprintf(strCfg, "%d %d %d", pBoxing, pBoxing, pBoxing); + accel->configure(strCfg); + accel->create(points); + + //--------------------------------------------------------------------- + // Collects elements of the mesh to be kept + //--------------------------------------------------------------------- + int numElements = 0; + if (field->isFieldOnNodes()) + { + numElements = pMesh->getNodes()->getNumberOfNodes(); + } + else + { + numElements = pMesh->getNumberOfElements((eMeshType)meshIt); + } + if (field->getProfil(pFieldIt).size() != 0) + { + Profil* profil = pMesh->getProfil(field->getProfil(pFieldIt)); + if (profil == NULL) throw IllegalStateException("Can't find the profile in the mesh.", __FILE__, __LINE__); + numElements = profil->getSet().size(); + } + + int numGaussPointsByElt = 0; + if (field->isFieldOnNodes()) + { + numGaussPointsByElt = 1; + } + else + { + numGaussPointsByElt = points.size() / numElements; + } + + *pOutGradMax = -1e300; + *pOutGradMin = 1e300; + *pOutGradAvg = 0.0; + int count = 0; + + // for each element + for (int itElt = 0 ; itElt < numElements ; itElt++) + { + // for each Gauss point of the current element + for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) + { + const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; + + vector<PointOfField> neighbours = accel->findNeighbours( + currentPt.mXYZ[0], + currentPt.mXYZ[1], + currentPt.mXYZ[2], + pRadius); + + // if no neighbours => keep element + if (neighbours.size() == 0) + { + continue; + } + + // otherwise compute gradient... + med_float normGrad = computeNormGrad(currentPt, neighbours); + + // debug + //cout << (itElt * numGaussPointsByElt + j) << ": " << normGrad << endl; + + if (!isnan(normGrad)) + { + if (normGrad > *pOutGradMax) *pOutGradMax = normGrad; + if (normGrad < *pOutGradMin) *pOutGradMin = normGrad; + *pOutGradAvg += normGrad; + count++; + } + } + } + + if (count != 0) *pOutGradAvg /= double(count); + + //--------------------------------------------------------------------- + // Cleans + //--------------------------------------------------------------------- + delete accel; + if (field->isFieldOnNodes()) + { + break; + } + } +} + + +med_float DecimationFilterGradAvg::computeNormGrad(const PointOfField& pPt, const std::vector<PointOfField>& pNeighbours) const +{ + med_float gradX = 0.0; + med_float gradY = 0.0; + med_float gradZ = 0.0; + + // for each neighbour + for (unsigned i = 0 ; i < pNeighbours.size() ; i++) + { + const PointOfField& neighbourPt = pNeighbours[i]; + + med_float vecX = neighbourPt.mXYZ[0] - pPt.mXYZ[0]; + med_float vecY = neighbourPt.mXYZ[1] - pPt.mXYZ[1]; + med_float vecZ = neighbourPt.mXYZ[2] - pPt.mXYZ[2]; + + med_float norm = med_float( sqrt( vecX*vecX + vecY*vecY + vecZ*vecZ ) ); + med_float val = neighbourPt.mVal - pPt.mVal; + + val /= norm; + + gradX += vecX * val; + gradY += vecY * val; + gradZ += vecZ * val; + } + + med_float invSize = 1.0 / med_float(pNeighbours.size()); + + gradX *= invSize; + gradY *= invSize; + gradZ *= invSize; + + med_float norm = med_float( sqrt( gradX*gradX + gradY*gradY + gradZ*gradZ ) ); + + return norm; + +} + +//***************************************************************************** +// Class DecimationFilterGradAvg +//***************************************************************************** + +DecimationFilterTreshold::DecimationFilterTreshold() +{ + // do nothing +} + + +DecimationFilterTreshold::~DecimationFilterTreshold() +{ + // do nothing +} + + +Mesh* DecimationFilterTreshold::apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) +{ + if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); + if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); + if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); + + char fieldName[MED_TAILLE_NOM + 1]; + int fieldIt; + double threshold; + int meshIt; + set<med_int> elementsToKeep[eMaxMedMesh]; + Field* field = NULL; + + int ret = sscanf(pArgv, "%s %d %lf", + fieldName, + &fieldIt, + &threshold); + + if (ret != 3) throw IllegalArgumentException("wrong number of arguments for filter Treshold; expected 3 parameters", __FILE__, __LINE__); + + for (meshIt = 0; meshIt < eMaxMedMesh; ++meshIt) + { + //--------------------------------------------------------------------- + // Retrieve field = for each point: get its coordinate and the value of the field + //--------------------------------------------------------------------- + field = pMesh->getFieldByName(fieldName, (eMeshType)meshIt); + if (field == NULL) continue; + if ((fieldIt < 1) || (fieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); + + vector<PointOfField> points; + pMesh->getAllPointsOfField(field, fieldIt, points, (eMeshType)meshIt); + + //--------------------------------------------------------------------- + // Collects elements of the mesh to be kept + //--------------------------------------------------------------------- + int numElements = 0; + if (field->isFieldOnNodes()) + { + numElements = pMesh->getNodes()->getNumberOfNodes(); + } + else + { + numElements = pMesh->getNumberOfElements((eMeshType)meshIt); + } + if (field->getProfil(fieldIt).size() != 0) + { + Profil* profil = pMesh->getProfil(field->getProfil(fieldIt)); + if (profil == NULL) throw IllegalStateException("Can't find the profile in the mesh.", __FILE__, __LINE__); + numElements = profil->getSet().size(); + } + + int numGaussPointsByElt = 0; + if (field->isFieldOnNodes()) + { + numGaussPointsByElt = 1; + } + else + { + numGaussPointsByElt = points.size() / numElements; + } + // for each element + for (int itElt = 0 ; itElt < numElements ; itElt++) + { + bool keepElement = false; + + // for each Gauss point of the current element + for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) + { + const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; + + if (currentPt.mVal > threshold) + { + keepElement = true; + break; + } + } + + if (keepElement) + { + // add index of the element to keep (index must start at 1) + elementsToKeep[meshIt].insert(med_int(itElt + 1)); + } + } + if (field->isFieldOnNodes()) + { + break; + } + } + //--------------------------------------------------------------------- + // Create the final mesh by extracting elements to keep from the current mesh + //--------------------------------------------------------------------- + Mesh* newMesh = NULL; + if (field && field->isFieldOnNodes()) + { + std::set<med_int> setOfElts[eMaxMedMesh]; + + for (meshIt = 0; meshIt < eMaxMedMesh; ++meshIt) + { + if (pMesh->getElements(meshIt) != NULL) + { + pMesh->getElements(meshIt)->extractSubSetFromNodes(elementsToKeep[0], setOfElts[meshIt]); + } + } + newMesh = pMesh->createFromSetOfElements(setOfElts, pNameNewMesh); + } + else + { + newMesh = pMesh->createFromSetOfElements(elementsToKeep, pNameNewMesh); + } + + return newMesh; +} + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_DecimationFilter.hxx b/src/MULTIPR/MULTIPR_DecimationFilter.hxx new file mode 100755 index 000000000..31281b886 --- /dev/null +++ b/src/MULTIPR/MULTIPR_DecimationFilter.hxx @@ -0,0 +1,213 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_DecimationFilter.hxx + * + * \brief Interface DecimationFilter: filter used for decimation. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_DECIMATION_FILTER_HXX +#define MULTIPR_DECIMATION_FILTER_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <iostream> +#include <vector> + + +namespace multipr +{ + +//***************************************************************************** +// Predeclaration +//***************************************************************************** + +class Mesh; +class PointOfField; + + +//***************************************************************************** +// Interface DecimationFilter and factory to build filters. +// Should be derivated to implement new filter. +//***************************************************************************** + +class DecimationFilter +{ +public: + /** + * Decimation filter factory. Must be used to build any new filter from its name. + * \param pFilterName name of the filter to be instanciated. + * \return a new instance of the given filter. + */ + static DecimationFilter* create(const char* pFilterName); + +public: + + /** + * Builds an empty DecimationFilter (default constructor). + */ + DecimationFilter() { /* do nothing */ } + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationFilter() { /* do nothing */ } + + /** + * Interface. Creates a new Mesh by decimating the given Mesh with this DecimationFilter. + * \param pMesh any mesh to be decimated; must not be NULL. + * \param pArgv all the arguments of the filter as a string; must not be NULL. + * \param pNameNewMesh name of the decimated mesh; must not be NULL. + * \return the decimated mesh. + */ + virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) = 0; + +private: + + // do not allow copy constructor + DecimationFilter(const DecimationFilter&); + + // do not allow copy + DecimationFilter& operator=(const DecimationFilter&); + + // do not allow operator == + bool operator==(const DecimationFilter&); + +}; // class DecimationFilter + + +//***************************************************************************** +// Filter : Average Gradient +//***************************************************************************** + +class DecimationFilterGradAvg : public DecimationFilter +{ +public: + + /** + * Builds an empty DecimationFilterGradAvg (default constructor). + */ + DecimationFilterGradAvg(); + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationFilterGradAvg(); + + /** + * Creates a new Mesh by decimating the given Mesh with this DecimationFilter. + * + * For each element + * Keep this element if all its points (related to a field) have a |gradient| > threshold. + * + * For each point, gradient is computed by considering all the neighbours in a sphere of radius r. + * + * \param pMesh any mesh to be decimated; must not be NULL. + * \param pArgv all the arguments of the filter as a string; must not be NULL. + * for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters). + * \param pNameNewMesh name of the decimated mesh; must not be NULL. + * \return the decimated mesh. + */ + virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh); + + /** + * Returns information about gradient. + */ + void getGradientInfo( + Mesh* pMesh, + const char* pFieldName, + int pFieldIt, + double pRadius, + int pBoxing, + double* pOutGradMin, + double* pOutGradAvg, + double* pOutGradMax); + +private: + + /** + * Returns the norm of the gradient of the field at the given point. + * Sub-method used by apply(). + * \param pPt any point in the field. + * \param pNeigbours neighbourhood of pPt. + * \return the norm of the gradient of the field in pPt. + */ + med_float computeNormGrad(const PointOfField& pPt, const std::vector<PointOfField>& pNeighbours) const; + +private: + + // do not allow copy constructor + DecimationFilterGradAvg(const DecimationFilterGradAvg&); + + // do not allow copy + DecimationFilterGradAvg& operator=(const DecimationFilterGradAvg&); + + // do not allow operator == + bool operator==(const DecimationFilterGradAvg&); + +}; // class DecimationFilterGradAvg + +//***************************************************************************** +// Filter : Treshold +//***************************************************************************** + +class DecimationFilterTreshold : public DecimationFilter +{ +public: + + /** + * Builds an empty DecimationFilterTreshold (default constructor). + */ + DecimationFilterTreshold(); + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationFilterTreshold(); + + /** + * Creates a new Mesh by decimating the given Mesh with this DecimationFilter. + * + * For each element + * Keep this element if all its points (related to a field) have a value > threshold. + * + * \param pMesh any mesh to be decimated; must not be NULL. + * \param pArgv all the arguments of the filter as a string; must not be NULL. + * for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters). + * \param pNameNewMesh name of the decimated mesh; must not be NULL. + * \return the decimated mesh. + */ + virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh); + + +private: + + // do not allow copy constructor + DecimationFilterTreshold(const DecimationFilterTreshold&); + + // do not allow copy + DecimationFilterTreshold& operator=(const DecimationFilterTreshold&); + + // do not allow operator == + bool operator==(const DecimationFilterTreshold&); + +}; // class DecimationFilterTreshold + +} // namespace MULTIPR + + +#endif // MULTIPR_DECIMATION_FILTER_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Elements.cxx b/src/MULTIPR/MULTIPR_Elements.cxx new file mode 100755 index 000000000..ab223f278 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Elements.cxx @@ -0,0 +1,634 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Elements.cxx + * + * \brief see MULTIPR_Elements.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Elements.hxx" +#include "MULTIPR_Nodes.hxx" +#include "MULTIPR_Exceptions.hxx" + +#include <iostream> +#include <set> +#include <map> + +using namespace std; + + +namespace multipr +{ + + +//***************************************************************************** +// Class Elements implementation +//***************************************************************************** + +Elements::Elements() +{ + mId = NULL; + mFamIdent = NULL; + mNames = NULL; + mCon = NULL; + mFlagPrintAll = false; + reset(); +} + +Elements::Elements(med_geometrie_element pGeomType) +{ + mId = NULL; + mFamIdent = NULL; + mNames = NULL; + mCon = NULL; + mNum = 0; + mGeom = pGeomType; + mNumNodesByElt = mGeom % 100; + mDim = mGeom / 100; + mEntity = MED_MAILLE; + mFlagPrintAll = false; +} + +Elements::~Elements() +{ + reset(); +} + + +void Elements::reset() +{ + mNum = 0; + mEntity = MED_MAILLE; + mGeom = MED_NONE; + mNumNodesByElt = 0; + mDim = 0; + + if (mId != NULL) { delete[] mId; mId = NULL; } + if (mFamIdent != NULL) { delete[] mFamIdent; mFamIdent = NULL; } + if (mNames != NULL) { delete[] mNames; mNames = NULL; } + if (mCon != NULL) { delete[] mCon; mCon = NULL; } + + mSetOfNodes.clear(); + + mFlagPrintAll = false; +} + + +med_int Elements::getFamilyIdentifier(med_int pIndex) const +{ + if ((pIndex < 0) || (pIndex >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mFamIdent[pIndex]; +} + + +const med_int* Elements::getConnectivity(int pIndex) const +{ + if ((pIndex < 0) || (pIndex >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mCon + mNumNodesByElt * pIndex; +} + + +void Elements::getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst) const +{ + if ((pIndexElt < 0) || (pIndexElt >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + if (pNodes == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pCoo == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + // get the list of nodes of the element + const med_int* con = getConnectivity(pIndexElt); + + med_float* destCoo = pCoo; + int size = sizeof(med_float) * mDim; + + // for each node of the element + int n = (mNumNodesByElt < pFirst) ? mNumNodesByElt : pFirst; + for (int i = 0 ; i < n ; i++) + { + // get index of node (MED index start at 1) + med_int indexNode = con[i] - 1; + + // get coordinates of this node + const med_float* srcCoo = pNodes->getCoordinates(indexNode); + + // copy coordinates to destCoo + memcpy(destCoo, srcCoo, size); + + // prepare next point + destCoo += mDim; + } +} + + +Elements* Elements::extractSubSet(const set<med_int>& pSetIndices) const +{ + Elements* subset = new Elements(); + + //--------------------------------------------------------------------- + // Copy parameters + //--------------------------------------------------------------------- + subset->mNum = pSetIndices.size(); + subset->mEntity = mEntity; + subset->mGeom = mGeom; // e.g. 310 for a TETRA10 + subset->mNumNodesByElt = mNumNodesByElt; // e.g. 10 for a TETRA10 + subset->mDim = mDim; // e.g. 3 for a TETRA10 + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + subset->mFamIdent = new med_int[subset->mNum]; + subset->mCon = new med_int[mNumNodesByElt * subset->mNum]; + + //--------------------------------------------------------------------- + // Copy subset of familys id and connectivity. + //--------------------------------------------------------------------- + med_int* destCon = subset->mCon; + set<med_int>::iterator itSet = pSetIndices.begin(); + for (int itElt = 0 ; itElt < subset->mNum && itSet != pSetIndices.end(); itElt++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mFamIdent[itElt] = mFamIdent[srcIndex]; + + med_int* srcCon = mCon + srcIndex * mNumNodesByElt; + memcpy(destCon, srcCon, sizeof(med_int) * mNumNodesByElt); + + destCon += mNumNodesByElt; + itSet++; + } + //--------------------------------------------------------------------- + // Copy subset of identifiers if necessary + //--------------------------------------------------------------------- + if (isIdentifiers()) + { + itSet = pSetIndices.begin(); + subset->mId = new med_int[subset->mNum]; + for (int itElt = 0 ; itElt < subset->mNum && itSet != pSetIndices.end(); itElt++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mId[itElt] = mId[srcIndex]; + + itSet++; + } + } + + //--------------------------------------------------------------------- + // Copy subset of names if necessary + //--------------------------------------------------------------------- + if (isNames()) + { + itSet = pSetIndices.begin(); + subset->mNames = new char[MED_TAILLE_PNOM * subset->mNum + 1]; + char* destPtr = subset->mNames; + for (int itElt = 0 ; itElt < subset->mNum && itSet != pSetIndices.end(); itElt++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + char* srcPtr = mNames + srcIndex * MED_TAILLE_PNOM; + memcpy(destPtr, srcPtr, MED_TAILLE_PNOM); + + destPtr += MED_TAILLE_PNOM; + itSet++; + } + subset->mNames[MED_TAILLE_PNOM * subset->mNum] = '\0'; + } + + return subset; +} + +void Elements::extractSubSetFromNodes(const std::set<med_int>& pSetOfNodes, + std::set<med_int>& pSubSetOfElements) const +{ + if (&pSetOfNodes == &pSubSetOfElements) throw IllegalStateException("pSetOfNodes and pSubSetOfElements must be different !", __FILE__, __LINE__); + + int numOfNodes = pSetOfNodes.size(); + bool keepElt = false; + for (int itElt = 0; itElt < mNum; ++itElt) + { + keepElt = false; + for (std::set<med_int>::iterator itNode = pSetOfNodes.begin(); + itNode != pSetOfNodes.end() && keepElt == false; ++itNode) + { + for (int itCon = 0; itCon < mNumNodesByElt && keepElt == false; ++itCon) + { + if ((*itNode) == mCon[itElt * mNumNodesByElt + itCon]) + { + keepElt = true; + } + } + } + if (keepElt) + { + pSubSetOfElements.insert(itElt + 1); + } + } +} + +const set<med_int>& Elements::getSetOfNodes() +{ + // lazy get: test if mSetOfNodes has already been built + if (mSetOfNodes.size() == 0) + { + buildSetOfNodes(); + } + + return mSetOfNodes; +} + + +set<med_int> Elements::getSetOfFamilies() const +{ + // set of families is empty at the beginning + set<med_int> setOfFamilies; + + // for each element, add its family to the set + for (int itElt = 0 ; itElt < mNum ; itElt++) + { + setOfFamilies.insert(mFamIdent[itElt]); + } + + return setOfFamilies; +} + + +void Elements::remap() +{ + int itNode, size; + // build set of nodes if necessary + if (mSetOfNodes.size() == 0) + { + buildSetOfNodes(); + } + + // build the map for indices convertion + map<med_int, med_int> mapOldIndexToNewIndex; + med_int newIndex = 1; // MED index start at 1 + for (set<med_int>::iterator itSet = mSetOfNodes.begin(); itSet != mSetOfNodes.end() ; itSet++) + { + med_int oldIndex = (*itSet); + mapOldIndexToNewIndex.insert(make_pair(oldIndex, newIndex)); + newIndex++; + } + + // for each node referenced by this set of elements + for (itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) + { + // convert old index to new index (remap) + mCon[itNode] = mapOldIndexToNewIndex[mCon[itNode]]; + } + + buildSetOfNodes(); +} + +void Elements::remap(std::set<med_int>& pSetOfNodes) +{ + int itNode, size; + + // build the map for indices convertion + map<med_int, med_int> mapOldIndexToNewIndex; + med_int newIndex = 1; // MED index start at 1 + itNode = 1; + for (std::set<med_int>::iterator it = pSetOfNodes.begin(); it != pSetOfNodes.end(); ++it) + { + med_int oldIndex = *it; + mapOldIndexToNewIndex.insert(make_pair(oldIndex, itNode)); + ++itNode; + } + // for each node referenced by this set of elements + for (itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) + { + // convert old index to new index (remap). + mCon[itNode] = mapOldIndexToNewIndex[mCon[itNode]];; + } + buildSetOfNodes(); + +} + +Elements* Elements::mergePartial(Elements* pElements, int pOffset) +{ + Elements* elements = new Elements(); + + //--------------------------------------------------------------------- + // Copy parameters + //--------------------------------------------------------------------- + elements->mNum = mNum + pElements->mNum; + + if (mEntity != pElements->mEntity) throw IllegalStateException("entity should be the same", __FILE__, __LINE__); + elements->mEntity = mEntity; + + elements->mGeom = mGeom; // e.g. 310 for a TETRA10 + elements->mNumNodesByElt = mNumNodesByElt; // e.g. 10 for a TETRA10 + if (mDim != pElements->mDim) throw IllegalStateException("dimension should be the same", __FILE__, __LINE__); + elements->mDim = mDim; // e.g. 3 for a TETRA10 + + elements->mId = NULL; + elements->mNames = NULL; + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + elements->mFamIdent = new med_int[elements->mNum]; + elements->mCon = new med_int[mNumNodesByElt * elements->mNum]; + + //--------------------------------------------------------------------- + // Copy familys id and connectivity. + //--------------------------------------------------------------------- + memcpy(elements->mFamIdent, mFamIdent, mNum * sizeof(med_int)); + memcpy(elements->mFamIdent + mNum, pElements->mFamIdent, pElements->mNum * sizeof(med_int)); + + memcpy(elements->mCon, mCon, mNum * mNumNodesByElt * sizeof(med_int)); + + med_int* dst = elements->mCon + mNum * mNumNodesByElt; + for (int i = 0, n = pElements->mNum * mNumNodesByElt ; i < n ; i++) + { + dst[i] = pElements->mCon[i] + pOffset; + } + + //cout << "WARNING: do no build set of nodes" << endl; + //elements->buildSetOfNodes(); + + return elements; +} + + +Elements* Elements::mergePartial(vector<Elements*> pElements, vector<int>& pOffsets) +{ + if (pElements.size() == 0) throw IllegalArgumentException("pElements should contain at least 1 element", __FILE__, __LINE__); + + Elements* elements = new Elements(); + + //--------------------------------------------------------------------- + // Copy parameters + //--------------------------------------------------------------------- + elements->mNum = mNum; + for (unsigned i = 0 ; i < pElements.size() ; i++) + { + elements->mNum += pElements[i]->mNum; + + if (mEntity != pElements[i]->mEntity) throw IllegalStateException("entity should be the same", __FILE__, __LINE__); + if (mDim != pElements[i]->mDim) throw IllegalStateException("dimension should be the same", __FILE__, __LINE__); + } + + elements->mEntity = mEntity; + elements->mGeom = mGeom; // e.g. 310 for a TETRA10 + elements->mNumNodesByElt = mNumNodesByElt; // e.g. 10 for a TETRA10 + elements->mDim = mDim; // e.g. 3 for a TETRA10 + + elements->mId = NULL; + elements->mNames = NULL; + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + elements->mFamIdent = new med_int[elements->mNum]; + elements->mCon = new med_int[mNumNodesByElt * elements->mNum]; + + //--------------------------------------------------------------------- + // Copy familys id and connectivity. + //--------------------------------------------------------------------- + memcpy(elements->mFamIdent, mFamIdent, mNum * sizeof(med_int)); + memcpy(elements->mCon, mCon, mNum * mNumNodesByElt * sizeof(med_int)); + + int offsetFamIdent = mNum; + int offsetCon = mNum; + for (unsigned j = 0 ; j < pElements.size() ; j++) + { + memcpy(elements->mFamIdent + offsetFamIdent, pElements[j]->mFamIdent, pElements[j]->mNum * sizeof(med_int)); offsetFamIdent += pElements[j]->mNum; + + med_int* dst = elements->mCon + offsetCon * mNumNodesByElt; + for (int i = 0, n = pElements[j]->mNum * mNumNodesByElt ; i < n ; i++) + { + dst[i] = pElements[j]->mCon[i] + pOffsets[j]; + } + offsetCon += pElements[j]->mNum; + } + + //cout << "WARNING: do no build set of nodes" << endl; + //elements->buildSetOfNodes(); + + return elements; +} + + +void Elements::buildSetOfNodes() +{ + if (mSetOfNodes.size() != 0) + { + mSetOfNodes.clear(); + } + + // for each node referenced by this set of elements + for (int itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) + { + // add the node to the set + mSetOfNodes.insert(mCon[itNode]); + } +} + + +void Elements::readMED( + med_idt pMEDfile, + char* pMeshName, + med_int pMeshDim, + med_entite_maillage pEntity, + med_geometrie_element pGeom) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if ((pMeshDim < 1) || (pMeshDim > 3)) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + mEntity = pEntity; + mGeom = pGeom; + mNumNodesByElt = mGeom % 100; + mDim = mGeom / 100; + + mNum = MEDnEntMaa( + pMEDfile, + pMeshName, + MED_CONN, // type of information requested = CONNECTIVITY + pEntity, + pGeom, + MED_NOD); // nodal connectivity + + if (mNum < 0) throw IOException("i/o error while reading information about elements in MED file", __FILE__, __LINE__); + + if (mNum == 0) + { + // empty mesh + return; + } + + mCon = new med_int[mNumNodesByElt * mNum]; + mNames = new char[MED_TAILLE_PNOM * mNum + 1]; + mId = new med_int[mNum]; + mFamIdent = new med_int[mNum]; + med_booleen isNames; + med_booleen isIdentifiers; + + med_err ret = MEDelementsLire( + pMEDfile, + pMeshName, + pMeshDim, + mCon, + MED_FULL_INTERLACE, + mNames, + &isNames, + mId, + &isIdentifiers, + mFamIdent, + mNum, + mEntity, + mGeom, + MED_NOD); // NODAL CONNECTIVITY + + if (ret != 0) throw IOException("i/o error while reading elements in MED file", __FILE__, __LINE__); + + if (!isNames) + { + delete[] mNames; + mNames = NULL; + } + + if (!isIdentifiers) + { + delete[] mId; + mId = NULL; + } +} + + +void Elements::writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((pMeshDim < 1) || (pMeshDim > 3)) throw IllegalArgumentException("", __FILE__, __LINE__); + + // special case: if no elements => do nothing + if (mNum == 0) return; + + med_err ret = MEDelementsEcr( + pMEDfile, + pMeshName, + pMeshDim, + mCon, + MED_FULL_INTERLACE, + mNames, + isNames()?MED_VRAI:MED_FAUX, + mId, + isIdentifiers()?MED_VRAI:MED_FAUX, + mFamIdent, + mNum, + mEntity, + mGeom, + MED_NOD); // NODAL CONNECTIVITY + + if (ret != 0) throw IOException("i/o error while writing elements in MED file", __FILE__, __LINE__); +} + + +ostream& operator<<(ostream& pOs, Elements& pE) +{ + char strEntity[16]; + switch (pE.mEntity) + { + case MED_MAILLE: strcpy(strEntity, "MED_MAILLE"); break; + case MED_FACE: strcpy(strEntity, "MED_FACE"); break; + case MED_ARETE: strcpy(strEntity, "MED_ARETE"); break; + case MED_NOEUD: strcpy(strEntity, "MED_NOEUD"); break; + default: strcpy(strEntity, "UNKNOWN"); break; + } + + pOs << "Elements: " << endl; + pOs << " #number =" << pE.mNum << endl; + pOs << " Entity =" << strEntity << endl; + pOs << " Geom =" << pE.mGeom << endl; + pOs << " Has names?" << (pE.isNames()?"yes":"no") << endl; + pOs << " Has id ?" << (pE.isIdentifiers()?"yes":"no") << endl; + + { + set<med_int> setOfFam = pE.getSetOfFamilies(); + if (setOfFam.size() == 0) + { + pOs << " Families: #fam=0" << endl; + } + else + { + set<med_int>::iterator itFam = setOfFam.end(); + itFam--; + pOs << " Families: #fam=" << setOfFam.size() << " id_min=" << (*(setOfFam.begin())) << " id_max=" << (*itFam) << endl; + + if (pE.mFlagPrintAll) + { + for (int i = 0 ; i < pE.mNum; i++) + { + pOs << " Elt " << (i + 1) << ": " << pE.mFamIdent[i] << endl; + } + } + } + } + + { + set<med_int> setOfNodes = pE.getSetOfNodes(); + if (setOfNodes.size() == 0) + { + pOs << " Connectivity: #nodes=0" << endl; + } + else + { + set<med_int>::iterator itNode = setOfNodes.end(); + itNode--; + pOs << " Connectivity: #nodes=" << setOfNodes.size() << " id_min=" << (*(setOfNodes.begin())) << " id_max=" << (*itNode) << endl; + + if (pE.mFlagPrintAll) + { + for (int i = 0 ; i < pE.mNum ; i++) + { + pOs << " Elt " << (i + 1) << ": "; + for (int j = 0 ; j < pE.mNumNodesByElt ; j++) + { + pOs << pE.mCon[i * pE.mNumNodesByElt + j] << " "; + } + pOs << endl; + } + } + } + } + + if (pE.mFlagPrintAll) + { + + if (pE.isIdentifiers()) + { + pOs << " Num (identifier): " << endl; + for (int i = 0 ; i < pE.mNum; i++) + { + pOs << " Elt " << (i + 1) << ": " << pE.mId[i] << " " << endl; + } + } + + if (pE.isNames()) + { + pE.mNames[MED_TAILLE_PNOM * pE.mNum] = '\0'; + pOs << " Names: |" << pE.mNames << "|" << endl; + } + + } + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Elements.hxx b/src/MULTIPR/MULTIPR_Elements.hxx new file mode 100755 index 000000000..ecd4248fc --- /dev/null +++ b/src/MULTIPR/MULTIPR_Elements.hxx @@ -0,0 +1,285 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Elements.hxx + * + * \brief Class Elements = table of elements in a mesh. + * All elements share the same type (e.g. MED_MAILLE) and the same geometric description (e.g. TETRA10). + * Each element has a family and a table of connectivity. + * Optional: each element has a name and an id. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_ELEMENTS_HXX +#define MULTIPR_ELEMENTS_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <set> +#include <vector> + + +namespace multipr +{ + +//***************************************************************************** +// Predeclaration +//***************************************************************************** + +class Nodes; + + +//***************************************************************************** +// Class Elements +//***************************************************************************** + +class Elements +{ +public: + + /** + * Builds an empty set of elements (default constructor). + */ + Elements(); + + /** + * Builds an empty set of elements with of the defined geometry type. + * \param pGeomType The geometry type. + */ + Elements(med_geometrie_element pGeomType); + + + /** + * Destructor. Removes everything. + */ + ~Elements(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true iff this object contains no elements (table of elements is empty). + * \return true iff this object contains no elements. + */ + bool isEmpty() const { return (mNum == 0); } + + /** + * Returns true iff elements have a name. + * \return true iff elements have a name. + */ + bool isNames() const { return (mNames != NULL); } + + /** + * Returns true iff elements have an identifier (= a number). + * \return true iff elements have an identifier (= a number). + */ + bool isIdentifiers() const { return (mId != NULL); } + + /** + * Returns the number of elements. + * \return the number of elements. + */ + int getNumberOfElements() const { return mNum; } + + /** + * Returns the type of primitives (e.g. MED_TETRA10). + * \return the type of primitives + */ + med_geometrie_element getTypeOfPrimitives() const { return mGeom; } + + /** + * Returns the number of nodes that composed an element. + * \return the number of nodes that composed an element. + */ + int getNumberOfNodesByElement() const { return mNumNodesByElt; } + + /** + * Returns the family associated with an element. + * \param pIndex index of any element in [0..NUMBER_OF_ELEMENTS-1]. + * \return the family associated with an element. + * \throw IndexOutOfBoundsException if pIndex is invalid. + */ + med_int getFamilyIdentifier(med_int pIndex) const; + + /** + * Returns the connectivity of one element. + * \param pIndex must be in [0..NUMBER_OF_ELEMENTS-1]. + * \return a pointer towards the table of connectivity of the element. + * \throw IndexOutOfBoundsException if pIndex is invalid. + */ + const med_int* getConnectivity(int pIndex) const; + + /** + * Returns the coordinates of all the nodes of one element. + * \param pIndexElt must be in [0..NUMBER_OF_ELEMENTS-1]. + * \param pNodes table of nodes, used to retrieve coordinates. + * \param pCoo (out) table of coordinates of nodes (e.g. 30 = 3 * 10 med_float for a TETRA10). + * \param pFirst only get the pFirst coordinates. + * \throw IndexOutOfBoundsException if pIndex is invalid. + */ + void getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst = 100) const; + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Constructor. Creates a subset of this set of elements from a set of indices. + * \param pSetIndices set of indices (start at 1). + * \return a restriction of this set of elements. + */ + Elements* extractSubSet(const std::set<med_int>& pSetIndices) const; + + /** + * Create a subset of elements containing the given nodes. + * \param pSetOfNodes The set of nodes. + * \param pSubSetOfElements The subset of elements to fill. + * \throw IllegalStateException if pSetOfNodes and pSubSetOfElements are not different. + */ + void extractSubSetFromNodes(const std::set<med_int>& pSetOfNodes, std::set<med_int>& pSubSetOfElements) const; + + /** + * Returns the set of indices (starting at 1) of all nodes used by this set of elements. + * \return the set of indices of all nodes used by this set of elements. + */ + const std::set<med_int>& getSetOfNodes(); + + /** + * Returns the set of families referenced by this set of elements. + * Each family is described by its identifier. + * \return Returns the set of families referenced by this set of elements. + */ + std::set<med_int> getSetOfFamilies() const; + + /** + * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... * + * This method is intended to be used after extractSubSet(). + */ + void remap(void); + + + /** + * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... * + * This method is intended to be used after extractSubSet(). + * This remap method allows to use the same set of nodes with several mesh type. + * \param pSetOfNodes The set of nodes index extracted from the original med file. + */ + void remap(std::set<med_int>& pSetOfNodes); + + + /** + * Builds a new set of elements by merging two set of elements (this and pElements) if possible. + * Merge is partial because Id and Names are not take into account. + * \param pElements any set of nodes to be merged with this. + * \param pOffset + * \return a new set of nodes. + * \throw IllegalStateException if the two sets of elements are incompatible. + */ + Elements* mergePartial(Elements* pElements, int pOffset); + Elements* mergePartial(std::vector<Elements*> pElements, std::vector<int>& pOffsets); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a set of elements from a MED file. + * You must give: name of mesh, dimension of the mesh, type of entity and type of elements. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName name of the mesh. + * \param pMeshDim dimension of the mesh. + * \param pEntity entity to be read (e.g. MED_MAILLE). + * \param pGeom type of primitves to be read (e.g. MED_TETRA10). + * \throw IOException if any i/o error occurs. + */ + void readMED( + med_idt pMEDfile, + char* pMeshName, + med_int pMeshDim, + med_entite_maillage pEntity, + med_geometrie_element pGeom); + + /** + * Writes this set of elements to a MED file. + * WARNING: mesh must have been created and added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pMeshName name of the mesh. + * \param pMeshDim dimension of the mesh. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Elements to the given output stream. + * \param pOs any output stream. + * \param pE any Elements. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Elements& pE); + +private: + + /** + * Builds the set of nodes used by this set of elements. + * If the set already exist, then it is cleared and a new set is computed. + */ + void buildSetOfNodes(); + +private: + + med_int mNum; /**< Number of elements. */ + med_entite_maillage mEntity; /**< Type of entity, e.g. MED_MAILLE. */ + med_geometrie_element mGeom; /**< Type of primitive, e.g. MED_TETRA10. */ + int mDim; /**< Dimension of elements = mGeom / 100. */ + int mNumNodesByElt; /**< Number of nodes by element = mGeom % 100. */ + med_int* mId; /**< Optional; for each element, its identifier; NULL if undefined. */ + med_int* mFamIdent; /**< For each element, its family (identifier). */ + char* mNames; /**< Optional; for each element, its name; NULL if undefined. */ + med_int* mCon; /**< For each element, list of nodes (index in 1..*) = table of connectivity. */ + std::set<med_int> mSetOfNodes; /**< Set of all nodes used by this set of elements. */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + +private: + + // do not allow copy constructor + Elements(const Elements&); + + // do not allow copy + Elements& operator=(const Elements&); + + // do not allow operator == + bool operator==(const Elements&); + +}; // class Elements + + +} // namespace MULTIPR + + +#endif // MULTIPR_NODES_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Exceptions.hxx b/src/MULTIPR/MULTIPR_Exceptions.hxx new file mode 100755 index 000000000..14c200e9f --- /dev/null +++ b/src/MULTIPR/MULTIPR_Exceptions.hxx @@ -0,0 +1,203 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Exceptions.hxx + * + * \brief All the exceptions used by MULTIPR. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_EXCEPTIONS_HXX +#define MULTIPR_EXCEPTIONS_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include <string> +#include <iostream> + + +namespace multipr +{ + +//***************************************************************************** +// Class RuntimeException +// Super class for all exceptions used by the module MULTIPR +//***************************************************************************** + +class RuntimeException +{ +public: + + /** + * Constructor. Build a new RuntimeException. + * \param pMsg message to be associated with this exception. + * \param pFile name of the file where the probem occur (you can use the macro __FILE__); "unknown" by default. + * \param pLine number of the line where the probem occur (you can use the macro __LINE__); 0 by default. + */ + RuntimeException( + const std::string& pMsg, + const std::string& pFile = "unknown", + int pLine = 0) + { + mMsg = pMsg; + mFile = pFile; + mLine = pLine; + mType = "RuntimeException"; + } + + /** + * Dumps info about this exception to the given output stream. + */ + void dump(std::ostream& pOs) const + { + pOs << "MULTIPR: " << mType << " (" << mFile << ", line " << mLine << "): " << mMsg << std::endl; + } + +protected: + + std::string mMsg; /**< Message associated with this exception. */ + std::string mFile; /**< Name of the source file where the problem occurs (macro __FILE__ can be used to retrieve this field). */ + int mLine; /**< Number of the line where the problem occurs (macro __LINE__ can be used to retrieve this field). */ + std::string mType; /**< Type of this exception. */ +}; + + +//***************************************************************************** +// Class NullArgumentException +// Should be used when an unexpected NULL pointer occurs +//***************************************************************************** + +class NullArgumentException : public RuntimeException +{ +public: + NullArgumentException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "NullArgumentException"; + } +}; + + +//***************************************************************************** +// Class IllegalArgumentException +// Should be used when an invalid parameter is detected (check precondition) +//***************************************************************************** + +class IllegalArgumentException : public RuntimeException +{ +public: + IllegalArgumentException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IllegalArgumentException"; + } +}; + + +//***************************************************************************** +// Class IllegalStateException +// Should be used when the internal state of an object is invalid +//***************************************************************************** + +class IllegalStateException : public RuntimeException +{ +public: + IllegalStateException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IllegalStateException"; + } +}; + + +//***************************************************************************** +// Class IndexOutOfBoundsException +// Should be used when an index is out of bounds +//***************************************************************************** + +class IndexOutOfBoundsException : public RuntimeException +{ +public: + IndexOutOfBoundsException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IndexOutOfBoundsException"; + } +}; + + +//***************************************************************************** +// Class IOException +// Should be used when any i/o error occurs +//***************************************************************************** + +class IOException : public RuntimeException +{ +public: + IOException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IOException"; + } +}; + + +//***************************************************************************** +// Class FileNotFoundException +// Should be used to indicate that a file has not been found +//***************************************************************************** + +class FileNotFoundException : public IOException +{ +public: + FileNotFoundException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : IOException(pMsg, pFile, pLine) + { + mType = "FileNotFoundException"; + } +}; + + +//***************************************************************************** +// Class UnsupportedOperationException +// Should be used when a function/method is not yet implemented or +// if an operation is not supported in a given context +//***************************************************************************** + +class UnsupportedOperationException : public RuntimeException +{ +public: + UnsupportedOperationException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "UnsupportedOperationException"; + } +}; + + +} // namespace MULTIPR + + +#endif // MULTIPR_EXCEPTIONS_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Family.cxx b/src/MULTIPR/MULTIPR_Family.cxx new file mode 100755 index 000000000..40373d3c2 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Family.cxx @@ -0,0 +1,506 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Family.cxx + * + * \brief see MULTIPR_Family.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Family.hxx" +#include "MULTIPR_Exceptions.hxx" + +#include <iostream> + +using namespace std; + + +namespace multipr +{ + + +//***************************************************************************** +// Class Attributs implementation +//***************************************************************************** + +Attributs::Attributs() +{ + mId = NULL; + mVal = NULL; + mDesc = NULL; + + reset(); +} + + +Attributs::~Attributs() +{ + reset(); +} + + +Attributs& Attributs::operator=(const Attributs& pAttr) +{ + if (this != &pAttr) // check for self-assignement + { + reset(); + + mNum = pAttr.mNum; + + if (mNum < 0) throw IllegalStateException("", __FILE__, __LINE__); + + if (pAttr.mId != NULL) + { + mId = new med_int[mNum]; + memcpy(mId, pAttr.mId, sizeof(med_int) * mNum); + } + + if (pAttr.mVal != NULL) + { + mVal = new med_int[mNum]; + memcpy(mVal, pAttr.mVal, sizeof(med_int) * mNum); + } + + if (pAttr.mDesc != NULL) + { + mDesc = new char[MED_TAILLE_DESC * mNum + 1]; + memcpy(mDesc, pAttr.mDesc, MED_TAILLE_DESC * mNum + 1); + } + } + + return *this; +} + + +void Attributs::reset() +{ + mNum = 0; + + if (mId != NULL) { delete[] mId; mId = NULL; } + if (mVal != NULL) { delete[] mVal; mVal = NULL; } + if (mDesc != NULL) { delete[] mDesc; mDesc = NULL; } +} + + +ostream& operator<<(ostream& pOs, Attributs& pA) +{ + if (pA.mNum == 0) + { + pOs << "NONE" << endl; + } + else + { + pOs << endl << " #attr=" << pA.mNum << endl; + + if (pA.mId != NULL) + { + pOs << " Id =["; + for (int i = 0 ; i < pA.mNum ; i++) + { + pOs << pA.mId[i] << " "; + } + pOs << "]" << endl; + } + else + { + pOs << " Id =NULL" << endl; + } + + if (pA.mVal != NULL) + { + pOs << " Val =["; + for (int i = 0 ; i < pA.mNum ; i++) + { + pOs << pA.mVal[i] << " "; + } + pOs << "]" << endl; + } + else + { + pOs << " Val =NULL"; + } + + if (pA.mDesc != NULL) + { + pOs << " Desc=|" << pA.mDesc << "|" << endl; + } + else + { + pOs << " Desc=NULL" << endl; + } + } + + return pOs; +} + + +//***************************************************************************** +// Class Family implementation +//***************************************************************************** + +Family::Family() +{ + reset(); +} + + +Family::Family(const Family& pFamily) +{ + strncpy(mName, pFamily.mName, MED_TAILLE_NOM); + mName[MED_TAILLE_NOM] = '\0'; + mId = pFamily.mId; + mStrNameGroups = pFamily.mStrNameGroups; + mNameGroups = pFamily.mNameGroups; + mAttributs = pFamily.mAttributs; +} + + +Family::~Family() +{ + reset(); +} + + +void Family::reset() +{ + mName[0] = '\0'; + mId = 0; + mStrNameGroups = ""; + + for (int i = 0; i < eMaxMedMesh; ++i) + { + mElt[i].clear(); + } + + mNameGroups.clear(); + mAttributs.reset(); + + mIsFamilyOfNodes = true; + + mFlagPrintAll = false; +} + + +void Family::insertElt(med_int pIndexElt, eMeshType pMeshIndex) +{ + if (pIndexElt < 1) throw new IllegalArgumentException("", __FILE__, __LINE__); + + mElt[pMeshIndex].insert(pIndexElt); +} + + +void Family::buildGroups(vector<Group*>& pGroups, map<string, Group*>& pGroupNameToGroup) const +{ + // pGroups / pGroupNameToGroup can be empty or not + + if (isFamilyOfNodes()) + { + return; + } + + // for each group in this family + for (unsigned itGroup = 0 ; itGroup < mNameGroups.size() ; itGroup++) + { + const string& keyName = mNameGroups[itGroup]; + + // check if the group already exist + map<string, Group*>::iterator it = pGroupNameToGroup.find(keyName); + + Group* group = NULL; + if (it != pGroupNameToGroup.end()) + { + // the group already exists + group = (*it).second; + } + else + { + // a new group have been identified: create a new entry + group = new Group(); + group->setName(keyName); + group->setIsGroupOfNodes(isFamilyOfNodes()); + + pGroups.push_back(group); + pGroupNameToGroup.insert(make_pair(keyName, group)); + } + + // add all elements of this family to the group + for (int i = 0; i < eMaxMedMesh; ++i) + { + for (set<med_int>::iterator itElt = mElt[i].begin() ; itElt != mElt[i].end() ; itElt++) + { + group->insertElt(*itElt, (eMeshType)i); + } + } + } +} + + +Family* Family::extractGroup(const char* pGroupName) +{ + Family* family = new Family(); + + strcpy(family->mName, mName); + family->mId = mId; + family->mAttributs = mAttributs; + + if (pGroupName == NULL) + { + family->mStrNameGroups = mStrNameGroups; + family->mNameGroups = mNameGroups; + } + else + { + if (strlen(pGroupName) > MED_TAILLE_LNOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (strlen(pGroupName) == 0) throw IllegalArgumentException("", __FILE__, __LINE__); + + if (strstr(mStrNameGroups.c_str(), pGroupName) == 0) + { + // pGroupName found in the list of groups => just keep pGroupName + family->mStrNameGroups = mStrNameGroups; + family->mNameGroups = mNameGroups; + } + else + { + // pGroupName not found in the current list of groups + // probably not a group of the same nature => keep all the groups + family->mStrNameGroups = pGroupName; + family->mNameGroups.push_back(pGroupName); + } + } + + return family; +} + + +void Family::readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex) +{ + med_int* attrId = NULL; + med_int* attrVal = NULL; + char* attrDesc = NULL; + char* nameGroups = NULL; + + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pIndex < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + med_int numGroups = MEDnGroupe(pMEDfile, pMeshName, pIndex); + if (numGroups < 0) throw IOException("i/o error while reading number of groups in MED file", __FILE__, __LINE__); + + med_int numAttr = MEDnAttribut(pMEDfile, pMeshName, pIndex); + if (numAttr != 0) + { + attrId = new med_int[numAttr]; + attrVal = new med_int[numAttr]; + attrDesc = new char[MED_TAILLE_DESC * numAttr + 1]; + attrDesc[0] = '\0'; + } + if (numGroups != 0) + { + nameGroups = new char[MED_TAILLE_LNOM * numGroups + 1]; + nameGroups[0] = '\0'; + } + + med_err ret = MEDfamInfo( + pMEDfile, + pMeshName, + pIndex, + mName, + &mId, + attrId, + attrVal, + attrDesc, + &numAttr, + nameGroups, + &numGroups); + + mName[MED_TAILLE_NOM] = '\0'; + if (ret != 0) throw IOException("i/o error while reading family information in MED file", __FILE__, __LINE__); + + if (attrDesc != NULL) + { + attrDesc[MED_TAILLE_DESC * numAttr] = '\0'; + } + + mAttributs.mNum = numAttr; + mAttributs.mId = attrId; + mAttributs.mVal = attrVal; + mAttributs.mDesc = attrDesc; + + if (nameGroups) + { + mStrNameGroups = nameGroups; + } + + // split nameGroups + for (int itGroup = 0 ; itGroup < numGroups ; itGroup++) + { + char str[MED_TAILLE_LNOM + 1]; + strncpy(str, nameGroups + itGroup * MED_TAILLE_LNOM, MED_TAILLE_LNOM); + str[MED_TAILLE_LNOM] = '\0'; + mNameGroups.push_back(str); + } + + delete[] nameGroups; + + // MEDfamLire is not necessary as we used MEDnoeudsLire/MEDelementsLire instead +} + + +void Family::writeMED(med_idt pMEDfile, char* pMeshName) +{ + if (pMEDfile == 0) throw IOException("Invalid MED file.", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("Invalide mesh name.", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("Mesh name is too long.", __FILE__, __LINE__); + if (strlen(mName) > MED_TAILLE_NOM) throw IllegalArgumentException("Family name is too long.", __FILE__, __LINE__); + + med_err ret = MEDfamCr( + pMEDfile, + pMeshName, + mName, + mId, + mAttributs.mId, + mAttributs.mVal, + mAttributs.mDesc, + mAttributs.mNum, + const_cast<char*>(mStrNameGroups.c_str()), + mNameGroups.size()); + + if (ret != 0) + { + throw IOException("i/o error while creating family in MED file", __FILE__, __LINE__); + } + + // MEDfamEcr is not necessary as we used MEDnoeudsEcr/MEDelementsEcr instead + +} + + +ostream& operator<<(ostream& pOs, Family& pF) +{ + pOs << "Family: " << endl; + pOs << " Name =|" << pF.mName << "| size=" << strlen(pF.mName) << endl; + pOs << " Id =" << pF.mId << endl; + pOs << " Family of =" << (pF.isFamilyOfNodes()?"NODES":"ELEMENTS") << endl; + + pOs << " Groups: #groups=" << pF.mNameGroups.size() << endl; + for (unsigned itGroup = 0 ; itGroup < pF.mNameGroups.size() ; itGroup++) + { + pOs << " Group " << (itGroup + 1) << ": |" << pF.mNameGroups[itGroup] << "| size=" << pF.mNameGroups[itGroup].length() << endl; + } + pOs << " Attributs: " << pF.mAttributs; + + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (pF.mElt[i].size() != 0) + { + set<med_int>::iterator itSet = pF.mElt[i].end(); + itSet--; + pOs << " Elements: #elt=" << pF.mElt[i].size() << " min_id=" << (*(pF.mElt[i].begin())) << " max_id=" << (*itSet) << endl; + if (pF.mFlagPrintAll) + { + pOs << " "; + for (set<med_int>::iterator itSet = pF.mElt[i].begin() ; itSet != pF.mElt[i].end() ; itSet++) + { + pOs << (*itSet) << " "; + } + pOs << endl; + } + } + else + { + pOs << " Elements: #elt=0" << endl; + } + } + pOs << "Name of groups=" << pF.mStrNameGroups << endl; + return pOs; +} + + +//***************************************************************************** +// Class Group implementation +//***************************************************************************** + +Group::Group() +{ + reset(); +} + + +Group::~Group() +{ + reset(); +} + + +void Group::reset() +{ + mName = ""; + for (int i = 0; i < eMaxMedMesh; ++i) + { + mElt[i].clear(); + } + mIsGroupOfNodes = true; + mFlagPrintAll = false; +} + + +void Group::setName(const string& pName) +{ + if (pName.length() > MED_TAILLE_LNOM) throw IllegalArgumentException("", __FILE__, __LINE__); + + mName = pName; +} + + +void Group::insertElt(med_int pIndexElt, eMeshType pMeshIndex) +{ + if (pIndexElt < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + mElt[pMeshIndex].insert(pIndexElt); +} + +ostream& operator<<(ostream& pOs, Group& pG) +{ + pOs << "Group: " << endl; + pOs << " Name =|" << pG.mName << "| size=" << pG.mName.length() << endl; + pOs << " Group of =" << (pG.isGroupOfNodes()?"NODES":"ELEMENTS") << endl; + + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (pG.mElt[i].size() != 0) + { + set<med_int>::iterator itSet = pG.mElt[i].end(); + itSet--; + pOs << " Elements: #elt=" << pG.mElt[i].size() << " min_id=" << (*(pG.mElt[i].begin())) << " max_id=" << (*itSet) << endl; + if (pG.mFlagPrintAll) + { + pOs << " "; + for (set<med_int>::iterator itSet = pG.mElt[i].begin() ; itSet != pG.mElt[i].end() ; itSet++) + { + pOs << (*itSet) << " "; + } + pOs << endl; + } + } + else + { + pOs << " Elements: #elt=0" << endl; + } + } + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Family.hxx b/src/MULTIPR/MULTIPR_Family.hxx new file mode 100755 index 000000000..eab5065b2 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Family.hxx @@ -0,0 +1,394 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Family.hxx + * + * \brief Class Family, Group and Attributs used to wrap MED file structures. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_FAMILY_HXX +#define MULTIPR_FAMILY_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + + +#include <iostream> +#include <vector> +#include <set> +#include <map> + +#include "MULTIPR_Mesh.hxx" + +namespace multipr +{ + +//***************************************************************************** +// Predeclaration +//***************************************************************************** + +class Group; + + +//***************************************************************************** +// Class Attributs +//***************************************************************************** + +class Attributs +{ +public: + + /** + * Builds an empty Attributs (default constructor). + */ + Attributs(); + + /** + * Destructor. Removes everything. + */ + ~Attributs(); + + /** + * Assignment operator (deep copy). + * \param pAttr any Atttibuts to be copied. + * \return a reference towards the copy. + */ + Attributs& operator=(const Attributs& pAttr); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Dumps any Attributs to the given output stream. + * \param pOs any output stream. + * \param pA any Attributs. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Attributs& pA); + +public: + + med_int mNum; /**< Number of attributes. */ + med_int* mId; /**< Table of identifiers: for each attribute, its identifier. */ + med_int* mVal; /**< Table of values; for each attribute, its value. */ + char* mDesc; /**< Table of description; for each attribute, its description. */ + +private: + + // do not allow copy constructor + Attributs(const Attributs&); + + // do not allow operator == + bool operator==(const Attributs&); + +}; // class Attribut + + +//***************************************************************************** +// Class Family +//***************************************************************************** + +class Family +{ +public: + + /** + * Builds an empty Family (default constructor). + */ + Family(); + + /** + * Copy constructor. + */ + Family(const Family& pFamily); + + /** + * Destructor. Removes everything. + */ + ~Family(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the identifier (= number) of this Family. + * \return the identifier of this Family. + */ + med_int getId() const { return mId; } + + /** + * Set the identifier of this family. + * \param pId The identifier. + */ + void setId(med_int pId) { mId = pId; }; + + /** + * Returns the name of this Family. + * \return the name of this Family. + */ + const char* getName() const { return mName; } + + /** + * Returns true if this Family if a family of nodes, false if is a family of elements (=cells)). + * \return true iff this Family if a family of nodes. + */ + bool isFamilyOfNodes() const { return mIsFamilyOfNodes; } + + /** + * Sets whether this Family is a family of nodes or family of elements (= cells). + * \param pIsFamilyOfNodes flag. + */ + void setIsFamilyOfNodes(bool pIsFamilyOfNodes) { mIsFamilyOfNodes = pIsFamilyOfNodes; } + + /** + * Inserts a new element (by its index) into this Family. + * \param pIndexElt index of the element to be added; must be >= 1. + * \param pMeshIndex Index of the mesh (eMED_TETRA4 etc...). Default value when its a family of nodes. + * \throw IllegalArgumentException if pIndexElt <= 0. + */ + void insertElt(med_int pIndexElt, eMeshType pMeshIndex = eMED_POINT1); + + /** + * Returns the number of elements in this Family. + * \return the number of elements in this Family. + */ + int getSize(eMeshType pMeshIndex = eMED_POINT1) const { return mElt[pMeshIndex].size(); } + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Adds all the groups of this Family into the set of groups described by (pGroups, pGroupNameToGroup). + * \param pGroups current list of groups. + * \param pGroupNameToGroup table (map) to retrieve a Group* from its name. + */ + void buildGroups( + std::vector<Group*>& pGroups, + std::map<std::string, Group*>& pGroupNameToGroup) const; + + /** + * Constructor. Returns a copy of this family restricted to the given group if pGroupName != NULL. + * Examples: + * 1. If current family have 3 groups "A", "B" and "C" and pGroupName="B", then the new family will only reference the group "B" + * 2. If current family have 3 groups "A", "B" and "C" and pGroupName="D", then the new family will reference groups "A", "B" and "C". + * WARNING: elements are not copied + * \param pGroupName name of the group to keep. + * \return a copy of this family. + */ + Family* extractGroup(const char* pGroupName); + + /** + * Returns the set of all the elements referenced in this Family. + * \return the set of all the elements referenced in this Family. + */ + const std::set<med_int>& getSetOfElt(eMeshType pMeshIndex) const { return mElt[pMeshIndex]; } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a Family from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName name of the mesh. + * \param pIndex index of the family to be read (must be >= 1). + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex); + + /** + * Writes this Family to a MED file. + * WARNING: mesh must have been created and added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pPeshName name of the mesh. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Family to the given output stream. + * \param pOs any output stream. + * \param pF any Family. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Family& pF); + +private: + + char mName[MED_TAILLE_NOM + 1]; /** Name of the Family */ + med_int mId; /**< Id: > 0 if family of nodes; < 0 if family of elements. */ + std::set<med_int> mElt[eMaxMedMesh]; /**< Set of all the elements (by their index in 1..*). */ + std::string mStrNameGroups; /**< A string with name of all groups which contain the Family. */ + std::vector<std::string> mNameGroups; /**< List of groups (by name) which contain the Family. */ + Attributs mAttributs; /**< All the attributed related to the Family. */ + bool mIsFamilyOfNodes; /**< Is it a family of nodes or a family of elements? */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + +private: + + // do not allow copy constructor + //Family(const Family&); + + // do not allow copy + Family& operator=(const Family&); + + // do not allow operator == + bool operator==(const Family&); + +}; // class Family + + +//***************************************************************************** +// Class Group +//***************************************************************************** + +class Group +{ +public: + + /** + * Builds an empty group (default constructor). + */ + Group(); + + /** + * Destructor. Removes everything. + */ + ~Group(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true if it is a group of nodes, false if it is a group of elements. + * \return true if it is a group of nodes, false if it is a group of elements. + */ + bool isGroupOfNodes() const { return mIsGroupOfNodes; } + + /** + * Sets whether it is a group of nodes or a group of elements. + * \param pIsGroupOfNodes true for a group of nodes, false for a group of elements. + */ + void setIsGroupOfNodes(bool pIsGroupOfNodes) { mIsGroupOfNodes = pIsGroupOfNodes; } + + /** + * Returns the name of this Group. + * \return the name of this Group. + */ + const std::string& getName() const { return mName; } + + /** + * Sets the name of this Group. + * \param pName new name of this Group (length of name must not exceed MED_TAILLE_LNOM). + */ + void setName(const std::string& pName); + + /** + * Adds the index of a new element to this Group. + * \param pIndexElt must be >= 1. + * \param pMeshIndex The index of the mesh type. + */ + void insertElt(med_int pIndexElt, eMeshType pMeshIndex); + + /** + * Set a complete set of elements. + * \param pMeshIndex The index of the mesh type. + * \param pSetOfElt The set of elements. + */ + void setSetOfElt(eMeshType pMeshIndex, const std::set<med_int>& pSetOfElt) { mElt[pMeshIndex] = pSetOfElt; }; + + /** + * Returns the set of all the elements referenced in this Group. + * \return the set of all the elements referenced in this Group. + */ + const std::set<med_int>& getSetOfElt(eMeshType pMeshIndex) const { return mElt[pMeshIndex]; } + + /** + * Returns the number of elements referenced in this Group. + * \return the number of elements referenced in this Group. + */ + int getSize(eMeshType pMeshIndex) const { return mElt[pMeshIndex].size(); } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Group to the given output stream. + * \param pOs any output stream. + * \param pG any Group. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Group& pG); + +private: + + std::string mName; /**< Name of the group. */ + std::set<med_int> mElt[eMaxMedMesh]; /**< All elements of this group; each element is referenced by its index >= 1; each element is unique. */ + bool mIsGroupOfNodes; /**< Is it a group of nodes or a group of elements? */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + +private: + + // do not allow copy constructor + Group(const Group&); + + // do not allow copy + Group& operator=(const Group&); + + // do not allow operator == + bool operator==(const Group&); + +}; // class Group + + +} // namespace MULTIPR + + +#endif // MULTIPR_FAMILY_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Field.cxx b/src/MULTIPR/MULTIPR_Field.cxx new file mode 100755 index 000000000..67bae0f30 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Field.cxx @@ -0,0 +1,903 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Field.cxx + * + * \brief see MULTIPR_Field.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Field.hxx" +#include "MULTIPR_MeshDis.hxx" +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_Family.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Elements.hxx" +#include "MULTIPR_Profil.hxx" + +#include <iostream> + +using namespace std; + + +namespace multipr +{ + +//***************************************************************************** +// Class Field implementation +//***************************************************************************** + +Field::Field() +{ + reset(); +} + + +Field::~Field() +{ + reset(); +} + + +void Field::reset() +{ + mName[0] = '\0'; + mEntity = MED_NOEUD; + mGeom = MED_NONE; + mGeomIdx = eMaxMedMesh; + mType = MED_FLOAT64; + mSizeOfType = 8; + mNumComponents = 0; + mStrComponent = ""; + mStrUnit = ""; + + mNGauss.clear(); + mDT.clear(); + mNumDT.clear(); + mDTUnit.clear(); + mNumO.clear(); + mGaussLoc.clear(); + mProfil.clear(); + mSizeOfData.clear(); + mNVal.clear(); + + for (unsigned it = 0 ; it < mVal.size() ; it++) + { + delete[] mVal[it]; + } + mVal.clear(); + + mFlagPrintAll = false; +} + + +bool Field::isEmpty() const +{ + return (mNGauss.size() == 0); +} + + +int Field::getNumberOfGaussPointsByElement(int pTimeStepIt) const +{ + if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mNGauss[pTimeStepIt - 1]; +} + + +const string& Field::getNameGaussLoc(int pTimeStepIt) const +{ + if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mGaussLoc[pTimeStepIt - 1]; +} + + +const unsigned char* Field::getValue(int pTimeStepIt, int pIndex) const +{ + if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + if ((pIndex < 1) || (pIndex > mNVal[pTimeStepIt - 1] / mNGauss[pTimeStepIt - 1])) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + // size of one data = size of type * number of components * number of Gauss points + int sizeOfOneData = mSizeOfType * mNumComponents * mNGauss[pTimeStepIt - 1]; + + unsigned char* ret = mVal[pTimeStepIt - 1] + (pIndex - 1) * sizeOfOneData; + + return ret; +} + +const std::string& Field::getProfil(int pTimeStep) const +{ + if ((pTimeStep < 1) || (pTimeStep > int(mProfil.size()))) throw IndexOutOfBoundsException("Unknown time step", __FILE__, __LINE__); + + return mProfil[pTimeStep - 1]; +} + +Field* Field::extractSubSet(const set<med_int>& pSetIndices) const +{ + Field* subset = new Field(); + + memcpy(subset->mName, mName, MED_TAILLE_NOM + 1); + subset->mEntity = mEntity; + subset->mGeom = mGeom; + subset->mType = mType; + subset->mSizeOfType = mSizeOfType; + subset->mNumComponents = mNumComponents; + subset->mStrComponent = mStrComponent; + subset->mStrUnit = mStrUnit; + + subset->mNGauss = mNGauss; + subset->mDT = mDT; + subset->mNumDT = mNumDT; + subset->mDTUnit = mDTUnit; + subset->mNumO = mNumO; + subset->mGaussLoc = mGaussLoc; + subset->mProfil = mProfil; + + // for each time step + for (unsigned itTimeStep = 0 ; itTimeStep < mNGauss.size() ; itTimeStep++) + { + //if (mProfil[itTimeStep].size() != 0) throw UnsupportedOperationException("", __FILE__, __LINE__); + // WARNING : do not manage profil for the moment + // if there is a profil, + // 1. we should set mProfil to NO_PROFIL for this time_step + // 2. we should extract data according to the profil + + int nval = pSetIndices.size() * subset->mNGauss[itTimeStep]; + subset->mNVal.push_back(nval); + + int sizeOfData = nval * mSizeOfType * mNumComponents; + subset->mSizeOfData.push_back(sizeOfData); + + unsigned char* data = new unsigned char[sizeOfData]; + unsigned char* dest = data; + int sizeOfOneData = mSizeOfType * mNumComponents * subset->mNGauss[itTimeStep]; + + // for each element to extract + for (set<med_int>::iterator itSet = pSetIndices.begin() ; itSet != pSetIndices.end() ; itSet++) + { + int indexElt = (*itSet); + + // MED index start at 1. + if (indexElt < 1) throw new IllegalArgumentException("", __FILE__, __LINE__); + + unsigned char* src = mVal[itTimeStep] + (indexElt - 1) * sizeOfOneData; + memcpy(dest, src, sizeOfOneData); + + dest += sizeOfOneData; + } + subset->mVal.push_back(data); + } + + return subset; +} + + +Field* Field::merge(Field* pField) +{ + Field* field = new Field(); + + if (strcmp(mName, pField->mName) != 0) throw IllegalStateException("incompatible field", __FILE__, __LINE__); + memcpy(field->mName, mName, MED_TAILLE_NOM + 1); + + if (mEntity != pField->mEntity) throw IllegalStateException("incompatible entity", __FILE__, __LINE__); + field->mEntity = mEntity; + + if (mGeom != pField->mGeom) throw IllegalStateException("incompatible geom", __FILE__, __LINE__); + field->mGeom = mGeom; + + if (mType != pField->mType) throw IllegalStateException("incompatible type", __FILE__, __LINE__); + field->mType = mType; + + field->mSizeOfType = mSizeOfType; + + if (mNumComponents != pField->mNumComponents) throw IllegalStateException("incompatible #components", __FILE__, __LINE__); + field->mNumComponents = mNumComponents; + + field->mStrComponent = mStrComponent; + field->mStrUnit = mStrUnit; + + if (mNGauss.size() != pField->mNGauss.size()) throw IllegalStateException("incompatible #time stamps", __FILE__, __LINE__); + field->mNGauss = mNGauss; + + field->mDT = mDT; + field->mNumDT = mNumDT; + field->mDTUnit = mDTUnit; + field->mNumO = mNumO; + field->mGaussLoc = mGaussLoc; + field->mProfil = mProfil; + + // for each time step + for (unsigned itTimeStep = 0 ; itTimeStep < mNGauss.size() ; itTimeStep++) + { + int sizeOfData = mSizeOfData[itTimeStep] + pField->mSizeOfData[itTimeStep]; + field->mSizeOfData.push_back(sizeOfData); + + int nVal = mNVal[itTimeStep] + pField->mNVal[itTimeStep]; + field->mNVal.push_back(nVal); + + unsigned char* data = new unsigned char[sizeOfData]; + memcpy(data, mVal[itTimeStep], mSizeOfData[itTimeStep]); + memcpy(data + mSizeOfData[itTimeStep], pField->mVal[itTimeStep], pField->mSizeOfData[itTimeStep]); + field->mVal.push_back(data); + } + + return field; +} + + +Field* Field::merge(vector<Field*> pFields, int pFieldIt) +{ + if (pFields.size() == 0) throw IllegalArgumentException("pElements should contain at least 1 element", __FILE__, __LINE__); + + Field* field = new Field(); + + // check if fields are compatible + for (unsigned i = 0 ; i < pFields.size() ; i++) + { + if (strcmp(mName, pFields[i]->mName) != 0) throw IllegalStateException("incompatible field", __FILE__, __LINE__); + if (mEntity != pFields[i]->mEntity) throw IllegalStateException("incompatible entity", __FILE__, __LINE__); + if (mGeom != pFields[i]->mGeom) throw IllegalStateException("incompatible geom", __FILE__, __LINE__); + if (mType != pFields[i]->mType) throw IllegalStateException("incompatible type", __FILE__, __LINE__); + if (mNumComponents != pFields[i]->mNumComponents) throw IllegalStateException("incompatible #components", __FILE__, __LINE__); + if (mNGauss.size() != pFields[i]->mNGauss.size()) throw IllegalStateException("incompatible #time stamps", __FILE__, __LINE__); + } + + memcpy(field->mName, mName, MED_TAILLE_NOM + 1); + field->mEntity = mEntity; + field->mGeom = mGeom; + field->mType = mType; + field->mSizeOfType = mSizeOfType; + field->mNumComponents = mNumComponents; + field->mStrComponent = mStrComponent; + field->mStrUnit = mStrUnit; + + if (pFieldIt == -1) // merge all time step + { + field->mNGauss = mNGauss; + field->mDT = mDT; + field->mNumDT = mNumDT; + field->mDTUnit = mDTUnit; + field->mNumO = mNumO; + field->mGaussLoc = mGaussLoc; + field->mProfil = mProfil; + + // for each time step + for (unsigned itTimeStep = 0 ; itTimeStep < mNGauss.size() ; itTimeStep++) + { + int sizeOfData = mSizeOfData[itTimeStep]; + int nVal = mNVal[itTimeStep]; + + for (unsigned i = 0 ; i < pFields.size() ; i++) + { + sizeOfData += pFields[i]->mSizeOfData[itTimeStep]; + nVal += pFields[i]->mNVal[itTimeStep]; + } + + field->mSizeOfData.push_back(sizeOfData); + field->mNVal.push_back(nVal); + + unsigned char* data = new unsigned char[sizeOfData]; + memcpy(data, mVal[itTimeStep], mSizeOfData[itTimeStep]); + + int offsetData = mSizeOfData[itTimeStep]; + for (unsigned i = 0 ; i < pFields.size() ; i++) + { + memcpy(data + offsetData, pFields[i]->mVal[itTimeStep], pFields[i]->mSizeOfData[itTimeStep]); + offsetData += pFields[i]->mSizeOfData[itTimeStep]; + } + + field->mVal.push_back(data); + } + } + else // only merge the given time step + { + field->mNGauss.push_back(mNGauss[pFieldIt]); + field->mDT.push_back(mDT[pFieldIt]); + field->mNumDT.push_back(mNumDT[pFieldIt]); + field->mDTUnit.push_back(mDTUnit[pFieldIt]); + field->mNumO.push_back(mNumO[pFieldIt]); + + if (mGaussLoc.size() != 0) field->mGaussLoc.push_back(mGaussLoc[pFieldIt]); + if (mProfil.size() != 0) field->mProfil.push_back(mProfil[pFieldIt]); + + // to finish + throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + } + + return field; +} + +void Field::getMinMax(float& pMin, float& pMax) +{ + pMin = std::numeric_limits<med_float>::max(); + pMax = std::numeric_limits<med_float>::min(); + + for (unsigned itTimeStep = 0 ; itTimeStep < mNGauss.size() ; itTimeStep++) + { + switch (mType) + { + case MED_FLOAT64: + { + med_float* src = reinterpret_cast<med_float*>(mVal[itTimeStep]); + for (int itVal = 0 ; itVal < mNVal[itTimeStep] * mNumComponents ; itVal++) + { + if (src[itVal] < pMin) + { + pMin = src[itVal]; + } + if (src[itVal] > pMax) + { + pMax = src[itVal]; + } + } + } + break; + case MED_INT: + case MED_INT32: + { + med_int* src = reinterpret_cast<med_int*>(mVal[itTimeStep]); + for (int itVal = 0 ; itVal < mNVal[itTimeStep] * mNumComponents ; itVal++) + { + if (src[itVal] < pMin) + { + pMin = src[itVal]; + } + if (src[itVal] > pMax) + { + pMax = src[itVal]; + } + } + } + break; + case MED_INT64: + { + long* src = reinterpret_cast<long*>(mVal[itTimeStep]); + for (int itVal = 0 ; itVal < mNVal[itTimeStep] * mNumComponents ; itVal++) + { + if (src[itVal] < pMin) + { + pMin = src[itVal]; + } + if (src[itVal] > pMax) + { + pMax = src[itVal]; + } + } + } + break; + default: + // should not be there + throw IllegalStateException("should not be there", __FILE__, __LINE__); + } + } +} + +void Field::getSetOfGaussLoc(set<string>& pSetOfGaussLoc) const +{ + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + const string& gaussLocName = mGaussLoc[itGaussLoc]; + + if (gaussLocName.length() != 0) + { + pSetOfGaussLoc.insert(gaussLocName); + } + } +} + + +void Field::readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName, med_geometrie_element pGeom) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pIndex < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + mNumComponents = MEDnChamp(pMEDfile, pIndex); + + if (mNumComponents < 0) throw IOException("", __FILE__, __LINE__); + + char* strComponent = new char[mNumComponents * MED_TAILLE_PNOM + 1]; + char* strUnit = new char[mNumComponents * MED_TAILLE_PNOM + 1]; + + strComponent[0] = '\0'; + strUnit[0] = '\0'; + + med_err ret = MEDchampInfo( + pMEDfile, + pIndex, + mName, + &(mType), + strComponent, + strUnit, + mNumComponents); + mName[MED_TAILLE_NOM] = '\0'; + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + mStrComponent = strComponent; + mStrUnit = strUnit; + + delete[] strUnit; + delete[] strComponent; + + switch (mType) + { + case MED_FLOAT64: mSizeOfType = 8; break; + case MED_INT64: mSizeOfType = 8; break; + case MED_INT32: mSizeOfType = 4; break; + case MED_INT: mSizeOfType = 4; break; + default: throw IllegalStateException("Unknown field data type", __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Read fields over nodes + //--------------------------------------------------------------------- + bool fieldOnNodes = false; + { + med_int numTimeStepNodes = MEDnPasdetemps( + pMEDfile, + mName, + MED_NOEUD, + (med_geometrie_element) 0); + + if (numTimeStepNodes < 0) throw IOException("", __FILE__, __LINE__); + + if (numTimeStepNodes > 0) + { + fieldOnNodes = true; + mEntity = MED_NOEUD; + mGeom = (med_geometrie_element) 0; + mGeomIdx = eMaxMedMesh; + readMEDtimeSteps(pMEDfile, numTimeStepNodes, pMeshName); + } + } + + //--------------------------------------------------------------------- + // Read fields over elements + //--------------------------------------------------------------------- + { + med_int numTimeStepElt = MEDnPasdetemps( + pMEDfile, + mName, + MED_MAILLE, + pGeom); + + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (CELL_TYPES[i] == pGeom) + { + mGeomIdx = (eMeshType)i; + break; + } + } + if (numTimeStepElt < 0) throw IOException("", __FILE__, __LINE__); + + if (numTimeStepElt > 0) + { + if (fieldOnNodes) throw IllegalStateException("", __FILE__, __LINE__); + mEntity = MED_MAILLE; + mGeom = pGeom; + readMEDtimeSteps(pMEDfile, numTimeStepElt, pMeshName); + } + } +} + + +void Field::readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pNumberOfTimeSteps < 0) throw IllegalArgumentException("", __FILE__, __LINE__); + + char strEntity[8]; + switch (mEntity) + { + case MED_ARETE: + case MED_FACE: + case MED_MAILLE: strcpy(strEntity, "CELLS"); break; + case MED_NOEUD: strcpy(strEntity, "NODES"); break; + default: strcpy(strEntity, "UNKNOWN"); break; + } + + // iterates over time step + for (int itTimeStep = 1 ; itTimeStep <= pNumberOfTimeSteps ; itTimeStep++) + { + med_int ngauss; + med_int numdt; + med_int numo; + char dtunit[MED_TAILLE_PNOM + 1]; + med_float dt; + char maa[MED_TAILLE_NOM + 1]; + med_booleen local; + med_int nmaa; + + med_err ret = MEDpasdetempsInfo( + pMEDfile, + mName, + mEntity, + mGeom, + itTimeStep, + &ngauss, + &numdt, + &numo, + dtunit, + &dt, + maa, + &local, + &nmaa); + + if (ret != 0) throw IOException("i/o error while reading #timesteps in MED file", __FILE__, __LINE__); + + // mesh must be local + if (local != MED_VRAI) throw IllegalStateException("only local fields are currently supported", __FILE__, __LINE__); + + // #mesh must be 1 + if (nmaa != 1) throw IllegalStateException("field shoud be associated with 1 mesh only", __FILE__, __LINE__); + + // mesh must be pMeshName + // if field does not apply on the current mesh, skip + if (strcmp(maa, pMeshName) != 0) + { + continue; + } + + mNGauss.push_back(ngauss); + mDT.push_back(dt); + mNumDT.push_back(numdt); + mDTUnit.push_back(dtunit); + mNumO.push_back(numo); + + med_int nval = MEDnVal( + pMEDfile, + mName, + mEntity, + mGeom, + numdt, + numo, + pMeshName, + MED_GLOBAL); + + if (nval < 0) throw IOException("i/o error while reading field in MED file", __FILE__, __LINE__); + + mNVal.push_back(nval); + + char gaussLocName[MED_TAILLE_NOM + 1]; + char profilName[MED_TAILLE_NOM + 1]; + int sizeOfData = mSizeOfType * mNumComponents * nval; + mSizeOfData.push_back(sizeOfData); + unsigned char* fieldData = new unsigned char[sizeOfData]; + ret = MEDchampLire( + pMEDfile, + pMeshName, + mName, + fieldData, + MED_FULL_INTERLACE, + MED_ALL, + gaussLocName, + profilName, + MED_COMPACT, // should be: MED_GLOBAL, MED_NO_PFLMOD, MED_COMPACT + mEntity, + mGeom, + numdt, + numo); + if (ret != 0) throw IOException("i/o error while reading field in MED file", __FILE__, __LINE__); + + mGaussLoc.push_back(gaussLocName); + mProfil.push_back(profilName); + mVal.push_back(fieldData); + } +} + + +void Field::writeMED(med_idt pMEDfile, char* pMeshName, bool pCreateField) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (mNumComponents < 1) throw IllegalStateException("", __FILE__, __LINE__); + med_err ret; + + if (pCreateField) + { + ret = MEDchampCr( + pMEDfile, + mName, // name of the field + mType, // type of data (MED_FLOAT64, MED_INT32, etc.) + const_cast<char*>(mStrComponent.c_str()), // name of components + const_cast<char*>(mStrUnit.c_str()), // name of units + mNumComponents); // number of components + + if (ret != 0) throw IOException("i/o error while creating field in MED file", __FILE__, __LINE__); + } + // for each time step + for (unsigned i = 0 ; i < mNGauss.size() ; i++) + { + // skip if no values + if (mNVal[i] == 0) continue; + + ret = MEDchampEcr( + pMEDfile, + pMeshName, // name of the mesh (first call to MEDchampEcr => name of reference) + mName, // name of the field + mVal[i], // data (= values) + MED_FULL_INTERLACE, // data organization + mNVal[i], // number of values + const_cast<char*>(mGaussLoc[i].c_str()), // name of Gauss reference + MED_ALL, // components to be selected + const_cast<char*>(mProfil[i].c_str()), // name of profil + MED_GLOBAL, // how to read data: MED_NO_PFLMOD,MED_COMPACT,MED_GLOBAL + mEntity, // type of entity (MED_NOEUD, MED_MAILLE, etc.) + mGeom, // type of geometry (TETRA10, etc.) + mNumDT[i], // time step iteration + const_cast<char*>(mDTUnit[i].c_str()), // unit of time step + mDT[i], // time key + mNumO[i]); // order number + + if (ret != 0) throw IOException("i/o error while writing field in MED file", __FILE__, __LINE__); + } +} + +void Field::writeMEDOptimized(std::vector<MeshDisPart*>* pParts, const char* pMeshName, GaussIndexList* pGaussList, int pGeomIdx, std::vector<med_int>& pFiles, std::map<std::string, Profil*>& pProfils) +{ + med_err ret; + unsigned char* lValue = NULL; + unsigned lGaussIdx = 0; + bool lCreateField = false; + med_int nbField; + char lName[MED_TAILLE_NOM + 1]; + med_type_champ type; + char* comp = new char[mNumComponents * MED_TAILLE_PNOM + 1]; + char* unit = new char[mNumComponents * MED_TAILLE_PNOM + 1]; + set<med_int>* idxSet; + std::set< med_int> lSetOfElt; + bool completeProfil; + + // For each time step. + for (unsigned itTimeStep = 0; itTimeStep < mNGauss.size(); ++itTimeStep) + { + lGaussIdx = 0; + // For each part. + for (unsigned itPart = 0 ; itPart < pParts->size() ; ++itPart) + { + // Skip empty part/mesh ! + if ((*pParts)[itPart]->getMesh()->getNumberOfElements((eMeshType)pGeomIdx) == 0 && + !this->isFieldOnNodes()) + { + continue; + } + + // Get the index of the nodes or elements of this field. If the index is empty + // the corresponding mesh was removed during domain split so we just skip it. + do + { + if (this->isFieldOnNodes()) + { + // Field is on nodes. + idxSet = &(*pGaussList)[lGaussIdx].second; + } + else + { + // Field is on elements. + idxSet = &(*pGaussList)[lGaussIdx].first[pGeomIdx]; + } + lGaussIdx++; + } + while (idxSet->size() == 0 && lGaussIdx < pGaussList->size()); + + // Check if the gauss list is empty. + if (lGaussIdx > pGaussList->size() || idxSet == 0) + { + // We should never go here... + throw IllegalStateException("Corrupted file !", __FILE__, __LINE__); + } + // We check if the field already exists in this MED file. + // I guess we could ignore this and always create the field but it seems + // to create corrupted MED files. + lCreateField = true; + nbField = MEDnChamp(pFiles[itPart], 0); + for (int i = 1; i <= nbField; ++i) + { + ret = MEDchampInfo(pFiles[itPart], i, lName, &type, comp, unit, mNumComponents); + lName[MED_TAILLE_NOM] = '\0'; + if (strncmp(mName, lName, MED_TAILLE_NOM) == 0) + { + lCreateField = false; + break; + } + } + + completeProfil = false; + // If we have some profile. + if (mProfil.size() > 0) + { + // Try to find it. + if (pProfils.find(mProfil[itTimeStep]) != pProfils.end()) + { + lSetOfElt.clear(); + // Extract the subset of elements contained in the profil and the current part. + pProfils[mProfil[itTimeStep]]->filterSetOfElement(*idxSet, lSetOfElt); + // If this part has no nodes of elements in the profil we skip it. + if (lSetOfElt.size() == 0) + { + continue; + } + // Detect if the profil contains the whole field + if (lSetOfElt.size() == pProfils[mProfil[itTimeStep]]->getSet().size()) + { + completeProfil = true; + } + // Replace the previous set. + idxSet = &lSetOfElt; + } + } + + // If the field doesn't exist we create it. + if (lCreateField == true) + { + ret = MEDchampCr( + pFiles[itPart], + mName, // name of the field + mType, // type of data (MED_FLOAT64, MED_INT32, etc.) + const_cast<char*>(mStrComponent.c_str()),// name of components + const_cast<char*>(mStrUnit.c_str()), // name of units + mNumComponents); // number of components + } + + int nval; + // If the profil contains the whole field, we dont need to copy it. + if (completeProfil) + { + nval = mNVal[itTimeStep]; + lValue = mVal[itTimeStep]; + } + else + { + // Compute field number of values, size of one value etc. + nval = idxSet->size() * this->mNGauss[itTimeStep]; + int sizeOfData = nval * mSizeOfType * mNumComponents; + int sizeOfOneData = mSizeOfType * mNumComponents * this->mNGauss[itTimeStep]; + lValue = new unsigned char[sizeOfData + 1]; + + // Copy the subset of values. + unsigned char* dest = lValue; + for (set<med_int>::iterator itSet = idxSet->begin() ; itSet != idxSet->end() ; ++itSet) + { + int indexElt = (*itSet); + unsigned char* src = mVal[itTimeStep] + (indexElt - 1) * sizeOfOneData; + memcpy(dest, src, sizeOfOneData); + dest += sizeOfOneData; + } + } + + // Write the field. + ret =MEDchampEcr( + pFiles[itPart], + const_cast<char*>(pMeshName),// name of the mesh (first call to MEDchampEcr => name of reference) + mName,// name of the field + lValue,// data (= values) + MED_FULL_INTERLACE ,// data organization + nval,// number of values + const_cast<char*>(mGaussLoc[itTimeStep].c_str()),// name of Gauss reference + MED_ALL,// components to be selected + const_cast<char*>(mProfil[itTimeStep].c_str()),// name of profil + MED_COMPACT,// how to read data: MED_NO_PFLMOD,MED_COMPACT,MED_GLOBAL + mEntity,// type of entity (MED_NOEUD, MED_MAILLE, etc.) + mGeom,// type of geometry (TETRA10, etc.) + mNumDT[itTimeStep],// time step iteration + const_cast<char*>(mDTUnit[itTimeStep].c_str()), // unit of time step + mDT[itTimeStep],// time key + mNumO[itTimeStep]);// order number + + // If we use the field's data we dont need to delete it. + if (!completeProfil) + { + delete[] lValue; + } + + if (ret != 0) + { + throw IOException("i/o error while writing field in MED file", __FILE__, __LINE__); + } + + } + } +} + +ostream& operator<<(ostream& pOs, Field& pF) +{ + char strEntity[16]; + switch (pF.mEntity) + { + case MED_MAILLE: strcpy(strEntity, "MED_MAILLE"); break; + case MED_FACE: strcpy(strEntity, "MED_FACE"); break; + case MED_ARETE: strcpy(strEntity, "MED_ARETE"); break; + case MED_NOEUD: strcpy(strEntity, "MED_NOEUD"); break; + default: strcpy(strEntity, "UNKNOWN"); break; + } + + char strType[16]; + switch (pF.mType) + { + case MED_FLOAT64: strcpy(strType, "MED_FLOAT64"); break; + case MED_INT32: strcpy(strType, "MED_INT32"); break; + case MED_INT64: strcpy(strType, "MED_INT64"); break; + case MED_INT: strcpy(strType, "MED_INT"); break; + default: strcpy(strType, "UNKNOWN"); break; + } + + pOs << "Field: " << endl; + pOs << " Name =|" << pF.mName << "|" << endl; + pOs << " Entity =" << strEntity << endl; + pOs << " Geom =" << pF.mGeom << endl; + pOs << " Type =" << strType << " (size=" << pF.mSizeOfType << ")" << endl; + pOs << " #Components=" << pF.mNumComponents << endl; + pOs << " Name component=|" << pF.mStrComponent << "|" << endl; + pOs << " Unit component=|" << pF.mStrUnit << "|" << endl; + pOs << " #Time steps=" << pF.mNGauss.size() << endl; + + for (unsigned itTimeStep = 0 ; itTimeStep < pF.mNGauss.size() ; itTimeStep++) + { + pOs << " Time=" << pF.mDT[itTimeStep]; + pOs << " it=" << pF.mNumDT[itTimeStep]; + pOs << " order=" << pF.mNumO[itTimeStep]; + pOs << " #gauss=" << pF.mNGauss[itTimeStep]; + pOs << " #val=" << pF.mNVal[itTimeStep]; + pOs << " sizeof_val=" << pF.mSizeOfData[itTimeStep]; + pOs << " gauss_loc=|" << ((pF.mGaussLoc[itTimeStep].size() == 0)?"NONE":pF.mGaussLoc[itTimeStep]) << "| size=" << pF.mGaussLoc[itTimeStep].size(); + pOs << " profil=|" << ((pF.mProfil[itTimeStep].size() == 0)?"NONE":pF.mProfil[itTimeStep]) << "| size=" << pF.mProfil[itTimeStep].size() << endl; + + if (pF.mFlagPrintAll) + { + cout << " Values: "; + switch (pF.mType) + { + case MED_FLOAT64: + { + med_float* src = reinterpret_cast<med_float*>(pF.mVal[itTimeStep]); + for (int itVal = 0 ; itVal < pF.mNVal[itTimeStep] * pF.mNumComponents ; itVal++) + { + cout << src[itVal] << " "; + } + } + break; + case MED_INT: + case MED_INT32: + { + med_int* src = reinterpret_cast<med_int*>(pF.mVal[itTimeStep]); + for (int itVal = 0 ; itVal < pF.mNVal[itTimeStep] * pF.mNumComponents ; itVal++) + { + cout << src[itVal] << " "; + } + } + break; + case MED_INT64: + // not yet implemented + throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + default: + // should not be there + throw IllegalStateException("should not be there", __FILE__, __LINE__); + } + cout << endl; + } + + } + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Field.hxx b/src/MULTIPR/MULTIPR_Field.hxx new file mode 100755 index 000000000..f265d29bf --- /dev/null +++ b/src/MULTIPR/MULTIPR_Field.hxx @@ -0,0 +1,295 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Field.hxx + * + * \brief Class Field used to wrap MED file fields. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_FIELD_HXX +#define MULTIPR_FIELD_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <string> +#include <vector> +#include <set> + +#include "MULTIPR_Globals.hxx" +#include "MULTIPR_Mesh.hxx" + + +namespace multipr +{ + +// Forward declaration. +class MeshDisPart; +class Group; + +//***************************************************************************** +// Class Field +//***************************************************************************** + +class Field +{ +public: + + /** + * Builds an empty field (default constructor). + */ + Field(); + + /** + * Destructor. Removes everything. + */ + ~Field(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true iff this field is empty (no data). + * \return true if this field is empty, false otherwise. + */ + bool isEmpty() const; + + /** + * Returns true iff this field apply on nodes (otherwise, information are related to elements). + * \return true iff this field apply on nodes. + */ + bool isFieldOnNodes() const { return (mEntity == MED_NOEUD); } + + /** + * Returns the name of this Field. + * \return the name of this Field. + */ + const char* getName() const { return mName; } + + /** + * Returns the number of time steps in this Field. + * \return the number of time steps in this Field. + */ + int getNumberOfTimeSteps() const { return mNGauss.size(); } + + /** + * Returns the numeric type of information contained in this Field (e.g. MED_FLOAT64). + * \return the numeric type of this Field. + */ + med_type_champ getType() const { return mType; } + + /** + * Get the internal index of geometry type (eMED_TETRA4, etc). + * \return The index of the geometry type. + */ + eMeshType getGeomIdx() { return mGeomIdx; } + /** + * Returns the number of components of this Field. + * \return the number of components of this Field. + */ + int getNumberOfComponents() const { return mNumComponents; } + + /** + * Return the component string. + * \return the component string. + */ + const std::string& getStrComponent() { return mStrComponent; } + + /** + * Return the unit string. + * \return the unit string. + */ + const std::string& getStrUnit() { return mStrUnit; } + + /** + * Returns the number of Gauss points for each element at the given time step. + * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. + * \return number of Gauss points in the elements of this Field at the given iteration. + * \throw IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION]. + */ + int getNumberOfGaussPointsByElement(int pTimeStepIt) const; + + /** + * Returns the name of the Gauss localization related to the given iteration. + * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. + * \return the name of the Gauss localization related to the given iteration. + * \throw IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION]. + */ + const std::string& getNameGaussLoc(int pTimeStepIt) const; + + /** + * Returns a pointer towards the first value of this Field for the given element at the given time step. + * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. + * \param pIndex index of the element; must be >= 1. + * \return the value of this Field for the given element at the given time step. + * \throw IndexOutOfBoundsException if pTimeStepIt or pIndex are invalid. + */ + const unsigned char* getValue(int pTimeStepIt, int pIndex) const; + + /** + * Get the profile (if any) at the given time step. + * \param pTimeStep The time step. + * \return The name of the profile. + * \throw IndexOutOfBoundsException if pTimeStep is invalid. + */ + const std::string& getProfil(int pTimeStep) const; + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Creates a subset of this Field restricted to a set of elements (NODES or CELLS). + * This method performs a projection of this Field on the given set of elements. + * \param pSetIndices WARNING: indices start at 1. + * \return a new Field restricted to the given set of elements. + */ + Field* extractSubSet(const std::set<med_int>& pSetIndices) const; + + /** + * Adds the set of GaussLoc used by this Field into the given set. + * \param pSetOfGauss any set of Gauss localisation. + */ + void getSetOfGaussLoc(std::set<std::string>& pSetOfGaussLoc) const; + + /** + * Builds a new field by merging data of this and pField if they are compatible. + * \param pField the field to be merged with this. + * \throw IllegalStateException if the two fields are incompatible. + */ + Field* merge(Field* pField); + Field* merge(std::vector<Field*> pFields, int pFieldIt = -1); + + /** + * Get the minimum and maximum values of this field for all time steps. + * \param pMin The mininum value to fill. + * \param pMax The maxinum value to fill. + */ + void getMinMax(float& pMin, float& pMax); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a field from a MED file. + * If the field is not related to the given mesh, the result is an empty field. + * \param pMEDfile any valid MED file opened for reading. + * \param pIndex index of the field to be read; must be >= 1. + * \param pMeshName name of the mesh (a field is always related to a mesh). + * \param pGeom Type of geometry (MED_TETRA4, etc). + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName, med_geometrie_element pGeom = (med_geometrie_element)0); + + /** + * Writes this field to a MED file. The field is linked to the given mesh. + * WARNING: all related Gauss info must have been added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pMeshName name of the mesh. + * \param pCreateField set this to false to not create the field. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName, bool pCreateField = true); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Read and write the fields for optimized domain split. + * \param pParts The splited parts. + * \param pMeshName The name of the current mesh. + * \param pGaussList List of gauss points index. + * \param pGeomIdx Internal geometry type index (eMED_TETRA4, etc). + * \param pFiles List of opened file identifier. + */ + void writeMEDOptimized(std::vector<MeshDisPart*>* pParts, const char* pMeshName, GaussIndexList* pGaussList, int pGeomIdx, std::vector<med_int>& pFiles, std::map<std::string, Profil*>& pProfils); + + /** + * Dumps any Field to the given output stream. + * \param pOs any output stream. + * \param pF any Field. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Field& pF); + +private: + + /** + * Reads all the information related to its field and a given time step (by its index). + * \param pMEDfile MED file handle. + * \param pNumberOfTimeSteps number of timesteps (iteration) to be read. + * \param pMeshName name of the mesh. + * \throw IOException if any i/o error occurs. + */ + void readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName); + +private: + + char mName[MED_TAILLE_NOM + 1]; + med_entite_maillage mEntity; // type of entity, e.g. MED_MAILLE + med_geometrie_element mGeom; // type of primitives, e.g. MED_TETRA10 (MED_NONE for a field on nodes) + eMeshType mGeomIdx; // Internal index of geometry type (eMED_TETRA4, etc). + med_type_champ mType; // type of field, e.g. MED_FLOAT64, MED_INT32 + int mSizeOfType; // 8 for MED_FLOAT64, 4 for MED_INT32, etc. + med_int mNumComponents; + std::string mStrComponent; + std::string mStrUnit; + + // Information related to time steps. + // Each vector should contain the same number of elements. + // Number of time step = mNGauss.size() = mDT.size() = ... + + std::vector<med_int> mNGauss; /**< For each time step, number of Gauss points in the field. */ + std::vector<med_float> mDT; /**< For each time step, value of time step. */ + std::vector<med_int> mNumDT; /**< For each time step, iteration number. */ + std::vector<std::string> mDTUnit; /**< For each time step, units. */ + std::vector<med_int> mNumO; /**< For each time step, order number. */ + std::vector<std::string> mGaussLoc; /**< For each time step, name of Gauss localization to be used (empty if none). */ + std::vector<std::string> mProfil; /**< For each time step, name of the profil to be used (empty if none). */ + std::vector<int> mSizeOfData; /**< For each time step, sizeof data (mVal) in bytes. */ + std::vector<med_int> mNVal; /**< For each time step, number of values. */ + std::vector<unsigned char*> mVal; /**< For each time step, raw data; can be MED_FLOAT64, MED_INT32, etc. see mType. */ + + bool mFlagPrintAll; /**< Flag to control the behaviour of the stream operator <<. */ + +private: + + // do not allow copy constructor + Field(const Field&); + + // do not allow copy + Field& operator=(const Field&); + + // do not allow operator == + bool operator==(const Field&); + +}; // class Field + + +} // namespace MULTIPR + + +#endif // MULTIPR_FIELD_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_GaussLoc.cxx b/src/MULTIPR/MULTIPR_GaussLoc.cxx new file mode 100755 index 000000000..eeeed7fac --- /dev/null +++ b/src/MULTIPR/MULTIPR_GaussLoc.cxx @@ -0,0 +1,227 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_GaussLoc.cxx + * + * \brief see MULTIPR_GaussLoc.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_GaussLoc.hxx" +#include "MULTIPR_Utils.hxx" +#include "MULTIPR_Exceptions.hxx" + +#include <iostream> +#include <cmath> + +using namespace std; + + +namespace multipr +{ + + +//***************************************************************************** +// Class GaussLoc implementation +//***************************************************************************** + +GaussLoc::GaussLoc() +{ + mRefCoo = NULL; + mGaussCoo = NULL; + mWeight = NULL; + + reset(); +} + + +GaussLoc::GaussLoc(const GaussLoc& pGaussLoc) +{ + mRefCoo = NULL; + mGaussCoo = NULL; + mWeight = NULL; + + strcpy(mName, pGaussLoc.mName); + + mGeom = pGaussLoc.mGeom; + mDim = pGaussLoc.mDim; + mNumNodes = pGaussLoc.mNumNodes; + mNumGauss = pGaussLoc.mNumGauss; + + if (mDim != (mGeom / 100)) throw IllegalStateException("", __FILE__, __LINE__); + if (mNumNodes != (mGeom % 100)) throw IllegalStateException("", __FILE__, __LINE__); + + if (pGaussLoc.mRefCoo != NULL) + { + mRefCoo = new med_float[mDim * mNumNodes]; + memcpy(mRefCoo, pGaussLoc.mRefCoo, sizeof(med_float) * mDim * mNumNodes); + } + + if (pGaussLoc.mGaussCoo != NULL) + { + mGaussCoo = new med_float[mDim * mNumGauss]; + memcpy(mGaussCoo, pGaussLoc.mGaussCoo, sizeof(med_float) * mDim * mNumGauss); + } + + if (pGaussLoc.mWeight != NULL) + { + mWeight = new med_float[mNumGauss]; + memcpy(mWeight, pGaussLoc.mWeight, sizeof(med_float) * mNumGauss); + } +} + + +GaussLoc::~GaussLoc() +{ + reset(); +} + + +void GaussLoc::reset() +{ + mName[0] = '\0'; + mGeom = MED_NONE; + mDim = 0; + mNumNodes = 0; + mNumGauss = 0; + + if (mRefCoo != NULL) { delete[] mRefCoo; mRefCoo = NULL; } + if (mGaussCoo != NULL) { delete[] mGaussCoo; mGaussCoo = NULL; } + if (mWeight != NULL) { delete[] mWeight; mWeight = NULL; } +} + + +void GaussLoc::getCoordGaussPoints( + const med_float* pCooElt, + med_float* pCooGaussPoints, + int nb_gauss) const +{ + med_float* pt = const_cast<med_float*>(pCooElt); + const med_float* coeff = mGaussCoo; + med_float* dest = pCooGaussPoints; + + for (int i = 0; i < mNumGauss; ++i) + { + for (int j = 0; j < mDim; ++j) + { + dest[j] = 0; + for (int k = 1; k < nb_gauss; ++k) + { + dest[j] += pt[k * mDim + j]; + } + dest[j] /= nb_gauss; + } + coeff += mDim; + dest += mDim; + } +} + + +void GaussLoc::readMED(med_idt pMEDfile, med_int pIndex) +{ + if (pMEDfile == 0) throw IOException("pMEDfile should not be NULL", __FILE__, __LINE__); + if (pIndex < 1) throw IllegalArgumentException("pIndex should be >= 1", __FILE__, __LINE__); + + reset(); + + med_err ret = MEDgaussInfo( + pMEDfile, + pIndex, + mName, + &mGeom, + &mNumGauss); + + if (ret != 0) throw IOException("i/o error while reading Gauss localization information in MED file", __FILE__, __LINE__); + + mDim = mGeom / 100; + mNumNodes = mGeom % 100; + + mRefCoo = new med_float[mDim * mNumNodes]; + mGaussCoo = new med_float[mDim * mNumGauss]; + mWeight = new med_float[mNumGauss]; + + ret = MEDgaussLire( + pMEDfile, + mRefCoo, + mGaussCoo, + mWeight, + MED_FULL_INTERLACE, + mName); + + if (ret != 0) throw IOException("i/o error while reading Gauss localization in MED file", __FILE__, __LINE__); +} + + +void GaussLoc::writeMED(med_idt pMEDfile) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (mNumGauss < 0) throw IllegalStateException("", __FILE__, __LINE__); + if (mRefCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mGaussCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mWeight == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("", __FILE__, __LINE__); + + med_err ret = MEDgaussEcr( + pMEDfile, + mGeom, + mRefCoo, + MED_FULL_INTERLACE, + mNumGauss, + mGaussCoo, + mWeight, + mName); + + if (ret != 0) throw IOException("i/o error while writing Gauss localization", __FILE__, __LINE__); +} + + +ostream& operator<<(ostream& pOs, GaussLoc& pG) +{ + pOs << "Gauss ref:" << endl; + pOs << " Name =|" << pG.mName << "|" << endl; + pOs << " Geom =" << pG.mGeom << endl; + pOs << " #Pt Gauss=" << pG.mNumGauss << endl; + + pOs << " Ref nodes coords.: (#nodes=" << pG.mNumNodes << " dim=" << pG.mDim << ")" << endl; + for (int itNode = 0 ; itNode < pG.mNumNodes ; itNode++) + { + pOs << " Node " << (itNode + 1) << ": "; + for (int itDim = 0; itDim < pG.mDim ; itDim++) + { + pOs << pG.mRefCoo[itNode * pG.mDim + itDim] << " "; + } + pOs << endl; + } + + pOs << " Gauss coords. and weight:" << endl; + for (int itGauss = 0 ; itGauss < pG.mNumGauss ; itGauss++) + { + pOs << " Pt " << (itGauss+1) << ": "; + for (int itDim = 0; itDim < pG.mDim ; itDim++) + { + pOs << pG.mGaussCoo[itGauss * pG.mDim + itDim] << " "; + } + pOs << "weight=" << pG.mWeight[itGauss]; + pOs << endl; + } + + // debug + //med_float res[15]; + //pG.getCoordGaussPoints(pG.mRefCoo, res); + //printArray2D(res, pG.mNumGauss, pG.mDim, "Gauss pt"); + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_GaussLoc.hxx b/src/MULTIPR/MULTIPR_GaussLoc.hxx new file mode 100755 index 000000000..6eb15f76f --- /dev/null +++ b/src/MULTIPR/MULTIPR_GaussLoc.hxx @@ -0,0 +1,150 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_GaussLoc.hxx + * + * \brief Class GaussLoc. Allow to locate all the Gauss points in an element of reference (e.g. a TETRA10). + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_GAUSSLOC_HXX +#define MULTIPR_GAUSSLOC_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <iostream> + + +namespace multipr +{ + + +//***************************************************************************** +// Class GaussLoc +//***************************************************************************** + +class GaussLoc +{ +public: + + /** + * Builds an empty Gauss reference (default constructor). + */ + GaussLoc(); + + /** + * Copy constructor (deep copy). + * \param pGaussLoc the GaussLoc to copy. + */ + GaussLoc(const GaussLoc& pGaussLoc); + + /** + * Destructor. Removes everything. + */ + ~GaussLoc(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //-------------------------------------------------------------------- + + /** + * Returns the name of this GaussLoc. + * \return the name of this GaussLoc. + */ + std::string getName() const { return mName; } + + /** + * Returns dimension of Gauss points which is also the dimension of reference nodes. + * \return dimension of Gauss points. + */ + int getDim() const { return mDim; } + + /** + * Returns number of Gauss points. + * \return number of Gauss points. + */ + int getNumGaussPoints() const { return mNumGauss; } + + //--------------------------------------------------------------------- + // Algorithms + //-------------------------------------------------------------------- + + /** + * Returns the coordinates of all the Gauss points for a given element. + * \param pCooElt (in) coordinates of nodes of an element. + * \param pCoo (out) coordinates of all the Gauss points (interlaced); memory must have been allocated. + */ + void getCoordGaussPoints(const med_float* pCooElt, med_float* pCooGaussPoints, int nb_gauss) const; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a GaussLoc object from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pIndex index of the gauss localization to be read; must be >= 1. + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, med_int pIndex); + + /** + * Writes this GaussLoc object to the given MED file. + * \param pMEDfile any valid MED file opened for writing. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile); + + /** + * Dumps any GaussLoc to the given output stream. + * \param pOs any output stream. + * \param pF any Field. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, GaussLoc& pG); + +private: + + char mName[MED_TAILLE_NOM + 1]; /**< Name of the Gauss info. */ + med_geometrie_element mGeom; /**< Type of elements, e.g. TETRA10 (code is 310). */ + int mDim; /**< Dimension of nodes, e.g. 3 for a TETRA10. */ + int mNumNodes; /**< Number of nodes in the reference element, e.g. 10 for a TETRA10. */ + med_int mNumGauss; /**< Number of Gauss points. */ + med_float* mRefCoo; /**< Table of coordinates of nodes. + Example: for a TETRA10: 10 nodes, 3 components => 30 med_float. */ + med_float* mGaussCoo; /**< Table of coordinates of Gauss points. */ + med_float* mWeight; /**< Table of weights of Gauss points. */ + +private: + + // do not allow copy + GaussLoc& operator=(const GaussLoc&); + + // do not allow operator == + bool operator==(const GaussLoc&); + +}; // class GaussLoc + + +} // namespace MULTIPR + + +#endif // MULTIPR_GAUSSLOC_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Globals.hxx b/src/MULTIPR/MULTIPR_Globals.hxx new file mode 100755 index 000000000..a5897af2b --- /dev/null +++ b/src/MULTIPR/MULTIPR_Globals.hxx @@ -0,0 +1,44 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Globals.hxx + * + * \brief Some useful macros. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + + +#ifndef MULTIPR_GLOBALS_HXX +#define MULTIPR_GLOBALS_HXX + +#include <vector> +#include <set> + +//***************************************************************************** +// Some useful macros +//***************************************************************************** + +#define ENABLE_LOG 0 +#define MULTIPR_LOG(STR) if (ENABLE_LOG) cout << STR; + +/** + * Pair of index. + * See definition of GaussIndexList. + */ +typedef std::pair < std::set<int>*, std::set<int> > IndexPair; + +/** + * List of gauss index for optimized domain split. + * The first element of the pair is the element index vector (size is + * eMaxMedMesh) and the second the node index. + */ +typedef std::vector< IndexPair > GaussIndexList; + +#endif // MULTIPR_GLOBALS_HXX + + +// EOF diff --git a/src/MULTIPR/MULTIPR_Mesh.cxx b/src/MULTIPR/MULTIPR_Mesh.cxx new file mode 100755 index 000000000..4788b6087 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Mesh.cxx @@ -0,0 +1,1994 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Mesh.cxx + * + * \brief see MULTIPR_Mesh.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_Nodes.hxx" +#include "MULTIPR_Elements.hxx" +#include "MULTIPR_Family.hxx" +#include "MULTIPR_Profil.hxx" +#include "MULTIPR_GaussLoc.hxx" +#include "MULTIPR_Field.hxx" +#include "MULTIPR_MeshDis.hxx" +#include "MULTIPR_PointOfField.hxx" +#include "MULTIPR_DecimationFilter.hxx" +#include "MULTIPR_Utils.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Globals.hxx" +#include "MULTIPR_API.hxx" +#include <stdio.h> +#include <cmath> + +using namespace std; + +namespace multipr +{ + +const med_geometrie_element CELL_TYPES[MED_NBR_GEOMETRIE_MAILLE] = +{ + MED_POINT1, + MED_SEG2, + MED_SEG3, + MED_TRIA3, + MED_TRIA6, + MED_QUAD4, + MED_QUAD8, + MED_TETRA4, + MED_TETRA10, + MED_HEXA8, + MED_HEXA20, + MED_PENTA6, + MED_PENTA15, + MED_PYRA5, + MED_PYRA13 +}; + + +char CELL_NAMES[MED_NBR_GEOMETRIE_MAILLE][MED_TAILLE_NOM + 1] = +{ + "MED_POINT1", + "MED_SEG2", + "MED_SEG3", + "MED_TRIA3", + "MED_TRIA6", + "MED_QUAD4", + "MED_QUAD8", + "MED_TETRA4", + "MED_TETRA10", + "MED_HEXA8", + "MED_HEXA20", + "MED_PENTA6", + "MED_PENTA15", + "MED_PYRA5", + "MED_PYRA13" +}; + +// Number of points to consider when looking for significant nodes in a mesh. +// ie the n first nodes. +const int CELL_NB_NODE[MED_NBR_GEOMETRIE_MAILLE] = +{ + 1, //MED_POINT1 + 2, //MED_SEG2 + 2, //MED_SEG3 + 3, //MED_TRIA3 + 3, //MED_TRIA6 + 4, //MED_QUAD4 + 4, //MED_QUAD8 + 4, //MED_TETRA4 + 4, //MED_TETRA10 + 8, //MED_HEXA8 + 8, //MED_HEXA20 + 6, //MED_PENTA6 + 6, //MED_PENTA15 + 5, //MED_PYRA5 + 5 //MED_PYRA13 +}; + + + +//***************************************************************************** +// Class Mesh implementation +//***************************************************************************** + +Mesh::Mesh() +{ + mNodes = NULL; + for (int i = 0; i < eMaxMedMesh; i++) + { + mElements[i] = NULL; + } + + reset(); +} + + +Mesh::~Mesh() +{ + reset(); +} + + +void Mesh::reset() +{ + mMEDfilename[0] = '\0'; + mMEDfile = 0; + + mMeshName[0] = '\0'; + mMeshUName[0] = '\0'; + mMeshDesc[0] = '\0'; + mMeshDim = -1; + mMeshType = MED_NON_STRUCTURE; + + for (int itDim = 0 ; itDim < 3 ; itDim++) + { + mMeshBBoxMin[itDim] = numeric_limits<med_float>::quiet_NaN(); + mMeshBBoxMax[itDim] = numeric_limits<med_float>::quiet_NaN(); + } + + if (mNodes != NULL) { delete mNodes; mNodes = NULL; } + + for (int i = 0; i < eMaxMedMesh; i++) + { + if (mElements[i] != NULL) + { + delete mElements[i]; + mElements[i] = NULL; + } + } + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) + { + delete mFamilies[itFam]; + } + mFamilies.clear(); + mFamIdToFam.clear(); + + for (unsigned itGroup = 0 ; itGroup < mGroups.size() ; itGroup++) + { + delete mGroups[itGroup]; + } + mGroups.clear(); + mGroupNameToGroup.clear(); + + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + delete mGaussLoc[itGaussLoc]; + } + mGaussLoc.clear(); + mGaussLocNameToGaussLoc.clear(); + + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + //delete mFields[itField]; + } + mFields.clear(); + + for (unsigned itProfil = 0 ; itProfil < mProfils.size() ; itProfil++) + { + delete mProfils[itProfil]; + } + mProfils.clear(); + + mFlagPrintAll = false; + + mGaussIndex.clear(); +} + + +vector<string> Mesh::getNameScalarFields() const +{ + vector<string> res; + + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + // only get scalar fields, not vectorial fields + // (because, currently, decimation can only be performed on scalar fields) + if (currentField->getNumberOfComponents() == 1) + { + res.push_back(currentField->getName()); + } + } + + return res; +} + + +int Mesh::getTimeStamps(const char* pFieldName) const +{ + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + if (strcmp(currentField->getName(), pFieldName) == 0) + { + return currentField->getNumberOfTimeSteps(); + } + } + + return 0; +} + +Field* Mesh::getFieldByName(const char* pFieldName, eMeshType pGeomType) const +{ + if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); + + Field* retField = NULL; + + // for each field + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + // Check if this is the field we want. + if (strncmp(pFieldName, currentField->getName(), MED_TAILLE_NOM) == 0 && + (currentField->getGeomIdx() == pGeomType || currentField->isFieldOnNodes())) + { + // field found! + retField = currentField; + break; + } + } + + return retField; +} + +void Mesh::getFieldMinMax(const char* pFieldName, float& pMin, float& pMax) const +{ + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + // Check if this is the field we want. + if (strncmp(pFieldName, currentField->getName(), MED_TAILLE_NOM) == 0) + { + currentField->getMinMax(pMin, pMax); + break; + } + } +} + +GaussLoc* Mesh::getGaussLocByName(const char* pGaussLocName) const +{ + if (pGaussLocName == NULL) throw NullArgumentException("pGaussLocName should not be NULL", __FILE__, __LINE__); + + map<string, GaussLoc*>::const_iterator itGaussLoc = mGaussLocNameToGaussLoc.find(pGaussLocName); + GaussLoc* retGaussLoc = NULL; + + if (itGaussLoc != mGaussLocNameToGaussLoc.end()) + { + retGaussLoc = (*itGaussLoc).second; + } + + return retGaussLoc; +} + + +int Mesh::getNumberOfElements(eMeshType pGeomType) const +{ + if (mElements[pGeomType]) + { + return mElements[pGeomType]->getNumberOfElements(); + } + else + { + return 0; + } +} + +int Mesh::getNumberOfElements() const +{ + int accum = 0; + + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i]) + { + accum += mElements[i]->getNumberOfElements(); + } + } + return accum; +} + +Profil* Mesh::getProfil(const std::string pProfilName) +{ + Profil* profile = NULL; + std::vector<Profil*>::iterator it; + if (pProfilName.size() > 0) + { + for (it = mProfils.begin(); it != mProfils.end(); ++it) + { + if ((*it)->getName() == pProfilName) + { + profile = (*it); + break; + } + } + } + return profile; +} + +Mesh* Mesh::createFromSetOfElements(const std::set<med_int>* pSetOfElements, const char* pNewMeshName) +{ + if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Create a new mesh + //--------------------------------------------------------------------- + Mesh* mesh = new Mesh(); + + //--------------------------------------------------------------------- + // Build name of the new mesh + //--------------------------------------------------------------------- + strcpy(mesh->mMeshName, pNewMeshName); + + MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); + + //--------------------------------------------------------------------- + // Fill general infos + //--------------------------------------------------------------------- + strcpy(mesh->mMeshUName, mMeshUName); + strcpy(mesh->mMeshDesc, mMeshDesc); + + mesh->mMeshDim = mMeshDim; + mesh->mMeshType = mMeshType; + + MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); + MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); + MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); + MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); + + //--------------------------------------------------------------------- + // Build nodes and elements + //--------------------------------------------------------------------- + // get all elements involved + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (pSetOfElements[i].size() != 0) + { + mesh->mElements[i] = mElements[i]->extractSubSet(pSetOfElements[i]); + MULTIPR_LOG((*(mesh->mElements[i])) << endl); + } + } + + // get all nodes involved + set<med_int> setOfNodes; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i] != NULL && mesh->mElements[i] != NULL) + { + const set<med_int>& curSetOfNodes = mesh->mElements[i]->getSetOfNodes(); + setOfNodes.insert(curSetOfNodes.begin(), curSetOfNodes.end()); + } + } + mesh->mNodes = mNodes->extractSubSet(setOfNodes); + MULTIPR_LOG((*(mesh->mNodes)) << endl); + + //--------------------------------------------------------------------- + // Remap nodes + //--------------------------------------------------------------------- + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i] != NULL && mesh->mElements[i] != NULL) + { + mesh->mElements[i]->remap(setOfNodes); + MULTIPR_LOG((*(mesh->mElements[i])) << endl); + } + } + + + //--------------------------------------------------------------------- + // Build families + //--------------------------------------------------------------------- + MULTIPR_LOG("Build fam.:" << endl); + // get families of nodes + { + set<med_int> famOfNodes = mesh->mNodes->getSetOfFamilies(); + for (set<med_int>::iterator itFam = famOfNodes.begin() ; itFam != famOfNodes.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + if (mesh->mFamIdToFam.find(famSrc->getId()) == mesh->mFamIdToFam.end()) + { + Family* famDest = famSrc->extractGroup(NULL); + mesh->mFamilies.push_back(famDest); + mesh->mFamIdToFam[famDest->getId()] = famDest; + } + } + } + + // get families of elements + { + set<med_int> famOfElt; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i] != NULL && mesh->mElements[i] != NULL) + { + set<med_int> curSetOfFamilies = mesh->mElements[i]->getSetOfFamilies(); + famOfElt.insert(curSetOfFamilies.begin(), curSetOfFamilies.end()); + } + } + for (set<med_int>::iterator itFam = famOfElt.begin() ; itFam != famOfElt.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + if (mesh->mFamIdToFam.find(famSrc->getId()) == mesh->mFamIdToFam.end()) + { + Family* famDest = famSrc->extractGroup(NULL); + mesh->mFamilies.push_back(famDest); + mesh->mFamIdToFam[famDest->getId()] = famDest; + } + } + } + + MULTIPR_LOG("Finalize:"); + + // fill families with elements and build groups + //mesh->finalizeFamiliesAndGroups(); + + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Build profils. + //--------------------------------------------------------------------- + for (std::vector<Profil*>::iterator it = mProfils.begin(); it != mProfils.end(); ++it) + { + Profil* lProfil = new Profil(); + lProfil->create((*it)->getName()); + std::set<med_int> lSet; + if ((*it)->getBinding() == OnNodes) + { + (*it)->extractSetOfElement(setOfNodes, lSet); + } + else + { + (*it)->extractSetOfElement(pSetOfElements[lProfil->getGeomIdx()], lSet); + } + if (lSet.size() == 0) + { + delete lProfil; + continue; + } + lProfil->set(lSet); + mesh->mProfils.push_back(lProfil); + } + + //--------------------------------------------------------------------- + // Create new fields and collect Gauss + //--------------------------------------------------------------------- + // for each field + set<string> newSetOfGauss; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + Field* newField = NULL; + if (currentField->isFieldOnNodes()) + { + newField = currentField->extractSubSet(setOfNodes); + } + else + { + if (pSetOfElements[currentField->getGeomIdx()].size() != 0) + { + newField = currentField->extractSubSet(pSetOfElements[currentField->getGeomIdx()]); + } + } + + if (newField != NULL && !newField->isEmpty()) + { + mesh->mFields.push_back(newField); + newField->getSetOfGaussLoc(newSetOfGauss); + } + } + MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); + + //--------------------------------------------------------------------- + // Build Gauss infos + //--------------------------------------------------------------------- + for (set<string>::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) + { + const string& keyName = (*itSet); + + GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); + if (gaussLoc != NULL) + { + GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); + mesh->mGaussLoc.push_back(copyGaussLoc); + mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); + } + } + + //--------------------------------------------------------------------- + // Compute bbox + //--------------------------------------------------------------------- + mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); + + return mesh; +} + + +Mesh* Mesh::createFromGroup(const Group* pGroup, const char* pNewMeshName) +{ + if (pGroup == NULL) throw NullArgumentException("pGroup should not be NULL", __FILE__, __LINE__); + if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName should not be NULL", __FILE__, __LINE__); + if (strlen(pNewMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("pNewMeshName length too long", __FILE__, __LINE__); + //--------------------------------------------------------------------- + // Create a new mesh + //--------------------------------------------------------------------- + Mesh* mesh = new Mesh(); + + //--------------------------------------------------------------------- + // Build name of the new mesh + //--------------------------------------------------------------------- + strcpy(mesh->mMeshName, pNewMeshName); + + MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); + + //--------------------------------------------------------------------- + // Fill general infos + //--------------------------------------------------------------------- + strcpy(mesh->mMeshUName, mMeshUName); + strcpy(mesh->mMeshDesc, mMeshDesc); + + mesh->mMeshDim = mMeshDim; + mesh->mMeshType = mMeshType; + + MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); + MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); + MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); + MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); + + //--------------------------------------------------------------------- + // Build nodes and elements + //--------------------------------------------------------------------- + // Get all elements involved + std::set< med_int>* setOfEltList = new std::set< med_int>[eMaxMedMesh]; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i] != NULL) + { + const set<med_int> setOfElt = pGroup->getSetOfElt((eMeshType)i); + mesh->mElements[i] = mElements[i]->extractSubSet(setOfElt); + setOfEltList[i] = setOfElt; + } + } + + // Get all nodes involved + // The nodes a common for all elements so we don't need to store them separately. + set<med_int> setOfNodes; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mesh->mElements[i] != NULL) + { + const set<med_int>& curSetOfNodes = mesh->mElements[i]->getSetOfNodes(); + setOfNodes.insert(curSetOfNodes.begin(), curSetOfNodes.end()); + } + } + mesh->mNodes = mNodes->extractSubSet(setOfNodes); + + // We need this for the optimized memory management. + this->mGaussIndex.push_back(IndexPair(setOfEltList, setOfNodes)); + //--------------------------------------------------------------------- + // Remap nodes + //--------------------------------------------------------------------- + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mesh->mElements[i] != NULL) + { + mesh->mElements[i]->remap(setOfNodes); + } + } + + //--------------------------------------------------------------------- + // Build families + //--------------------------------------------------------------------- + MULTIPR_LOG("Build fam.:" << endl); + // get families of nodes + { + set<med_int> famOfNodes = mesh->mNodes->getSetOfFamilies(); + for (set<med_int>::iterator itFam = famOfNodes.begin() ; itFam != famOfNodes.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + Family* famDest = famSrc->extractGroup(pGroup->getName().c_str()); + mesh->mFamilies.push_back(famDest); + } + } + + // get families of elements + { + set<med_int> famOfElt; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mesh->mElements[i] != NULL) + { + set<med_int> curSetOfFamilies = mesh->mElements[i]->getSetOfFamilies(); + famOfElt.insert(curSetOfFamilies.begin(), curSetOfFamilies.end()); + } + } + for (set<med_int>::iterator itFam = famOfElt.begin() ; itFam != famOfElt.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + Family* famDest = famSrc->extractGroup(pGroup->getName().c_str()); + mesh->mFamilies.push_back(famDest); + } + } + + MULTIPR_LOG("Finalize:"); + + // fill families with elements and build groups + mesh->finalizeFamiliesAndGroups(); + + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Build profils. + //--------------------------------------------------------------------- + for (std::vector<Profil*>::iterator it = mProfils.begin(); it != mProfils.end(); ++it) + { + Profil* lProfil = new Profil(); + lProfil->create((*it)->getName()); + std::set<med_int> lSet; + if ((*it)->getBinding() == OnNodes) + { + (*it)->extractSetOfElement(setOfNodes, lSet); + } + else + { + (*it)->extractSetOfElement(setOfEltList[lProfil->getGeomIdx()], lSet); + } + if (lSet.size() == 0) + { + delete lProfil; + continue; + } + lProfil->set(lSet); + mesh->mProfils.push_back(lProfil); + } + + //--------------------------------------------------------------------- + // Create new fields and collect Gauss + //--------------------------------------------------------------------- + // for each field + set<string> newSetOfGauss; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + Field* newField; + if (currentField->isFieldOnNodes()) + { + newField = currentField->extractSubSet(setOfNodes); + } + else + { + if (setOfEltList[currentField->getGeomIdx()].size() != 0) + { + newField = currentField->extractSubSet(setOfEltList[currentField->getGeomIdx()]); + } + } + + if (!newField->isEmpty()) + { + mesh->mFields.push_back(newField); + newField->getSetOfGaussLoc(newSetOfGauss); + } + } + // Get gauss locs for optimized fields reading. + if (mFields.size() == 0) + { + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + const string& gaussLocName = mGaussLoc[itGaussLoc]->getName(); + + if (gaussLocName.length() != 0) + { + newSetOfGauss.insert(gaussLocName); + } + } + } + MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); + + //--------------------------------------------------------------------- + // Build Gauss infos + //--------------------------------------------------------------------- + for (set<string>::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) + { + const string& keyName = (*itSet); + + GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); + if (gaussLoc != NULL) + { + GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); + mesh->mGaussLoc.push_back(copyGaussLoc); + mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); + } + } + + //--------------------------------------------------------------------- + // Compute bbox + //--------------------------------------------------------------------- + mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); + + return mesh; +} + + +Mesh* Mesh::createFromFamily(const Family* pFamily, const char* pNewMeshName) +{ + if (pFamily == NULL) throw NullArgumentException("pFamily should not be NULL", __FILE__, __LINE__); + if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName should not be NULL", __FILE__, __LINE__); + if (strlen(pNewMeshName) > MED_TAILLE_NOM) + { + char msg[256]; + sprintf(msg, "pNewMeshName length (=%d) too long: max size allowed is %d", strlen(pNewMeshName), MED_TAILLE_NOM); + throw IllegalArgumentException(msg, __FILE__, __LINE__); + } + //--------------------------------------------------------------------- + // Create a new mesh + //--------------------------------------------------------------------- + Mesh* mesh = new Mesh(); + + //--------------------------------------------------------------------- + // Build name of the new mesh + //--------------------------------------------------------------------- + strcpy(mesh->mMeshName, pNewMeshName); + + MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); + + //--------------------------------------------------------------------- + // Fill general infos + //--------------------------------------------------------------------- + strcpy(mesh->mMeshUName, mMeshUName); + strcpy(mesh->mMeshDesc, mMeshDesc); + + mesh->mMeshDim = mMeshDim; + mesh->mMeshType = mMeshType; + + MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); + MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); + MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); + MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); + + //--------------------------------------------------------------------- + // Build nodes and elements + //--------------------------------------------------------------------- + // Get all elements involved + std::set< med_int>* setOfEltList = new std::set< med_int>[eMaxMedMesh]; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i] != NULL) + { + const set<med_int> setOfElt = pFamily->getSetOfElt((eMeshType)i); + mesh->mElements[i] = mElements[i]->extractSubSet(setOfElt); + setOfEltList[i] = setOfElt; + } + } + + // Get all nodes involved + // The nodes a common for all elements so we don't need to store them separately. + set<med_int> setOfNodes; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mesh->mElements[i] != NULL) + { + const set<med_int>& curSetOfNodes = mesh->mElements[i]->getSetOfNodes(); + setOfNodes.insert(curSetOfNodes.begin(), curSetOfNodes.end()); + } + } + mesh->mNodes = mNodes->extractSubSet(setOfNodes); + + // We need this for the optimized memory management. + this->mGaussIndex.push_back(IndexPair(setOfEltList, setOfNodes)); + //--------------------------------------------------------------------- + // Remap nodes + //--------------------------------------------------------------------- + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mesh->mElements[i] != NULL) + { + mesh->mElements[i]->remap(setOfNodes); + } + } + + //--------------------------------------------------------------------- + // Build families + //--------------------------------------------------------------------- + MULTIPR_LOG("Build fam.:" << endl); + // get families of nodes + Family* lFam = new Family(*pFamily); + mesh->mFamilies.push_back(lFam); + + MULTIPR_LOG("Finalize:"); + + // fill families with elements and build groups + mesh->finalizeFamiliesAndGroups(); + + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Build profils. + //--------------------------------------------------------------------- + for (std::vector<Profil*>::iterator it = mProfils.begin(); it != mProfils.end(); ++it) + { + Profil* lProfil = new Profil(); + lProfil->create((*it)->getName()); + std::set<med_int> lSet; + if ((*it)->getBinding() == OnNodes) + { + (*it)->extractSetOfElement(setOfNodes, lSet); + } + else + { + (*it)->extractSetOfElement(setOfEltList[lProfil->getGeomIdx()], lSet); + } + if (lSet.size() == 0) + { + delete lProfil; + continue; + } + lProfil->set(lSet); + mesh->mProfils.push_back(lProfil); + } + + //--------------------------------------------------------------------- + // Create new fields and collect Gauss + //--------------------------------------------------------------------- + // for each field + set<string> newSetOfGauss; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + Field* newField; + if (currentField->isFieldOnNodes()) + { + newField = currentField->extractSubSet(setOfNodes); + } + else + { + if (setOfEltList[currentField->getGeomIdx()].size() != 0) + { + newField = currentField->extractSubSet(setOfEltList[currentField->getGeomIdx()]); + } + } + + if (!newField->isEmpty()) + { + mesh->mFields.push_back(newField); + newField->getSetOfGaussLoc(newSetOfGauss); + } + } + // Get gauss locs for optimized fields reading. + if (mFields.size() == 0) + { + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + const string& gaussLocName = mGaussLoc[itGaussLoc]->getName(); + + if (gaussLocName.length() != 0) + { + newSetOfGauss.insert(gaussLocName); + } + } + } + MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); + + //--------------------------------------------------------------------- + // Build Gauss infos + //--------------------------------------------------------------------- + for (set<string>::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) + { + const string& keyName = (*itSet); + + GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); + if (gaussLoc != NULL) + { + GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); + mesh->mGaussLoc.push_back(copyGaussLoc); + mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); + } + } + + //--------------------------------------------------------------------- + // Compute bbox + //--------------------------------------------------------------------- + mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); + + return mesh; +} + +Mesh* Mesh::mergePartial(vector<Mesh*> pMeshes, const char* pFieldName, int pFieldIt) +{ + if (pMeshes.size() == 0) throw IllegalArgumentException("list must contain one mesh at least", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Create a new mesh + //--------------------------------------------------------------------- + Mesh* mesh = new Mesh(); + + //--------------------------------------------------------------------- + // Build name of the new mesh + //--------------------------------------------------------------------- + strcpy(mesh->mMeshName, mMeshName); + + //--------------------------------------------------------------------- + // Merge general infos + //--------------------------------------------------------------------- + strcpy(mesh->mMeshUName, mMeshUName); + strcpy(mesh->mMeshDesc, mMeshDesc); + + mesh->mMeshDim = mMeshDim; + mesh->mMeshType = mMeshType; + + //--------------------------------------------------------------------- + // Merge nodes and elements + //--------------------------------------------------------------------- + vector<Nodes*> nodes; + vector<Elements*> elements[eMaxMedMesh]; + vector<int> offsets[eMaxMedMesh]; + + int offset[eMaxMedMesh]; + for (unsigned j = 0; j < eMaxMedMesh; ++j) + { + offset[j] = mNodes->getNumberOfNodes(); + } + + for (unsigned i = 0 ; i < pMeshes.size() ; i++) + { + if (mMeshDim != pMeshes[i]->mMeshDim) throw IllegalStateException("all meshes should have same dimension", __FILE__, __LINE__); + if (mMeshType != pMeshes[i]->mMeshType) throw IllegalStateException("all meshes should have same type", __FILE__, __LINE__); + + + nodes.push_back(pMeshes[i]->mNodes); + for (unsigned j = 0; j < eMaxMedMesh; ++j) + { + + if (pMeshes[i]->mElements[j] != NULL) + { + elements[j].push_back(pMeshes[i]->mElements[j]); + offsets[j].push_back(offset[j]); + } + offset[j] += pMeshes[i]->mNodes->getNumberOfNodes(); + } + } + + mesh->mNodes = mNodes->mergePartial(nodes); + for (unsigned i = 0; i < eMaxMedMesh; ++i) + { + if (elements[i].size() != 0) + { + if (mElements[i] == NULL) + { + mElements[i] = new Elements(CELL_TYPES[i]); + mElements[i]->mergePartial(elements[i].front(), offsets[i].front()); + elements[i].erase(elements[i].begin()); + } + mesh->mElements[i] = mElements[i]->mergePartial(elements[i], offsets[i]); + } + else if (mElements[i] != NULL) + { + mesh->mElements[i] = mElements[i]; + } + } + + + //--------------------------------------------------------------------- + // Merge families + //--------------------------------------------------------------------- + for (unsigned i = 0 ; i < mFamilies.size() ; i++) + { + Family* family = new Family(*(mFamilies[i])); + mesh->mFamilies.push_back(family); + mesh->mFamIdToFam.insert(make_pair(family->getId(), family)); + } + + for (unsigned j = 0 ; j < pMeshes.size() ; j++) + { + for (unsigned i = 0 ; i < pMeshes[j]->mFamilies.size() ; i++) + { + // test if there is a fimaly with the same id + map<med_int, Family*>::iterator itFam = mesh->mFamIdToFam.find(pMeshes[j]->mFamilies[i]->getId()); + + if (itFam == mesh->mFamIdToFam.end()) + { + // id not found: create a new family + Family* family = new Family(*(pMeshes[j]->mFamilies[i])); + mesh->mFamilies.push_back(family); + mesh->mFamIdToFam.insert(make_pair(family->getId(), family)); + } + } + } + + //--------------------------------------------------------------------- + // Merge fields + //--------------------------------------------------------------------- + // for each mesh + + vector<Field*> fields; + for (unsigned i = 0 ; i < pMeshes.size() ; i++) + { + for (std::vector<Field*>::iterator it = pMeshes[i]->mFields.begin(); + it != pMeshes[i]->mFields.end(); ++it) + { + if (strcmp((*it)->getName(), pFieldName) == 0) + { + fields.push_back(*it); + break; + } + } + } + bool hasField = false; + for (std::vector<Field*>::iterator it = mFields.begin(); + it != mFields.end(); ++it) + { + if (strcmp((*it)->getName(), pFieldName) == 0) + { + Field* field = (*it)->merge(fields, pFieldIt); + mesh->mFields.push_back(field); + hasField = true; + break; + } + } + if (hasField == false) + { + Field* lField = fields.back(); + fields.pop_back(); + Field* field = lField->merge(fields, pFieldIt); + mesh->mFields.push_back(field); + } + + //--------------------------------------------------------------------- + // Merge Gauss infos + //--------------------------------------------------------------------- + // WARNING: assume Gauss infos are the same for the two meshes. + for (unsigned i = 0 ; i < mGaussLoc.size() ; i++) + { + GaussLoc* copyGaussLoc = new GaussLoc(*(mGaussLoc[i])); + mesh->mGaussLoc.push_back(copyGaussLoc); + mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); + } + + return mesh; +} + + +MeshDis* Mesh::splitGroupsOfElements() +{ + MeshDis* meshDis = new MeshDis(); + meshDis->setSequentialMEDFilename(mMEDfilename); + + // get prefix from the original MED filename + string strPrefix = removeExtension(mMEDfilename, ".med"); + int numGroup = 1; + int numFam = 1; + + // for each group + for (unsigned itGroup = 0 ; itGroup < mGroups.size() ; itGroup++) + { + Group* currentGroup = mGroups[itGroup]; + + // skip this group if it is a group of nodes + if (currentGroup->isGroupOfNodes()) + { + this->mGaussIndex.push_back(IndexPair()); + continue; + } + + char strPartName[256]; + sprintf(strPartName, "%s_%d", mMeshName, numGroup); + + char strMEDfilename[256]; + char strMedGroup[256]; + int i; + for (i = 0; currentGroup->getName()[i] && currentGroup->getName()[i] != ' '; ++i) + { + strMedGroup[i] = currentGroup->getName()[i]; + } + strMedGroup[i] = '\0'; + sprintf(strMEDfilename, "%s_%s.med", strPrefix.c_str(), strMedGroup); + + Mesh* mesh = createFromGroup(currentGroup, mMeshName); + + // skip the group which contain all the others groups, even if it contains only 1 group + if (mesh->getNumberOfElements() == this->getNumberOfElements()) + { + for (int i = 0; i < eMaxMedMesh; ++i) + { + this->mGaussIndex.back().first[i].clear(); + } + this->mGaussIndex.back().second.clear(); + delete mesh; + mesh = NULL; + continue; + } + meshDis->addMesh( + MeshDisPart::MULTIPR_WRITE_MESH, + mMeshName, + numGroup, + strPartName, + "localhost", + strMEDfilename, + mesh); + + numGroup++; + } + if (mGroups.size() == 0) + { + for (unsigned itFam = 0; itFam < mFamilies.size(); ++itFam) + { + + Family* currentFam = mFamilies[itFam]; + + // skip this family if it is a family of nodes + if (currentFam->isFamilyOfNodes()) + { + this->mGaussIndex.push_back(IndexPair()); + continue; + } + + char strPartName[256]; + sprintf(strPartName, "%s_%d", mMeshName, numGroup); + + char strMEDfilename[256]; + char strMedFam[256]; + int i; + for (i = 0; currentFam->getName()[i] && currentFam->getName()[i] != ' '; ++i) + { + strMedFam[i] = currentFam->getName()[i]; + } + strMedFam[i] = '\0'; + sprintf(strMEDfilename, "%s_%s.med", strPrefix.c_str(), strMedFam); + + Mesh* mesh = createFromFamily(currentFam, mMeshName); + + meshDis->addMesh( + MeshDisPart::MULTIPR_WRITE_MESH, + mMeshName, + numFam, + strPartName, + "localhost", + strMEDfilename, + mesh); + + numFam++; + } + } + + return meshDis; +} + + +Mesh* Mesh::decimate( + const char* pFilterName, + const char* pArgv, + const char* pNameNewMesh) +{ + //--------------------------------------------------------------------- + // Check parameters + //--------------------------------------------------------------------- + if (pFilterName == NULL) throw NullArgumentException("pFilterName should not be NULL", __FILE__, __LINE__); + if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); + if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Instanciate filter used for decimation + //--------------------------------------------------------------------- + DecimationFilter* filter = DecimationFilter::create(pFilterName); + + //--------------------------------------------------------------------- + // Create new mesh by decimating current one + //--------------------------------------------------------------------- + Mesh* decimatedMesh = filter->apply(this, pArgv, pNameNewMesh); + + //--------------------------------------------------------------------- + // Cleans + //--------------------------------------------------------------------- + delete filter; + + return decimatedMesh; +} + + + +void Mesh::getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector<PointOfField>& pPoints, eMeshType pGeomType) +{ + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + if (pField == NULL) throw NullArgumentException("field should not be NULL", __FILE__, __LINE__); + if (pTimeStepIt < 1) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__); + + if (mMeshDim != 3) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + if (pField->getType() != MED_FLOAT64) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + if (pField->getNumberOfComponents() != 1) throw UnsupportedOperationException("field have more than 1 component (vectorial field, expected scalar field)", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Get profile + //--------------------------------------------------------------------- + + const std::string& profilName = pField->getProfil(pTimeStepIt); + std::vector<Profil*>::iterator it; + Profil* profile = NULL; + int count = 0; + if (profilName.size() > 0) + { + for (it = mProfils.begin(); it != mProfils.end(); ++it) + { + if ((*it)->getName() == profilName) + { + profile = (*it); + break; + } + } + if (it == mProfils.end()) throw IllegalStateException("Can't find the profile in the mesh.", __FILE__, __LINE__); + + } + + //--------------------------------------------------------------------- + // Collect points + //--------------------------------------------------------------------- + + if (pField->isFieldOnNodes()) + { + //------------------------------------------------------------- + // Case 1: field of nodes + //------------------------------------------------------------- + if (mNodes == NULL) throw IllegalStateException("no nodes in the current mesh", __FILE__, __LINE__); + + // for each node + for (int itNode = 0, size = mNodes->getNumberOfNodes() ; itNode < size ; itNode++) + { + if (profile && profile->find(itNode) == false) + { + continue; + } + // collect coordinates and value of the point + const med_float* coo = mNodes->getCoordinates(itNode); + + const med_float* val = + reinterpret_cast<const med_float*>(pField->getValue(pTimeStepIt, count + 1)); + // add new point + pPoints.push_back(PointOfField(coo[0], coo[1], coo[2], val[0])); + ++count; + } + } + else + { + //------------------------------------------------------------- + // Case 2: field of elements + //------------------------------------------------------------- + + if (mElements[pGeomType] == NULL) throw IllegalStateException("no elements in the current mesh", __FILE__, __LINE__); + + const string& nameGaussLoc = pField->getNameGaussLoc(pTimeStepIt); + GaussLoc* gaussLoc = getGaussLocByName(nameGaussLoc.c_str()); + if (gaussLoc == NULL) throw IllegalStateException("no Gauss localization for these elements", __FILE__, __LINE__); + + int numGauss = pField->getNumberOfGaussPointsByElement(pTimeStepIt); + int size = gaussLoc->getDim() * gaussLoc->getNumGaussPoints(); + med_float* cooGaussPts = new med_float[size]; + + int dim = mElements[pGeomType]->getTypeOfPrimitives() / 100; + //int numNodes = mElements[pGeomType]->getTypeOfPrimitives() % 100; + size = dim * numGauss; + med_float* cooNodes = new med_float[size]; + + // for each elements + for (int itElt = 0, size = mElements[pGeomType]->getNumberOfElements() ; itElt < size ; itElt++) + { + if (profile && profile->find(itElt) == false) + { + continue; + } + // get coordinates of nodes of the current elements + mElements[pGeomType]->getCoordinates(itElt, mNodes, cooNodes, numGauss); + + // compute coordinates of gauss points + gaussLoc->getCoordGaussPoints(cooNodes, cooGaussPts, numGauss); + + const med_float* val = + reinterpret_cast<const med_float*>(pField->getValue(pTimeStepIt, count + 1)); + + // for each point of Gauss of the element + med_float* srcCoo = cooGaussPts; + for (int itPtGauss = 0 ; itPtGauss < numGauss ; itPtGauss++) + { + pPoints.push_back(PointOfField(srcCoo[0], srcCoo[1], srcCoo[2], val[itPtGauss])); + srcCoo += 3; + } + ++count; + } + + delete[] cooNodes; + delete[] cooGaussPts; + } +} + + +float Mesh::evalDefaultRadius(int pN) const +{ + if (mFields.size() == 0) return 1.0f; + + //--------------------------------------------------------------------- + // Compute default radius + //--------------------------------------------------------------------- + + med_float volumeBBox = + (mMeshBBoxMax[0] - mMeshBBoxMin[0]) * + (mMeshBBoxMax[1] - mMeshBBoxMin[1]) * + (mMeshBBoxMax[2] - mMeshBBoxMin[2]); + + if (isnan(volumeBBox)) + { + return 1.0f; + } + + const med_float k = 0.8; // considered 80% of the volume + + // get number of gauss points in the field + try + { + Field* anyField = mFields[mFields.size()-1]; + int numTimeSteps = anyField->getNumberOfTimeSteps(); + + int numGaussPoints = getNumberOfElements() * anyField->getNumberOfGaussPointsByElement(numTimeSteps-1); + + med_float radius = med_float(pow( (3.0/4.0) * pN * k * volumeBBox / (3.1415 * numGaussPoints), 1.0/3.0)); + + return float(radius); + } + catch (...) + { + return 1.0f; + } +} + +void Mesh::_openMEDFile(const char* pMEDfilename, med_mode_acces pMEDModeAccess) +{ + reset(); + + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + MULTIPR_LOG("Check arguments: "); + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + strncpy(mMEDfilename, pMEDfilename, 256); + + //--------------------------------------------------------------------- + // Open MED file (READ_ONLY) + //--------------------------------------------------------------------- + MULTIPR_LOG("Open MED file: "); + mMEDfile = MEDouvrir(mMEDfilename, pMEDModeAccess); + if (mMEDfile <= 0) throw FileNotFoundException("MED file not found", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Check valid HDF format + //--------------------------------------------------------------------- + MULTIPR_LOG("Format HDF: "); + if (MEDformatConforme(mMEDfilename) != 0) throw IOException("invalid file", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Get MED version + //--------------------------------------------------------------------- + MULTIPR_LOG("MED version: "); + med_int verMajor, verMinor, verRelease; + med_err ret = MEDversionLire(mMEDfile, &verMajor, &verMinor, &verRelease); + if (ret != 0) throw IOException("error while reading MED version", __FILE__, __LINE__); + MULTIPR_LOG(verMajor << "." << verMinor << "." << verRelease << ": OK\n"); + } + + +void Mesh::_readSequentialMED(const char* pMeshName, bool pReadFields) +{ + med_err ret = 1; + + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + MULTIPR_LOG("Check arguments: "); + if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + strncpy(mMeshName, pMeshName, MED_TAILLE_NOM); + + //--------------------------------------------------------------------- + // Read profils + //--------------------------------------------------------------------- + MULTIPR_LOG("Profils: "); + med_int nbProfils = MEDnProfil(mMEDfile); + for (med_int i = 1; i <= nbProfils; ++i) + { + Profil* profil = new Profil(); + profil->readMED(mMEDfile, i); + profil->readProfilBinding(mMEDfile, const_cast<char*>(pMeshName)); + this->mProfils.push_back(profil); + } + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Read all Gauss localizations + //--------------------------------------------------------------------- + MULTIPR_LOG("Gauss localizations: "); + readGaussLoc(); + + //--------------------------------------------------------------------- + // Read scalars (should be 0) + //--------------------------------------------------------------------- + MULTIPR_LOG("Scalars: "); + med_int nbScalars = MEDnScalaire(mMEDfile); + if (nbScalars != 0) throw UnsupportedOperationException("scalars information not yet implemented", __FILE__, __LINE__); + MULTIPR_LOG(nbScalars << ": OK\n"); + + //--------------------------------------------------------------------- + // Find the mesh + //--------------------------------------------------------------------- + // read number of meshes + MULTIPR_LOG("Num meshes: "); + med_int nbMeshes = MEDnMaa(mMEDfile); + if (nbMeshes <= 0) throw IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); + MULTIPR_LOG(nbMeshes << ": OK\n"); + + med_int meshIndex = -1; + // iteration over mesh to find the mesh we want + // for each mesh in the file (warning: first mesh is number 1) + for (int itMesh = 1 ; itMesh <= nbMeshes ; itMesh++) + { + char meshName[MED_TAILLE_NOM + 1]; + + ret = MEDmaaInfo( + mMEDfile, + itMesh, + meshName, + &mMeshDim, + &mMeshType, + mMeshDesc); + + if (ret != 0) throw IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); + MULTIPR_LOG("Mesh: |" << meshName << "|"); + + // test if the current mesh is the mesh we want + if (strcmp(pMeshName, meshName) == 0) + { + // *** mesh found *** + MULTIPR_LOG(" OK (found)\n"); + meshIndex = itMesh; + break; + } + else + { + // not the mesh we want: skip this mesh + MULTIPR_LOG(" skipped\n"); + } + } + + if (meshIndex == -1) + { + throw IllegalStateException("mesh not found in the given MED file", __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Check mesh validity + //--------------------------------------------------------------------- + // dimension of the mesh must be 3 (= 3D mesh) + MULTIPR_LOG("Mesh is 3D: "); + if (mMeshDim != 3) throw UnsupportedOperationException("dimension of the mesh should be 3; other dimension not yet implemented", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + // mesh must not be a grid + MULTIPR_LOG("Mesh is not a grid: "); + if (mMeshType != MED_NON_STRUCTURE) + throw UnsupportedOperationException("grid not supported", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + med_connectivite connectivite = MED_NOD; // NODAL CONNECTIVITY ONLY + // Read all the supported geometry type. + for (int itCell = 0; itCell < eMaxMedMesh ; ++itCell) + { + med_int meshNumCells = MEDnEntMaa( + mMEDfile, + mMeshName, + MED_CONN, + MED_MAILLE, + CELL_TYPES[itCell], + connectivite); + + + //--------------------------------------------------------------------- + // Read elements + //--------------------------------------------------------------------- + if (meshNumCells > 0) + { + mElements[itCell] = new Elements(); + mElements[itCell]->readMED(mMEDfile, mMeshName, mMeshDim, MED_MAILLE, CELL_TYPES[itCell]); + } + } + // everything is OK... + + //--------------------------------------------------------------------- + // Check num joint = 0 + //--------------------------------------------------------------------- + MULTIPR_LOG("Num joints: "); + med_int numJoints = MEDnJoint(mMEDfile, mMeshName); + MULTIPR_LOG(numJoints << ": OK\n"); + + //--------------------------------------------------------------------- + // Check num equivalence = 0 + //--------------------------------------------------------------------- + MULTIPR_LOG("Num equivalences: "); + med_int numEquiv = MEDnEquiv(mMEDfile, mMeshName); + MULTIPR_LOG(numEquiv << ": OK\n"); + + //--------------------------------------------------------------------- + // Read nodes + //--------------------------------------------------------------------- + mNodes = new Nodes(); + mNodes->readMED(mMEDfile, mMeshName, mMeshDim); + mNodes->getBBox(mMeshBBoxMin, mMeshBBoxMax); + + if (mNodes->getNumberOfNodes() != 0) + { + + //--------------------------------------------------------------------- + // Read families + //--------------------------------------------------------------------- + readFamilies(); + finalizeFamiliesAndGroups(); + + //--------------------------------------------------------------------- + // Read fields + //--------------------------------------------------------------------- + if (pReadFields) + { + readFields(); + } + } + + //--------------------------------------------------------------------- + // Close the MED file + //--------------------------------------------------------------------- + MULTIPR_LOG("Close MED file: "); + ret = MEDfermer(mMEDfile); + if (ret != 0) throw IOException("i/o error while closing MED file", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); +} + + +void Mesh::readSequentialMED(const char* pMEDfilename, const char* pMeshName, bool pReadFields) +{ + _openMEDFile(pMEDfilename); + _readSequentialMED(pMeshName, pReadFields); +} + + +void Mesh::readSequentialMED(const char* pMEDfilename, med_int pMeshNumber, bool pReadFields) +{ + _openMEDFile(pMEDfilename); + + //--------------------------------------------------------------------- + // Find the mesh + //--------------------------------------------------------------------- + // read number of meshes + MULTIPR_LOG("Num meshes: "); + med_int nbMeshes = MEDnMaa(mMEDfile); + if (nbMeshes <= 0) throw IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); + MULTIPR_LOG(nbMeshes << ": OK\n"); + + med_int meshDim; + med_maillage meshType; + char meshDesc[MED_TAILLE_DESC + 1]; + char meshName[MED_TAILLE_NOM + 1]; + + med_err ret = MEDmaaInfo(mMEDfile, pMeshNumber, meshName, &meshDim, &meshType, meshDesc); + if (ret != 0) throw IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); + + _readSequentialMED(meshName, pReadFields); +} + + +void Mesh::writeMED(const char* pMEDfilename) +{ + writeMED(pMEDfilename, getName()); +} + + +void Mesh::writeMED(const char* pMEDfilename, const char* pMeshName) +{ + bool noMesh = true; + MULTIPR_LOG("Write MED: " << pMEDfilename << endl); + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (strlen(pMEDfilename) == 0) throw IllegalArgumentException("pMEDfilename size is 0", __FILE__, __LINE__); + + if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); + if (strlen(pMeshName) == 0) throw IllegalArgumentException("pMeshName size is 0", __FILE__, __LINE__); + + remove(pMEDfilename); + + char aMeshName[MED_TAILLE_NOM + 1]; + strncpy(aMeshName, pMeshName, MED_TAILLE_NOM); + + //--------------------------------------------------------------------- + // Create the new MED file (WRITE_ONLY) + //--------------------------------------------------------------------- + med_idt newMEDfile = MEDouvrir(const_cast<char*>(pMEDfilename), MED_CREATION); + if (newMEDfile == -1) throw IOException("", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Write scalars + //--------------------------------------------------------------------- + // no scalars to write + + //--------------------------------------------------------------------- + // Create mesh: must be created first + //--------------------------------------------------------------------- + med_err ret = MEDmaaCr( + newMEDfile, + aMeshName, + mMeshDim, + MED_NON_STRUCTURE, + mMeshDesc); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + MULTIPR_LOG(" Create mesh: |" << aMeshName << "|: OK" << endl); + + //--------------------------------------------------------------------- + // Write nodes and elements (mesh must exist) + //--------------------------------------------------------------------- + if (mNodes == NULL) throw IllegalStateException("mNodes should not be NULL", __FILE__, __LINE__); + mNodes->writeMED(newMEDfile, aMeshName); + MULTIPR_LOG(" Write nodes: ok" << endl); + + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (mElements[i] != NULL) + { + noMesh = false; + mElements[i]->writeMED(newMEDfile, aMeshName, mMeshDim); + } + } + if (noMesh == true) + { + //throw IllegalStateException("No mesh writen.", __FILE__, __LINE__); + return ; + } + + MULTIPR_LOG(" write elt: ok" << endl); + + //--------------------------------------------------------------------- + // Write families (mesh must exist) + //--------------------------------------------------------------------- + // MED assume there is a family 0 in the file. + bool createFamZero = true; + for(std::vector<Family*>::iterator it = mFamilies.begin(); + it != mFamilies.end(); ++it) + { + if ((*it)->getId() == 0) + { + createFamZero = false; + break; + } + } + if (createFamZero) + { + Family famZero; + famZero.setId(0); + strcpy(const_cast<char*>(famZero.getName()), "FAMILLE_ZERO"); + famZero.writeMED(newMEDfile, aMeshName); + } + + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; ++itFam) + { + Family* fam = mFamilies[itFam]; + fam->writeMED(newMEDfile, aMeshName); + } + MULTIPR_LOG(" Write families: ok" << endl); + + //--------------------------------------------------------------------- + // Write profil + //--------------------------------------------------------------------- + for (unsigned itProf = 0; itProf < mProfils.size(); ++itProf) + { + Profil* prof = mProfils[itProf]; + prof->writeMED(newMEDfile); + } + + //--------------------------------------------------------------------- + // Write Gauss localization (must be written before fields) + //--------------------------------------------------------------------- + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; + itGaussLoc++) + { + GaussLoc* gaussLoc = mGaussLoc[itGaussLoc]; + gaussLoc->writeMED(newMEDfile); + } + + MULTIPR_LOG(" Write Gauss: ok" << endl); + + //--------------------------------------------------------------------- + // Write fields + //--------------------------------------------------------------------- + std::set<std::string> fieldNameList; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* field = mFields[itField]; + if (fieldNameList.find(std::string(field->getName())) != fieldNameList.end()) + { + field->writeMED(newMEDfile, aMeshName, false); + } + else + { + fieldNameList.insert(std::string(field->getName())); + field->writeMED(newMEDfile, aMeshName); + } + } + + MULTIPR_LOG(" Write fields: ok" << endl); + + //--------------------------------------------------------------------- + // Close the new MED file + //--------------------------------------------------------------------- + ret = MEDfermer(newMEDfile); + if (ret != 0) throw IOException("", __FILE__, __LINE__); +} + +void Mesh::readGaussLoc() +{ + MULTIPR_LOG("Gauss ref: "); + med_int numGauss = MEDnGauss(mMEDfile); + if (numGauss < 0) throw IOException("", __FILE__, __LINE__); + MULTIPR_LOG(numGauss << ": OK\n"); + + for (int itGauss = 1 ; itGauss <= numGauss ; itGauss++) + { + GaussLoc* gaussLoc = new GaussLoc(); + gaussLoc->readMED(mMEDfile, itGauss); + MULTIPR_LOG((*gaussLoc) << endl); + mGaussLoc.push_back(gaussLoc); + mGaussLocNameToGaussLoc.insert(make_pair(gaussLoc->getName(), gaussLoc)); + } +} + +void Mesh::readFamilies() +{ + med_int numFamilies = MEDnFam(mMEDfile, mMeshName); + if (numFamilies <= 0) throw IOException("", __FILE__, __LINE__); + + for (int itFam = 1 ; itFam <= numFamilies ; ++itFam) + { + Family* fam = new Family(); + fam->readMED(mMEDfile, mMeshName, itFam); + mFamilies.push_back(fam); + } +} + + +void Mesh::finalizeFamiliesAndGroups() +{ + if (mFamilies.size() == 0) + { + return ; + } + //--------------------------------------------------------------------- + // Build mapping between family id and pointers towards families + //--------------------------------------------------------------------- + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; ++itFam) + { + Family* fam = mFamilies[itFam]; + mFamIdToFam.insert(make_pair(fam->getId(), fam)); + } + //--------------------------------------------------------------------- + // Fill families of nodes + //--------------------------------------------------------------------- + for (int itNode = 1 ; itNode <= mNodes->getNumberOfNodes() ; ++itNode) + { + // get family of the ith nodes + int famIdent = mNodes->getFamIdent(itNode - 1); // MED nodes start at 1 + + map<med_int, Family*>::iterator itFam = mFamIdToFam.find(famIdent); + + if (itFam == mFamIdToFam.end()) + { + char msg[256]; + sprintf(msg, "wrong family of nodes for node #%d: family %d not found", itNode, famIdent); + throw IllegalStateException(msg, __FILE__, __LINE__); + } + + Family* fam = (*itFam).second; + + // add the current node to its family + fam->insertElt(itNode); + fam->setIsFamilyOfNodes(true); + } + //--------------------------------------------------------------------- + // Fill families of elements + //--------------------------------------------------------------------- + for (int itMesh = 0; itMesh < eMaxMedMesh; ++itMesh) + { + if (mElements[itMesh] != NULL) + { + for (int itElt = 1 ; itElt <= mElements[itMesh]->getNumberOfElements() ; itElt++) + { + // get family of the ith element (MED index start at 1) + int famIdent = mElements[itMesh]->getFamilyIdentifier(itElt - 1); + + map<med_int, Family*>::iterator itFam = mFamIdToFam.find(famIdent); + + if (itFam == mFamIdToFam.end()) + { + char msg[256]; + sprintf(msg, "wrong family of elements for element #%d: family %d not found", itElt, famIdent); + throw IllegalStateException(msg, __FILE__, __LINE__); + } + + Family* fam = (*itFam).second; + + // add the current element to its family + fam->insertElt( itElt, (eMeshType)itMesh); + fam->setIsFamilyOfNodes(false); + } + } + } + //--------------------------------------------------------------------- + // Build groups + //--------------------------------------------------------------------- + // for each family + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) + { + mFamilies[itFam]->buildGroups(mGroups, mGroupNameToGroup); + } +} + + +void Mesh::readFields() +{ + //--------------------------------------------------------------------- + // Read number of fields + //--------------------------------------------------------------------- + MULTIPR_LOG("Read fields: "); + med_int numFields = MEDnChamp(mMEDfile, 0); + if (numFields <= 0) throw IOException("", __FILE__, __LINE__); + MULTIPR_LOG(numFields << ": OK\n"); + + //--------------------------------------------------------------------- + // Iterate over fields + //--------------------------------------------------------------------- + // for each field, read number of components and others infos + for (int itField = 1 ; itField <= numFields ; itField++) + { + for (int i = 0; i < eMaxMedMesh; ++i) + { + Field* field = new Field(); + field->readMED(mMEDfile, itField, mMeshName, CELL_TYPES[i]); + + // if the nth field does not apply on our mesh => slip it + if (field->isEmpty()) + { + delete field; + } + else + { + mFields.push_back(field); + // ReadMed will always work with fields on node so we need to stop the first time. + // ie : CELL_TYPES[i] is not used in this case. + if (field->isFieldOnNodes()) + { + break; + } + } + } + } +} + + +ostream& operator<<(ostream& pOs, Mesh& pM) +{ + pOs << "Mesh: " << endl; + pOs << " MED file =|" << pM.mMEDfilename << "|" << endl; + pOs << " Name =|" << pM.mMeshName << "|" << endl; + pOs << " Unv name =|" << pM.mMeshUName << "|" << endl; + pOs << " Desc =|" << pM.mMeshDesc << "|" << endl; + pOs << " Dim =" << pM.mMeshDim << endl; + pOs << " Type =" << ((pM.mMeshType == MED_STRUCTURE)?"STRUCTURE":"NON_STRUCTURE") << endl; + pOs << " BBox =[" << pM.mMeshBBoxMin[0] << " ; " << pM.mMeshBBoxMax[0] << "] x [" << pM.mMeshBBoxMin[1] << " ; " << pM.mMeshBBoxMax[1] << "] x [" << pM.mMeshBBoxMin[2] << " ; " << pM.mMeshBBoxMax[2] << "]" << endl; + + int numFamOfNodes = 0; + for (unsigned i = 0 ; i < pM.mFamilies.size() ; i++) + { + if (pM.mFamilies[i]->isFamilyOfNodes()) + { + numFamOfNodes++; + } + } + + int numGroupsOfNodes = 0; + for (unsigned i = 0 ; i < pM.mGroups.size() ; i++) + { + if (pM.mGroups[i]->isGroupOfNodes()) + { + numGroupsOfNodes++; + } + } + + if (pM.mFlagPrintAll) + { + cout << (*(pM.mNodes)) << endl; + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (pM.mElements[i] != NULL) + { + cout << (*(pM.mElements[i])) << endl; + } + } + + pOs << " Families : #=" << pM.mFamilies.size() << " (nodes=" << numFamOfNodes << " ; elements=" << (pM.mFamilies.size() - numFamOfNodes) << ")" << endl; + for (unsigned i = 0 ; i < pM.mFamilies.size() ; i++) + { + cout << (*(pM.mFamilies[i])) << endl; + } + + pOs << " Groups : #=" << pM.mGroups.size() << " (nodes=" << numGroupsOfNodes << " ; elements=" << (pM.mGroups.size() - numGroupsOfNodes) << ")" << endl; + for (unsigned i = 0 ; i < pM.mGroups.size() ; i++) + { + cout << (*(pM.mGroups[i])) << endl; + } + + pOs << " Gauss loc: #=" << pM.mGaussLoc.size() << endl; + for (unsigned i = 0 ; i < pM.mGaussLoc.size() ; i++) + { + cout << (*(pM.mGaussLoc[i])) << endl; + } + + pOs << " Fields : #=" << pM.mFields.size() << endl; + for (unsigned i = 0 ; i < pM.mFields.size() ; i++) + { + cout << (*(pM.mFields[i])) << endl; + } + } + else + { + if (pM.mNodes != NULL) + { + pOs << " Nodes : #=" << pM.mNodes->getNumberOfNodes() << endl; + } + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (pM.mElements[i] != NULL) + { + const set<med_int>& setOfNodes = pM.mElements[i]->getSetOfNodes(); + if (setOfNodes.size() == 0) + { + pOs << " Elt : #=" << pM.mElements[i]->getNumberOfElements() << endl; + } + else + { + set<med_int>::iterator itNode = setOfNodes.end(); + itNode--; + pOs << " Elt : #=" << pM.mElements[i]->getNumberOfElements() << " node_id_min=" << (*(setOfNodes.begin())) << " node_id_max=" << (*itNode) << endl; + } + } + } + pOs << " Families : #=" << pM.mFamilies.size() << " (nodes=" << numFamOfNodes << " ; elements=" << (pM.mFamilies.size() - numFamOfNodes) << ")" << endl; + pOs << " Groups : #=" << pM.mGroups.size() << " (nodes=" << numGroupsOfNodes << " ; elements=" << (pM.mGroups.size() - numGroupsOfNodes) << ")" << endl; + pOs << " Gauss loc: #=" << pM.mGaussLoc.size() << endl; + pOs << " Fields : #=" << pM.mFields.size() << endl; + } + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Mesh.hxx b/src/MULTIPR/MULTIPR_Mesh.hxx new file mode 100755 index 000000000..72d75a1ec --- /dev/null +++ b/src/MULTIPR/MULTIPR_Mesh.hxx @@ -0,0 +1,510 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Mesh.hxx + * + * \brief Class Mesh used by the MULTIPR API; used to wrap MED file meshes. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_MESH_HXX +#define MULTIPR_MESH_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <iostream> +#include <fstream> +#include <set> +#include <map> +#include <vector> +#include <string> + +#include "MULTIPR_Globals.hxx" + +namespace multipr +{ + +//***************************************************************************** +// Pre-declaration +//***************************************************************************** + +class GaussLoc; +class Profil; +class Nodes; +class Elements; +class Family; +class Field; +class Group; +class MeshDis; +class PointOfField; + +extern const med_geometrie_element CELL_TYPES[MED_NBR_GEOMETRIE_MAILLE]; +extern char CELL_NAMES[MED_NBR_GEOMETRIE_MAILLE][MED_TAILLE_NOM + 1]; +extern const int CELL_NB_NODE[MED_NBR_GEOMETRIE_MAILLE]; + +enum eMeshType +{ + eMED_POINT1, + eMED_SEG2, + eMED_SEG3, + eMED_TRIA3, + eMED_TRIA6, + eMED_QUAD4, + eMED_QUAD8, + eMED_TETRA4, + eMED_TETRA10, + eMED_HEXA8, + eMED_HEXA20, + eMED_PENTA6, + eMED_PENTA15, + eMED_PYRA5, + eMED_PYRA13, + eMaxMedMesh +}; + +//***************************************************************************** +// Class Mesh +//***************************************************************************** + +/** + * Assumes: + * - 3D mesh in a 3D space + * - Unstructured mesh (not a grid) + * - Nodal connectivity + * - Cartesian coordinates system + * Always use FULL_INTERLACE arrays + */ +class Mesh +{ +public: + + /** + * Builds an empty Mesh (default constructor). + */ + Mesh(); + + /** + * Destructor. Removes everything. + */ + ~Mesh(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the name of this Mesh. + * \return the name of this Mesh. + */ + const char* getName() const { return mMeshName; } + + /** + * Returns the groups of this Mesh. + * \return the groups of this Mesh. + */ + std::vector<Group*>* getGroups() { return &mGroups; } + + /** + * Returns the nodes of this Mesh. + * \return the nodes of this Mesh. + */ + const Nodes* getNodes() const { return mNodes; } + + /** + * Returns the elements of this Mesh. + * \param pGeomIdx The index of the geometry. + * \return the elements of this Mesh. + */ + const Elements* getElements(int pGeomIdx) const { return mElements[pGeomIdx]; } + + /** + * Returns the gauss index of the splited meshes. + * Only valid after a call to Mesh::splitGroupsOfElements(). + * \return the elements of this Mesh. + */ + GaussIndexList* editGaussIndex() { return &mGaussIndex; } + + /** + * Returns the name of all the scalar fields. + * \return the name of all the scalar fields. + */ + std::vector<std::string> getNameScalarFields() const; + + /** + * Returns the number of iteration for a given field. + * \return the number of iteration for a given field. + */ + int getTimeStamps(const char* pFieldName) const; + + /** + * Returns a Field from its name; NULL if it does not exist. + * \param pFieldName name of the field to be retrieved. + * \param pGeomType The type of the mesh. + * \return the Field pFieldName of it exists, NULL otherwise. + * \throw NullArgumentException if pFieldName is NULL. + */ + Field* getFieldByName(const char* pFieldName, eMeshType pGeomType = eMaxMedMesh) const; + + /** + * Get the minimum and maximum value of the field. + * \param pFieldName The name of the field. + * \param pMin The mininum value to fill. + * \param pMax The maxinum value to fill. + */ + void getFieldMinMax(const char* pFieldName, float& pMin, float& pMax) const; + + /** + * Returns a GaussLoc from its name; NULL if it does not exist. + * \param pGaussLocName name of the GaussLoc to be retrieved. + * \return the GaussLoc pGaussLocName if it exists, NULL otherwise. + * \throw NullArgumentException if pGaussLocName is NULL. + */ + GaussLoc* getGaussLocByName(const char* pGaussLocName) const; + + /** + * Returns the number of elements for all geometry type (TETRA4 AND HEXA8 AND etc). + * \return the number of elements. + */ + int getNumberOfElements() const; + + /** + * Returns the number of elements for the specified geometry type. + * \param pGeomType The type of geometry (eMED_TETRA4 OR eMED_HEXA20 OR etc) + * \return the number of elements. + */ + int getNumberOfElements(eMeshType pGeomType) const; + + /** + * Add a profile to the mesh. + * \param pProfil The profile to add. + */ + void addProfile(Profil* pProfil) { this->mProfils.push_back(pProfil); } + + /** + * Get the vector of profiles of this mesh. + * \return A vector of profiles (of this mesh...). + */ + std::vector<Profil*>& getProfils() { return mProfils; } + + /** + * Get the profile by its name. + * \param pProfilName The name of the profil to get. + * \return A Profil or NULL. + */ + Profil* getProfil(const std::string pProfilName); + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Creates a Mesh from a subset of its elements (cells). + * \param pSetOfElements subset of elements to keep. + * \param pNewMeshName name of the new Mesh. + * \return a new Mesh which is a restriction of this Mesh to the given set of elements. + * \throw NullArgumentException if pNewMeshName is NULL. + */ + Mesh* createFromSetOfElements(const std::set<med_int>* pSetOfElements, const char* pNewMeshName); + + /** + * Creates a Mesh from one of its group. + * \param pGroup any group of this Mesh. + * \param pNewMeshName name of the new Mesh. + * \return a new Mesh which is a restriction of this Mesh to pGroup. + * \throw NullArgumentException if pGroup or pNewMeshName is NULL. + */ + Mesh* createFromGroup(const Group* pGroup, const char* pNewMeshName); + + /** + * Creates a Mesh from one of its family. + * \param pFamily any family of this Mesh. + * \param pNewMeshName name of the new Mesh. + * \return a new Mesh which is a restriction of this Mesh to pFamily. + * \throw NullArgumentException if pGroup or pNewMeshName is NULL. + */ + Mesh* createFromFamily(const Family* pFamily, const char* pNewMeshName); + + /** + * Creates a Mesh by merging this one with the given one. + * Warning: not all the data are merged (e.g. bounding box if not computed and family/groups are partially filled). + * This method is intended to be used to build mesh for visualization (VISU integration). + * Merge is partial to improve speed. + * \param pMesh any Mesh + * \return a new Mesh which is a the union of this and pMesh. + * \throw NullArgumentException if pGroup or pNewMeshName is NULL. + */ + //Mesh* mergePartial(const Mesh* pMesh); + Mesh* mergePartial(std::vector<Mesh*> pMeshes, const char* pFieldName, int pFieldIt); + + /** + * Creates a distributed mesh (MeshDis) by creating a new mesh for each group of elements in this Mesh. + * \return a distributed mesh from groups of this Mesh. + */ + MeshDis* splitGroupsOfElements(); + + /** + * Creates a new mesh by decimating this one. + * \param pFilterName name of the filter to be used for decimation (e.g. Filtre_GradientMoyen); should not be NULL. + * \param pArgv all the arguments for filtering as a single string. + * \param pNameNewMesh name of the new mesh. + * \return the decimated mesh. + * \throw NullArgumentException if one of the arguments is NULL. + * \throw RuntimeException if any error occurs while decimating data. + */ + Mesh* decimate( + const char* pFilterName, + const char* pArgv, + const char* pNameNewMesh); + + /** + * Gets all the points in a field. Each point has coordinates and a value. + * \param pField any field of this Mesh. + * \param pTimeStepIt time step iteration. + * \param pPoints (out) list of points. + * \param pGeomType Get the points from this type of geometry. If the values are on the node, this parameter is ignored. + * \throw NullArgumentException if pField is NULL. + * \throw IllegalArgumentException if pTimeStepIt is invalid. + */ + void getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector<PointOfField>& pPoints, eMeshType pGeomType); + + /** + * Returns a default value for neighborhood radius. + * Return value is such that, for any point in the field, average number of neighbours is pN. + * \param pN average number of neighbours. + * \return a default value for neighborhood radius; 1.0 if some error occurs. + */ + float evalDefaultRadius(int pN) const; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a Mesh from a sequential MED file. Resets the object before. + * \param pMEDfilename + * \param pMeshName + * \param pReadFields Set this to false to skip field. + * \throw IOException if any i/o error occurs. + */ + void readSequentialMED(const char* pMEDfilename, const char* pMeshName, bool pReadFields = true); + + /** + * Reads a Mesh from a sequential MED file. Resets the object before. + * \param pMEDfilename + * \param pMeshNumber + * \param pReadFields Set this to false to skip field. + * \throw IOException if any i/o error occurs. + */ + void readSequentialMED(const char* pMEDfilename, med_int pMeshNumber, bool pReadFields = true); + + /** + * Writes this Mesh and all related things into a MED file. + * \param pMEDfilename + * \throw IOException if any i/o error occurs. + */ + void writeMED(const char* pMEDfilename); + + /** + * Writes this Mesh and all related things into a MED file. + * \param pMEDfilename + * \param pMeshName + * \throw IOException if any i/o error occurs. + */ + void writeMED(const char* pMEDfilename, const char* pMeshName); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Mesh to the given output stream. + * \param pOs any output stream. + * \param pM any Mesh. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Mesh& pM); + +private: + + /** + * Opens a MED file for the given file name. + * \param pMEDfilename + * \param pMEDModeAccess + * \throw IOException if any i/o error occurs. + */ + void _openMEDFile(const char* pMEDfilename, med_mode_acces pMEDModeAccess = MED_LECTURE); + + /** + * Reads a Mesh from a sequential MED file. Resets the object before. + * \param pMeshName + * \param pReadFields Set this to false to skip field. + * \throw IOException if any i/o error occurs. + */ + void _readSequentialMED(const char* pMeshName, bool pReadFields); + + /** + * Reads all Gauss localizations in the current MED file. + * \throw IOException if an i/o error occurs. + */ + void readGaussLoc(); + + /** + * Reads families in the currentMED file and build groups. + * \throw IOException if an i/o error occurs. + */ + void readFamilies(); + + /** + * Finalizes the constructions of families and groups. + * Fill structures with elements. + */ + void finalizeFamiliesAndGroups(); + + /** + * Reads fields related to this mesh in the current MED file. + * \throw IOException if an i/o error occurs. + */ + void readFields(); + +private: + + /** + * Name of the associated MED file. + */ + char mMEDfilename[256]; + + /** + * MED file handle. + */ + med_idt mMEDfile; + + /** + * Name of this mesh. + */ + char mMeshName[MED_TAILLE_NOM + 1]; + + /** + * Universal name of this mesh. + */ + char mMeshUName[MED_TAILLE_DESC + 1]; + + /** + * Description. + */ + char mMeshDesc[MED_TAILLE_DESC + 1]; + + /** + * Dimension. + */ + med_int mMeshDim; + + /** + * Type of mesh (MED_NON_STRUCTURE or MED_STRUCTURE (=grid)) + */ + med_maillage mMeshType; + + /** + * Axis aligned bounding box of this mesh. + */ + med_float mMeshBBoxMin[3]; + med_float mMeshBBoxMax[3]; + + /** + * All the nodes used by this mesh. + */ + Nodes* mNodes; + + /** + * All the TETRA10 elements used by this mesh. + */ + Elements* mElements[eMaxMedMesh]; + + /** + * Table of families used by this mesh. + */ + std::vector<Family*> mFamilies; + + /** + * Map to retrieve a Family from its id. + */ + std::map<med_int, Family*> mFamIdToFam; + + /** + * Table of groups used by this mesh. + */ + std::vector<Group*> mGroups; + + /** + * Map to retrieve a Group from its name. + */ + std::map<std::string, Group*> mGroupNameToGroup; + + /** + * Table of GaussLoc. + */ + std::vector<GaussLoc*> mGaussLoc; + + /** + * Map to retrieve a Gauss info from its name. + */ + std::map<std::string, GaussLoc*> mGaussLocNameToGaussLoc; + + /** + * Table of fields related to this mesh. + * Number of fields = mFields.size(). + */ + std::vector<Field*> mFields; + + /** + * Table of profils. + */ + std::vector<Profil*> mProfils; + + /** + * Flag to control the behaviour of the stream operator <<. + */ + bool mFlagPrintAll; + + /** + * List of gauss points index for optimized domain split. + */ + GaussIndexList mGaussIndex; + +private: + + // do not allow copy constructor + Mesh(const Mesh&); + + // do not allow copy + Mesh& operator=(const Mesh&); + + // do not allow operator == + bool operator==(const Mesh&); + +}; // class Mesh + + +} // namespace MULTIPR + + +#endif // MULTIPR_MESH_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_MeshDis.cxx b/src/MULTIPR/MULTIPR_MeshDis.cxx new file mode 100755 index 000000000..5eaa381ed --- /dev/null +++ b/src/MULTIPR/MULTIPR_MeshDis.cxx @@ -0,0 +1,1479 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_MeshDis.cxx + * + * \brief see MULTIPR_MeshDis.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_MeshDis.hxx" +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_DecimationFilter.hxx" +#include "MULTIPR_Utils.hxx" +#include "MULTIPR_Globals.hxx" +#include "MULTIPR_API.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_ProgressCallback.hxx" +#include "MULTIPR_Field.hxx" +#include "MULTIPR_Profil.hxx" + +#include "MEDSPLITTER_API.hxx" +#include "MED_Factory.hxx" + +#include <iostream> +#include <fstream> +#include <string> +#include <map> + +// Standard includes for decimation statistics. +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdio.h> + + +using namespace std; + + +namespace multipr +{ + +//***************************************************************************** +// Global variables (exported) +//***************************************************************************** + +// callback used to report progress about a long task (e.g. save to disk) +MULTIPR_ProgressCallback* gProgressCallback = NULL; + +// callback used to report empty meshes +MULTIPR_EmptyMeshCallback* gEmptyMeshCallback = NULL; + + +//***************************************************************************** +// Class MeshDisEntry implementation +//***************************************************************************** + +MeshDisPart::MeshDisPart() +{ + mMesh = NULL; + mCollection = NULL; + mOldCollection = NULL; + + reset(); +} + + +MeshDisPart::~MeshDisPart() +{ + reset(); +} + + +void MeshDisPart::reset() +{ + mToDoOnNextWrite = MULTIPR_UNDEFINED; + + mMeshName[0] = '\0'; + mId = 0; + mPartName[0] = '\0'; + mPath[0] = '\0'; + mMEDFileName[0] = '\0'; + + if (mMesh != NULL) + { + delete mMesh; + mMesh = NULL; + } + + mSplit = 0; + + if (mCollection != NULL) + { + delete mCollection; + mCollection = NULL; + } + + if (mOldCollection != NULL) + { + delete mOldCollection; + mOldCollection = NULL; + } +} + + +const char* MeshDisPart::getMEDFileNameSuffix() const +{ + // Examples: + // "agregat100grains_12pas_groupe97.med" -> "groupe97" + // "agregat100grains_12pas_groupe100_part2.med" -> "groupe100_part2" + // "agregat100grains_12pas_groupe98_gradmoy-low-25.0-0.3.med" -> "groupe98_gradmoy-low-25-0.3" + + string prefix = removeExtension(mMEDFileName, ".med"); + prefix.erase(0, prefix.rfind("groupe")); + return prefix.c_str(); +} + + +void MeshDisPart::create( + OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh) +{ + if (pToDoOnNextWrite == MULTIPR_UNDEFINED) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pId < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pPath == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pMEDFileName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + reset(); + + mToDoOnNextWrite = pToDoOnNextWrite; + strcpy(mMeshName, pMeshName); + mId = pId; + strcpy(mPartName, pPartName); + strcpy(mPath, pPath); + strcpy(mMEDFileName, pMEDFileName); + mMesh = pMesh; +} + + +void MeshDisPart::readMED() +{ + if (mMesh != NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mOldCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__); + + mMesh = new Mesh(); + mMesh->readSequentialMED(mMEDFileName, mMeshName); +} + + +ostream& operator<<(ostream& pOs, MeshDisPart& pM) +{ + switch (pM.mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_UNDEFINED: + pOs << "undefined"; + break; + + case MeshDisPart::MULTIPR_KEEP_AS_IT: + pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName; + break; + + case MeshDisPart::MULTIPR_WRITE_MESH: + pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName; + break; + + case MeshDisPart::MULTIPR_WRITE_PARTS: + pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName << " SPLIT " << pM.mSplit; + break; + + default: throw IllegalStateException("", __FILE__, __LINE__); + } + + return pOs; +} + +//***************************************************************************** +// Class TLockProxy implementation +//***************************************************************************** +/* +TLockProxy::TLockProxy (MeshDis* theMeshDis, boost::shared_ptr<boost::mutex> theMutex) + : myMeshDis(theMeshDis), + myMutex(theMutex) +{ + //boost::detail::thread::lock_ops<MeshDis::TMutex>::lock(myMeshDis->myMutex); + boost::detail::thread::lock_ops<boost::mutex>::lock(*myMutex); +} + +TLockProxy::~TLockProxy() +{ + //boost::detail::thread::lock_ops<MeshDis::TMutex>::unlock(myMeshDis->myMutex); + boost::detail::thread::lock_ops<boost::mutex>::unlock(*myMutex); +} + +MeshDis* TLockProxy::operator-> () const // never throws +{ + return myMeshDis; +} +*/ +//***************************************************************************** +// Class MeshDis implementation +//***************************************************************************** + +MeshDis::MeshDis() +{ + reset(); +} + + +MeshDis::~MeshDis() +{ + reset(); +} + + +void MeshDis::reset() +{ + mSequentialMEDFilename[0] = '\0'; + mDistributedMEDFilename[0] = '\0'; + + for (unsigned itPart = 0 ; itPart != mParts.size() ; itPart++) + { + MeshDisPart* part = mParts[itPart]; + delete part; + } + mParts.clear(); + + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + mWriteProgress = 100; +} + + +void MeshDis::setSequentialMEDFilename(const char* pFilename) +{ + strcpy(mSequentialMEDFilename, pFilename); +} + + +void MeshDis::addMesh( + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh) +{ + MeshDisPart* part = new MeshDisPart(); + + part->create( + pToDoOnNextWrite, + pMeshName, + pId, + pPartName, + pPath, + pMEDFileName, + pMesh); + + mParts.push_back(part); +} + + +void MeshDis::insertMesh( + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh, + int pPosition) +{ + MeshDisPart* part = new MeshDisPart(); + + part->create( + pToDoOnNextWrite, + pMeshName, + pId, + pPartName, + pPath, + pMEDFileName, + pMesh); + + mParts.insert(mParts.begin() + pPosition, part); + + // rename id of following parts + for (unsigned i = pPosition + 1 ; i < mParts.size() ; i++) + { + mParts[i]->mId++; + } +} + + +void MeshDis::removeParts(const char* pPrefixPartName) +{ + if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + char strPrefix[256]; + sprintf(strPrefix, "%s_", pPrefixPartName); + + for (vector<MeshDisPart*>::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++) + { + MeshDisPart* currentPart = (*itPart); + + // remove part which have the same name and all sub_parts + // e.g. if pPrefixPartName="PART_4" => remove "PART_4" and "PART_4_*", but not "PART41" + if ((strcmp(currentPart->getPartName(), pPrefixPartName) == 0) || + startsWith(currentPart->getPartName(), strPrefix)) + { + mParts.erase(itPart); + + // decrement id of following parts + for (vector<MeshDisPart*>::iterator itPart2 = itPart ; itPart2 != mParts.end() ; itPart2++) + { + (*itPart2)->mId--; + } + + itPart--; + if (currentPart->mMEDFileName != NULL) + { + remove(currentPart->mMEDFileName); + } + + delete currentPart; + } + } +} + + +MeshDisPart* MeshDis::findPart(const char* pPartName) +{ + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + MeshDisPart* part = NULL; + + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + MeshDisPart* currentPart = mParts[itPart]; + if (strcmp(currentPart->getPartName(), pPartName) == 0) + { + part = currentPart; + break; + } + } + + return part; + +} + + +vector<string> MeshDis::getMeshes() const +{ + vector<string> res; + + if (mParts.size() > 0) + { + MeshDisPart* part = mParts[0]; + const char* meshName = part->getMeshName(); + res.push_back(meshName); + } + + return res; +} + + +vector<string> MeshDis::getFields(const char* pPartList, bool pAddNbGaussPoint) const +{ + vector<string> res; + MeshDisPart* curPart = NULL; + unsigned i, pos, len; + + if (mParts.size() == 0) + { + return res; + } + + // get the right part. + pos = 0; + len = 0; + // Get the next separator. + for (; pPartList[pos+len] && pPartList[pos+len] != '|'; ++len); + // Find the corresponding part. + for (i = 0; i < mParts.size(); ++i) + { + // Avoid a match between MAIL_9 and MAIL_99 + if (len != strlen(mParts[i]->getPartName())) + { + continue; + } + if (strncmp(mParts[i]->getPartName(), &pPartList[pos], len) == 0) + { + curPart = mParts[i]; + } + } + if (curPart == NULL) + { + return res; + } + + // all the parts of the distributed MED file should have the same fields + // => just return the name of fields of the first part + switch (curPart->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + case MeshDisPart::MULTIPR_WRITE_PARTS: + { + vector<pair<string, int> > tmp; + multipr::getListScalarFields(curPart->getMEDFileName(), tmp, + pAddNbGaussPoint, curPart->getMeshName()); + + for (unsigned i = 0 ; i < tmp.size() ; i++) + { + res.push_back(tmp[i].first); + } + return res; + } + + case MeshDisPart::MULTIPR_WRITE_MESH: + return curPart->mMesh->getNameScalarFields(); + + default: + throw IllegalStateException("Don't know what to do now.", __FILE__, __LINE__); + } +} + + +int MeshDis::getTimeStamps(const char* pPartList, const char* pFieldName) const +{ + MeshDisPart* curPart = NULL; + unsigned i, pos, len; + + if (mParts.size() == 0) + { + // no parts in this distributed MED file => no fields => #iteration = 0 + return 0; + } + + // get the right part. + pos = 0; + len = 0; + // Get the next separator. + for (; pPartList[pos+len] && pPartList[pos+len] != '|'; ++len); + // Find the corresponding part. + for (i = 0; i < mParts.size(); ++i) + { + // Avoid a match between MAIL_9 and MAIL_99 + if (len != strlen(mParts[i]->getPartName())) + { + continue; + } + if (strncmp(mParts[i]->getPartName(), &pPartList[pos], len) == 0) + { + curPart = mParts[i]; + } + } + + // all the parts of the distributed MED file should have the same fields + // => just return the number of iteration found in the field of the first part + switch (mParts[0]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + case MeshDisPart::MULTIPR_WRITE_PARTS: + { + vector<pair<string, int> > tmp; + multipr::getListScalarFields(curPart->getMEDFileName(), tmp); + + for (unsigned i = 0 ; i < tmp.size() ; i++) + { + if (strcmp(tmp[i].first.c_str(), pFieldName) == 0) + { + return tmp[i].second; + } + } + + // pFieldName not found in the list of fields + return 0; + } + + case MeshDisPart::MULTIPR_WRITE_MESH: + return mParts[0]->mMesh->getTimeStamps(pFieldName); + + default: + throw IllegalStateException("", __FILE__, __LINE__); + } +} + + +string MeshDis::getPartInfo(const char* pPartName) +{ + MeshDisPart* part = findPart(pPartName); + + if (part != NULL) + { + char num[16]; + sprintf(num, "%d", part->mId); + + string res = + string(part->mMeshName) + + string(" ") + + string(num) + + string(" ") + + string(part->mPartName) + + string(" ") + + string(part->mPath) + + string(" ") + + string(part->mMEDFileName); + + return res; + } + else + { + // part not found => return empty string + return ""; + } +} + + +void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner) +{ + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) + throw IllegalArgumentException("should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Find the MED file corresponding to the given part + //--------------------------------------------------------------------- + MeshDisPart* part = findPart(pPartName); + + if (part == NULL) + { + throw IllegalArgumentException("part not found in this distributed MED file", __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Load the sequential MED file + //--------------------------------------------------------------------- + MEDSPLITTER::MESHCollection* collection = + new MEDSPLITTER::MESHCollection(part->getMEDFileName(), part->getMeshName()); + collection->setDriverType(MEDSPLITTER::MedAscii); + + //--------------------------------------------------------------------- + // Partition the group + //--------------------------------------------------------------------- + MEDSPLITTER::Topology* topology; + if (pPartitionner == MULTIPR_METIS) + { + try + { + topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::METIS); + } + catch (...) + { + throw RuntimeException("MEDSPLITTER error: createPartition(), using METIS", __FILE__, __LINE__); + } + } + else if (pPartitionner == MULTIPR_SCOTCH) + { + try + { + topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::SCOTCH); + } + catch (...) + { + throw RuntimeException("MEDSPLITTER error: createPartition(), using SCOTCH", __FILE__, __LINE__); + } + } + else + { + throw IllegalStateException("unknown partitionner", __FILE__, __LINE__); + } + + try + { + MEDSPLITTER::MESHCollection* newCollection = new MEDSPLITTER::MESHCollection(*collection, topology); + newCollection->setDriverType(MEDSPLITTER::MedAscii); + + part->mToDoOnNextWrite = MeshDisPart::MULTIPR_WRITE_PARTS; + part->mSplit = pNbParts; + part->mOldCollection = collection; + part->mCollection = newCollection; + } + catch (...) + { + throw RuntimeException("MEDSPLITTER error: new MESHCollection()", __FILE__, __LINE__); + } +} + + +std::list<std::string> MeshDis::decimatePart (const char* pPartName, + const char* pFieldName, + med_int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + char stats[512]; + float lowResStat = 0.0f; + float medResStat = 0.0f; + unsigned lowResSize = 0; + unsigned medResSize = 0; + struct stat fileStat; + + fileStat.st_size = 0; + + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + if (pPartName == NULL) + throw NullArgumentException("partname should not be NULL", __FILE__, __LINE__); + if (pFieldName == NULL) + throw NullArgumentException("fieldname should not be NULL", __FILE__, __LINE__); + if (pFieldIt < med_int(1)) + throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__); + if (pFilterParams == NULL) + throw IllegalArgumentException("filterparams should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Find the MED file corresponding to the given part + //--------------------------------------------------------------------- + MeshDisPart* part = findPart(pPartName); + if (part == NULL) + { + throw IllegalArgumentException("part not found in the given distributed MED file", + __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Load the associated sequential MED file + //--------------------------------------------------------------------- + if (part->mMesh == NULL) + { + part->readMED(); + } + + Mesh* meshFull = part->mMesh; + cout << (*meshFull) << endl; + + std::list<std::string> ret; + + const char* originalFilename = part->getMEDFileName(); + string strPrefix = removeExtension(originalFilename, ".med"); + + // debug + //cout << (*this) << endl; + + //--------------------------------------------------------------------- + // Decimates the given mesh + //--------------------------------------------------------------------- + // arguments for decimation are passed as a string for genericity + char argv[256]; + char newPartName[MED_TAILLE_NOM + 1]; + char newMEDFileNameLow[256]; + char newMEDFileNameMed[256]; + float lTMed; + float lTLow; + float lRadius = 0.0f; + int lBoxing = 0; + + // *** create a new mesh = MEDIUM resolution *** + if (strcmp(pFilterName, "Filtre_GradientMoyen") == 0) + { + sscanf(pFilterParams, "%f %f %f %d", &lTMed, &lTLow, &lRadius, &lBoxing); + sprintf(newMEDFileNameMed, "%s_%s-med-%s-%s.med", + strPrefix.c_str(), + "gradmoy", + realToString(lTMed).c_str(), + realToString(lRadius).c_str()); + sprintf(newMEDFileNameLow, "%s_%s-low-%s-%s.med", + strPrefix.c_str(), + "gradmoy", + realToString(lTLow).c_str(), + realToString(lRadius).c_str()); + } + else if (strcmp(pFilterName, "Filtre_Direct") == 0) + { + sscanf(pFilterParams, "%f %f", &lTMed, &lTLow); + sprintf(newMEDFileNameMed, "%s_%s-med-%s.med", + strPrefix.c_str(), + "direct", + realToString(lTMed).c_str()); + sprintf(newMEDFileNameLow, "%s_%s-low-%s.med", + strPrefix.c_str(), + "direct", + realToString(lTLow).c_str()); + } + else + { + throw IllegalArgumentException("Filter not found !", __FILE__, __LINE__); + } + + sprintf(argv, "%s %d %f %f %d", pFieldName, pFieldIt, lTMed, lRadius, lBoxing); + sprintf(newPartName, "%s_MED", pPartName); + { + Mesh* meshMedium = meshFull->decimate(pFilterName, argv, part->getMeshName()); + cout << (*meshMedium) << endl; + if (meshMedium->getNumberOfElements()) + { + medResStat = 1.0f - (float)meshMedium->getNumberOfElements() / (float)meshFull->getNumberOfElements(); + + // We write the file in /tmp to get it's size. + try { + meshMedium->writeMED("/tmp/delete-me.med"); + stat("/tmp/delete-me.med", &fileStat); + medResSize = fileStat.st_size; + remove("/tmp/delete-me.med"); + } + catch (...) + { + medResSize = 0; + } + + insertMesh( + MeshDisPart::MULTIPR_WRITE_MESH, + part->getMeshName(), + part->mId + 1, + newPartName, + "localhost", + newMEDFileNameMed, + meshMedium, + part->mId + 0); + } + else + { + ret.push_back(newPartName); + delete meshMedium; + } + } + + // *** create a new mesh = LOW resolution *** + sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, lTLow, lRadius, lBoxing); + sprintf(newPartName, "%s_LOW", pPartName); + { + Mesh* meshLow = meshFull->decimate(pFilterName, argv, part->getMeshName()); + cout << (*meshLow) << endl; + if (meshLow->getNumberOfElements()) + { + lowResStat = 1.0f - (float)meshLow->getNumberOfElements() / (float)meshFull->getNumberOfElements(); + + // We write the file in /tmp to get it's size. + try { + meshLow->writeMED("/tmp/delete-me.med"); + stat("/tmp/delete-me.med", &fileStat); + lowResSize = fileStat.st_size; + remove("/tmp/delete-me.med"); + } + catch (...) + { + lowResSize = 0; + } + + insertMesh(MeshDisPart::MULTIPR_WRITE_MESH, + part->getMeshName(), + part->mId + 2, + newPartName, + "localhost", + newMEDFileNameLow, + meshLow, + part->mId + 1); + } + else + { + ret.push_back(newPartName); + delete meshLow; + } + } + // We get the original file size. + std::string filename = part->getMEDFileName(); + stat(filename.c_str(), &fileStat); + + snprintf(stats, 512, "Mesh compression : Low resolution=%.1f\%%. Medium resolution=%.1f%%.\nFile compression : Low resolution=%.1f%%. Medium resolution=%.1f%%.", + lowResStat * 100.0f, medResStat * 100.0f, + (1.0f - (float)lowResSize / (float)fileStat.st_size) * 100.0f, + (1.0f - (float)medResSize / (float)fileStat.st_size) * 100.0f); + this->mStats = stats; + + return ret; +} + + +string MeshDis::evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + MeshDisPart* part = findPart(pPartName); + if (part == NULL) + { + return ""; + } + + try + { + if (part->mMesh == NULL) + { + part->readMED(); + } + + multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName); + if (filter == NULL) + { + return ""; + } + + multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter); + + if (filterGrad != NULL) + { + int mode; + + int ret = sscanf(pFilterParams, "%d", &mode); + + // mode 2 = GET RADIUS + if ((ret == 1) && (mode == 2)) + { + double radius = part->mMesh->evalDefaultRadius(8); + char res[256]; + sprintf(res, "%f", radius); + return res; + } + + float radius; + int boxing; + + ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing); + + // mode 1 = GET GRADIENT MIN, MAX and AVG + if ((ret == 3) && (mode == 1)) + { + double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2; + + filterGrad->getGradientInfo( + part->mMesh, + pFieldName, + pFieldIt, + radius, + boxing, + &gradMin, + &gradAvg, + &gradMax); + + char res[2048]; + sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax); + return res; + } + } + + delete filter; + } + catch(...) + { + } + + return ""; +} + + +int MeshDis::computeNumParts() +{ + int numParts = 0; + + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + switch (mParts[itPart]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + case MeshDisPart::MULTIPR_WRITE_MESH: + numParts++; + break; + + case MeshDisPart::MULTIPR_WRITE_PARTS: + numParts += mParts[itPart]->mSplit + 1; + break; + + default: throw IllegalStateException("", __FILE__, __LINE__); + } + } + + return numParts; +} + + +void MeshDis::readDistributedMED(const char* pMEDfilename) +{ + if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__); + + const int MAX_SIZEOF_LINE = 1024; + + reset(); + strcpy(mDistributedMEDFilename, pMEDfilename); + + //--------------------------------------------------------------------- + // Open master file (ASCII file) + //--------------------------------------------------------------------- + ifstream fileMaster(mDistributedMEDFilename); + if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read header + //--------------------------------------------------------------------- + char charbuffer[MAX_SIZEOF_LINE]; + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + + // check format + if ((charbuffer[0] != '#') || + (charbuffer[1] != ' ') || + (charbuffer[2] != 'M') || + (charbuffer[3] != 'E') || + (charbuffer[4] != 'D')) + throw IOException("not a valid distributed MED file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + char* strTag = NULL; + if ((charbuffer[0] == '#') && ((strTag = strstr(charbuffer, "[SOURCE]=")) != NULL)) + { + char strSequentialMEDFilename[256]; + int ret = sscanf(strTag, "[SOURCE]=%s", strSequentialMEDFilename); + if (ret == 1) + { + MED::EVersion aVersion = MED::GetVersionId(strSequentialMEDFilename, true); + if ( aVersion == MED::eVUnknown ) { + std::string aMessage = std::string("source file - '") + strSequentialMEDFilename + "' is not a valid MED file"; + throw IOException( aMessage.c_str(), __FILE__, __LINE__ ); + } + + setSequentialMEDFilename(strSequentialMEDFilename); + } + } + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + } + + // read number of parts + int nbParts = atoi(charbuffer); + + //--------------------------------------------------------------------- + // Read infos about sub-parts + //--------------------------------------------------------------------- + char lMeshName[MED_TAILLE_NOM + 1]; + int lId; + char lPartName[MED_TAILLE_NOM + 1]; + char lPath[256]; + char lMEDFileName[256]; + + for (int i = 0 ; i < nbParts ; i++) + { + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + } + + lMeshName[0] = '\0'; + lId = 0; + lPartName[0] = '\0'; + lPath[0] = '\0'; + lMEDFileName[0] = '\0'; + + int ret = sscanf(charbuffer, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__); + + MED::EVersion aVersion = MED::GetVersionId(lMEDFileName, true); + if ( aVersion == MED::eVUnknown ) { + std::string aMessage = std::string("partition file - '") + lMEDFileName + "' is not a valid MED file" ; + throw IOException( aMessage.c_str(), __FILE__, __LINE__ ); + } + + //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl; + addMesh( + MeshDisPart::MULTIPR_KEEP_AS_IT, + lMeshName, + lId, + lPartName, + lPath, + lMEDFileName, + NULL); + } + + //--------------------------------------------------------------------- + // Close master file + //--------------------------------------------------------------------- + fileMaster.close(); + if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); +} + +void MeshDis::readPersistentDistributedMED(const char* pMEDfilename) +{ + if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__); + + const int MAX_SIZEOF_LINE = 1024; + + reset(); + strcpy(mDistributedMEDFilename, pMEDfilename); + + //--------------------------------------------------------------------- + // Open master file (ASCII file) + //--------------------------------------------------------------------- + ifstream fileMaster(mDistributedMEDFilename); + if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read header + //--------------------------------------------------------------------- + char charbuffer[MAX_SIZEOF_LINE]; + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + + // check format + if ((charbuffer[0] != '#') || + (charbuffer[1] != ' ') || + (charbuffer[2] != 'M') || + (charbuffer[3] != 'E') || + (charbuffer[4] != 'D')) + throw IOException("not a valid distributed MED file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + char* strTag = NULL; + if ((charbuffer[0] == '#') && ((strTag = strstr(charbuffer, "[SOURCE]=")) != NULL)) + { + char strSequentialMEDFilename[256]; + int ret = sscanf(strTag, "[SOURCE]=%s", strSequentialMEDFilename); + if (ret == 1) + { + setSequentialMEDFilename(strSequentialMEDFilename); + } + } + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + } + + // read number of parts + int nbParts = atoi(charbuffer); + + //--------------------------------------------------------------------- + // Read infos about sub-parts + //--------------------------------------------------------------------- + char lMeshName[MED_TAILLE_NOM + 1]; + int lId; + char lPartName[MED_TAILLE_NOM + 1]; + char lPath[256]; + char lMEDFileName[256]; + + for (int i = 0 ; i < nbParts ; i++) + { + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + } + + lMeshName[0] = '\0'; + lId = 0; + lPartName[0] = '\0'; + lPath[0] = '\0'; + lMEDFileName[0] = '\0'; + + int ret = sscanf(charbuffer, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) + throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__); + + // For Persistent (most probably moved) set of files: + // - replace path to the part in <lMEDFileName> by path to the master file. + string masterFilePath = multipr::getPath(pMEDfilename); + string partFileName = multipr::getFilenameWithoutPath(lMEDFileName); + string newMEDFileName = masterFilePath + partFileName; + + //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl; + addMesh(MeshDisPart::MULTIPR_KEEP_AS_IT, + lMeshName, + lId, + lPartName, + lPath, + newMEDFileName.c_str(), // lMEDFileName + NULL); + } + + //--------------------------------------------------------------------- + // Close master file + //--------------------------------------------------------------------- + fileMaster.close(); + if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); +} + +/** + * Retrieves the output of MEDSPLITTER and convert it for MULTIPR. + */ +int convertMedsplitterToMultipr( + ofstream& pFileMaster, + const char* pTmpFilename, + int pId, + MeshDisPart* pPart, + string pDestPath) +{ + MULTIPR_LOG("convert" << endl); + + const int MAX_SIZEOF_LINE = 1024; + char charbuffer[MAX_SIZEOF_LINE]; + + // Open medsplitter master file (ASCII file) + ifstream fileMasterMedsplitter(pTmpFilename); + if (fileMasterMedsplitter.fail()) + throw IOException("i/o error while opening MEDSPLITTER master file", __FILE__, __LINE__); + + fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMasterMedsplitter.fail()) + throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMasterMedsplitter.fail()) + throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__); + } + + // read number of parts + int nbParts = atoi(charbuffer); + //cout << "nb parts=" << nbParts << endl; + + char lMeshName[MED_TAILLE_NOM + 1]; + int lId; + char lPartName[MED_TAILLE_NOM + 1]; + char lPath[256]; + char lMEDFileName[256]; + + for (int i = 0 ; i < nbParts ; i++) + { + fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMasterMedsplitter.fail()) throw IOException("", __FILE__, __LINE__); + + // parses the current line + lMeshName[0] = '\0'; + lId = 0; + lPartName[0] = '\0'; + lPath[0] = '\0'; + lMEDFileName[0] = '\0'; + + int ret = sscanf(charbuffer, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) + throw IOException("i/o error while reading MEDSPLITTER master file; bad format", __FILE__, __LINE__); + + string strDestFilename = pDestPath + multipr::getFilenameWithoutPath(lMEDFileName); + if (strcmp(lMEDFileName, strDestFilename.c_str()) != 0) + { + multipr::copyFile(lMEDFileName, pDestPath.c_str()); + strcpy(lMEDFileName, strDestFilename.c_str()); + } + + pFileMaster << lMeshName << "_" << (i + 1) << " " << (pId + i + 1) + << " " << pPart->getPartName() << "_" << (i + 1) + << " " << lPath << " " << lMEDFileName << endl; + } + + fileMasterMedsplitter.close(); + if (fileMasterMedsplitter.fail()) + throw IOException("i/o error while closing MEDSPLITTER master file", __FILE__, __LINE__); + + // remove master file generated by MEDSPLITTER + remove(pTmpFilename); + + return nbParts + 1; +} + + +void MeshDis::writeDistributedMED (const char* pMEDfilenamePrefix, + bool pIsPersistence) +{ + if (pMEDfilenamePrefix == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Build master filename + //--------------------------------------------------------------------- + string strPrefix = string(pMEDfilenamePrefix); + const char* strExtension = ".med"; + string strMasterFilename; + + // add suffix "_groupes_maitre" iff it is not yet in the filename + if (strstr(pMEDfilenamePrefix, "_groupes_maitre") == 0) + { + strMasterFilename= strPrefix + "_groupes_maitre" + strExtension; + } + else + { + strMasterFilename = strPrefix + strExtension; + } + + string strDestPath = multipr::getPath(strMasterFilename.c_str()); + + MULTIPR_LOG("Create master: " << strMasterFilename << endl); + strcpy(mDistributedMEDFilename, strMasterFilename.c_str()); + + //--------------------------------------------------------------------- + // Create an ASCII master file for the resulting distributed mesh and write header + //--------------------------------------------------------------------- + remove(strMasterFilename.c_str()); + ofstream fileMaster(strMasterFilename.c_str()); + + if (fileMaster == 0) throw IOException("i/o error while creating MED master file", __FILE__, __LINE__); + + fileMaster << "# MED file v2.3 - Master file created by MULTIPR v" << getVersion() << endl; + fileMaster << "#" << " " << endl; + fileMaster << "# [SOURCE]=" << mSequentialMEDFilename << endl; + fileMaster << "#" << " " << endl; + + fileMaster << computeNumParts() << endl; + if (fileMaster.fail()) throw IOException("i/o error while writing MED master file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Create a new MED file (v2.3) + //--------------------------------------------------------------------- + int id = 1; + + if (gProgressCallback != NULL) gProgressCallback->start("Save mesh", mParts.size()); + setProgress(0); + + try + { + // for each sub-meshes + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + switch (mParts[itPart]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + { + string curFilename = mParts[itPart]->getMEDFileName(); + int curId = mParts[itPart]->mId; + + mParts[itPart]->mId = id; + id++; + + // copy file in another directory? + string strSrcPath = multipr::getPath(curFilename.c_str()); + if (strSrcPath != strDestPath) + { + string strDestFilename = strDestPath + + multipr::getFilenameWithoutPath(curFilename.c_str()); + multipr::copyFile(mParts[itPart]->getMEDFileName(), strDestPath.c_str()); + strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str()); + } + + fileMaster << (*mParts[itPart]) << endl; + cout << (*mParts[itPart]) << endl; + + // restore old filename and id in case of persistence + if (pIsPersistence) + { + strcpy(mParts[itPart]->mMEDFileName, curFilename.c_str()); + mParts[itPart]->mId = curId; + } + break; + } + + case MeshDisPart::MULTIPR_WRITE_MESH: + { + if (strlen(mParts[itPart]->getMEDFileName()) == 0) + throw IOException("MED filename should not be empty", __FILE__, __LINE__); + if (mParts[itPart]->mMesh == NULL) + throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__); + + string curFilename = mParts[itPart]->getMEDFileName(); + int curId = mParts[itPart]->mId; + + string strDestFilename = strDestPath + + multipr::getFilenameWithoutPath(curFilename.c_str()); + strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str()); + + mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName()); + mParts[itPart]->mId = id; + id++; + fileMaster << (*mParts[itPart]) << endl; + cout << (*mParts[itPart]) << endl; + + // restore old filename and id in case of persistence + if (pIsPersistence) + { + strcpy(mParts[itPart]->mMEDFileName, curFilename.c_str()); + mParts[itPart]->mId = curId; + } + break; + } + + case MeshDisPart::MULTIPR_WRITE_PARTS: + { + // We need to keep the original file. + fileMaster << (*mParts[itPart]) << endl; + // split this part using medsplitter + if (mParts[itPart]->mOldCollection == NULL) + throw IllegalStateException("collection should not be NULL", __FILE__, __LINE__); + string strPrefix = removeExtension(mParts[itPart]->getMEDFileName(), ".med"); + char tmpFilename[256]; + sprintf(tmpFilename, "%s_part", strPrefix.c_str()); + + // remove previous file + remove(tmpFilename); + for (int i = 1 ; i <= mParts[itPart]->mSplit ; i++) + { + char filename[256]; + sprintf(filename, "%s%d.med", tmpFilename, i); + remove(filename); + } + + mParts[itPart]->mCollection->write(tmpFilename); + mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection)); + int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, + mParts[itPart], strDestPath); + id += ret; + //remove(mParts[itPart]->getMEDFileName()); + break; + } + + default: throw IllegalStateException("should not be there", __FILE__, __LINE__); + } + + if (gProgressCallback != NULL) gProgressCallback->moveOn(); + setProgress((itPart + 1) * 100 / mParts.size()); + } + } + catch (RuntimeException& e) + { + if (gProgressCallback != NULL) gProgressCallback->done(); + setProgress(100); + throw e; + } + + if (gProgressCallback != NULL) gProgressCallback->done(); + setProgress(90); + + //--------------------------------------------------------------------- + // Close master file + //--------------------------------------------------------------------- + fileMaster.close(); + + if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); +} + +void MeshDis::setProgress (int pPercents) +{ + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + mWriteProgress = pPercents; +} + +int MeshDis::getProgress() +{ + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + int ret = mWriteProgress; + return ret; +} + + +void MeshDis::readAndWriteFields (const char* pMeshName, std::vector<Group*>* pGroups, + GaussIndexList* pGaussList, std::vector<Profil*>& pProfils) +{ + med_int lMEDfile, lCurMEDfile; + std::vector<med_int> lFiles; + std::map<std::string, Profil*> lProfilByName; + + // Open the original MED file. + lMEDfile = MEDouvrir(mSequentialMEDFilename, MED_LECTURE); + //--------------------------------------------------------------------- + // Read number of fields + //--------------------------------------------------------------------- + MULTIPR_LOG("Read fields: "); + med_int numFields = MEDnChamp(lMEDfile, 0); + if (numFields <= 0) + throw IOException("error while reading number of fields in the MED file", __FILE__, __LINE__); + MULTIPR_LOG(numFields << ": OK\n"); + + // For each part open the corresponding MED file. + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + lCurMEDfile = MEDouvrir(const_cast<char*>(mParts[itPart]->getMEDFileName()), MED_LECTURE_ECRITURE); + // Keep the files descriptors. + lFiles.push_back(lCurMEDfile); + if (lCurMEDfile == -1) + { + throw IOException("Can't open part med file.", __FILE__, __LINE__); + } + } + + // For easy acces we create an associative container to find the profil by its name. + for (std::vector<Profil*>::iterator it = pProfils.begin(); it != pProfils.end(); ++it) + { + std::string lName = (*it)->getName(); + lProfilByName[lName] = (*it); + } + + //--------------------------------------------------------------------- + // Iterate over fields + //--------------------------------------------------------------------- + // for each field, read and write number of components and others infos + for (int itField = 1 ; itField <= numFields ; ++itField) + { + for (int i = 0; i < eMaxMedMesh; ++i) + { + // Create and read the field. + Field* field = new Field(); + field->readMED(lMEDfile, itField, const_cast<char*>(pMeshName), CELL_TYPES[i]); + // if the nth field does not apply on our mesh => skip it + if (!field->isEmpty()) + { + // Split and write this field in the MED files of the parts. + field->writeMEDOptimized(&mParts, pMeshName, pGaussList, i, lFiles, lProfilByName); + // If this field is on nodes, we dont need to iterate over the geometry types. + if (field->isFieldOnNodes()) + { + delete field; + break; + } + } + delete field; + } + } + // Close all MED files. + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + MEDfermer(lFiles[itPart]); + } +} + +ostream& operator<<(ostream& pOs, MeshDis& pM) +{ + pOs << "Mesh Dis.:" << endl; + pOs << " Sequential filename (source) =|" << pM.mSequentialMEDFilename << "|" << endl; + pOs << " Distributed filename (master)=|" << pM.mDistributedMEDFilename << "|" << endl; + pOs << " #Sub-meshes =" << pM.mParts.size() << endl; + + for (unsigned itPart = 0 ; itPart < pM.mParts.size() ; itPart++) + { + cout << " " << (itPart + 1) << ": " << (*(pM.mParts[itPart])) << endl; + } + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_MeshDis.hxx b/src/MULTIPR/MULTIPR_MeshDis.hxx new file mode 100755 index 000000000..45f76db43 --- /dev/null +++ b/src/MULTIPR/MULTIPR_MeshDis.hxx @@ -0,0 +1,619 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_MeshDis.hxx + * + * \brief Class MeshDis: distributed mesh. + * = MASTER file (ASCII) -> list of sequential MED file. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_MESHDIS_HXX +#define MULTIPR_MESHDIS_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <iostream> +#include <vector> + +// include MEDSPLITTER used to split mesh using METIS or SCOTCH +#include "MEDMEM_define.hxx" +#include "MEDMEM_Mesh.hxx" +#include "MEDMEM_Family.hxx" +#include "MEDSPLITTER_Graph.hxx" +#include "MEDSPLITTER_MESHCollection.hxx" +#include "MEDSPLITTER_Topology.hxx" +#include "MULTIPR_Globals.hxx" + +#include <boost/thread/recursive_mutex.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/shared_ptr.hpp> + +namespace multipr +{ + +//***************************************************************************** +// Pre-declaration +//***************************************************************************** + +class Mesh; +class Group; +class Profil; + +//***************************************************************************** +// Class MeshDisPart = a sub-part of a distributed mesh. +// +// It can be : +// - a sequential MED file representing a Group (scenario 1) +// - a sequential MED file representing a part of a Group (scenario 2 -> MEDSPLITTER) +// - a lower resolution of a part (decimation) +//***************************************************************************** + +class MeshDisPart +{ + +public: + + /** + * Action to be done for this part on next writing on disk. + */ + enum OnNextWrite + { + MULTIPR_UNDEFINED, + MULTIPR_KEEP_AS_IT, + MULTIPR_WRITE_MESH, + MULTIPR_WRITE_PARTS + }; + +public: + + /** + * Builds an empty part of a distributed mesh (default constructor). + */ + MeshDisPart(); + + /** + * Destructor. Removes everything. + */ + ~MeshDisPart(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + /** + * Creates a MeshDisPart. + * \param pToDoOnNextWrite + * \param pMeshName + * \param pId + * \param pPartName + * \param pPath + * \param pMEDFileName file name excluding the path. + * \param pMesh can be NULL. + */ + void create( + OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the name of this part. + * \return the name of this part. + */ + const char* getPartName() const { return mPartName; } + + /** + * Returns the name of the mesh of this part. + * \return the name of the mesh of this part. + */ + const char* getMeshName() const { return mMeshName; } + + /** + * Returns the mesh of this part. + * \return the mesh of this part. + */ + const Mesh* getMesh() const { return mMesh; } + + /** + * Returns the MED filename which contain this part. + * \return the MED filename which contain this part. + */ + const char* getMEDFileName() const { return mMEDFileName; } + + /** + * Returns the suffix of the related MED filename (without .med extension). + * For examples: + * 1. "agregat100grains_12pas_grain97.med" -> "grain97" + * 2. "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2" + * 3. "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3" + */ + const char* getMEDFileNameSuffix() const; + + /** + * Returns the action to be performed on this part on next write. + * \return the action to be performed on this part on next write. + */ + OnNextWrite getOnNextWrite() const { return mToDoOnNextWrite; } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads the sequentiel MED file corresponding to this part. + * \throw IOException if an i/o error occurs. + */ + void readMED(); + + /** + * Dumps any MeshDisPart to the given output stream. + * \param pOs any output stream. + * \param pM any MeshDisPart. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, MeshDisPart& pM); + +private: + + // MeshDisPart can be used: + // 1 (KEEP_AS_IT) : To store data read from one line of an ASCII master file (distributed MED file) + // 2 (WRITE_MESH) : As a temporary structure to store all infos about a mesh corresponding to a group (before writing on disk). + // 3 (WRITE_PARTS) : As a temporary structure to store all infos about splitting using MEDSPLITTER. + + OnNextWrite mToDoOnNextWrite; /**< See enum OnNextWrite. */ + + //--------------------------------------------------------------------- + // Case 1, 2, and 3 + //--------------------------------------------------------------------- + char mMeshName[MED_TAILLE_NOM + 1]; /**< Name of the mesh. */ + int mId; /**< Id of this part in [1..n]. */ + char mPartName[MED_TAILLE_NOM + 1]; /**< Name of this part. */ + char mPath[256]; /**< Path of the MED file. */ + char mMEDFileName[256]; /**< Name of the MED file which contain this part. */ + + //--------------------------------------------------------------------- + // Case 2: mesh of the related sequential MED file (can be NULL if not loaded) + //--------------------------------------------------------------------- + Mesh* mMesh; /**< Mesh associated with this part; can be NULL. */ + + //--------------------------------------------------------------------- + // Case 3 only: temporary result of MEDSPLITTER + //--------------------------------------------------------------------- + int mSplit; /**< For MEDSPLITTER: number of parts. Temporary. */ + MEDSPLITTER::MESHCollection* mCollection; /**< New data after splitting. */ + MEDSPLITTER::MESHCollection* mOldCollection; /**< Data before splitting (we need them when we want to write new data on disk. */ + +private: + + // do not allow copy constructor + MeshDisPart(const MeshDisPart&); + + // do not allow copy + MeshDisPart& operator=(const MeshDisPart&); + + // do not allow operator == + bool operator==(const MeshDisPart&); + + //--------------------------------------------------------------------- + // Friends + //--------------------------------------------------------------------- + friend class MeshDis; + +}; // class MeshDisPart + + +//***************************************************************************** +// Class MeshDis +//***************************************************************************** + +class MeshDis +{ +public: + + /** + * Builds an empty mesh (default constructor). + */ + MeshDis(); + + /** + * Destructor. Removes everything. + */ + ~MeshDis(); + + /** + * Resets this object in its state by default (empty). Clean memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Sets the name of the associated sequential MED file (=original MED file). + * \param pFilename name of the associated sequential MED file. + */ + void setSequentialMEDFilename(const char* pFilename); + + /** + * Returns the name of this sequential MED file (=original MED file). + * \return the name of this sequential MED file (=original MED file). + */ + const char* getSequentialMEDFilename() const { return mSequentialMEDFilename; } + + /** + * Returns the name of this distributed MED file (=name of the master file). + * \return the name of this distributed MED file (=name of the master file). + */ + const char* getDistributedMEDFilename() const { return mDistributedMEDFilename; } + + /** + * Adds a new part to this distributed mesh. + * Used by the split process (extract groups). + * \param pToDoOnNextWrite + * \param pMeshName + * \param pId + * \param pPartName + * \param pPath + * \param pMEDFileName + * \param pMesh can be NULL. + */ + void addMesh( + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh); + + /** + * Inserts a new part to this distributed mesh. + * Used by the decimation process. + * \param pToDoOnNextWrite + * \param pMeshName + * \param pId + * \param pPartName + * \param pPath + * \param pMEDFileName + * \param pMesh can be NULL. + * \param pPosition insert after this position. Start at 1. + */ + void insertMesh( + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh, + int pPosition); + + /** + * Removes all the part beginning by pPrefixPartName from this distributed mesh. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". + * \param pPrefixPartName name of the part. + */ + void removeParts(const char* pPrefixPartName); + + /** + * Returns the current number of parts in this distributed mesh. + * \return the current number of parts in this distributed mesh. + */ + int getNumParts() const { return mParts.size(); } + + /** + * Returns the nth part of this distributed mesh. + * \param pIndex index of the part (in 0..getNumParts()-1). + * \return the nth part of this distributed mesh. + */ + MeshDisPart* getPart(int pIndex) const { return mParts[pIndex]; } + + /** + * Returns the list of meshes contained in this distributed MED file. + * \return the list of meshes contained in this distributed MED file. + */ + std::vector<std::string> getMeshes() const; + + /** + * Returns the list of fields contained in this distributed MED file. + * \param pPartList The list of parts to get the fields from (separator is '|'). + * \param pAddNbGaussPoint If set to true, the number of gauss point of each field is added. + * \return the list of fields contained in this distributed MED file. + */ + std::vector<std::string> getFields(const char* pPartList, bool pAddNbGaussPoint = false) const; + + /** + * Returns the number of iteration for a given field. + * \param pPartList The list of parts to get the fields from (separator is '|'). + * \param pFieldName field name. + * \return the number of iteration for a given field. + */ + int getTimeStamps(const char* pPartList, const char* pFieldName) const; + + /** + * Returns all information about a part. + * \param pPartName name of the part. + * \return all information about a part. + */ + std::string getPartInfo(const char* pPartName); + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Finds a part of this distributed mesh by its name. + * Returns NULL if the part does not exist. + * \param pPartName part to be found; must not be NULL. + * \return a pointer towards the part if it exists, NULL otherwise. + * \throw NullArgumentException if pPartName is NULL. + */ + MeshDisPart* findPart(const char* pPartName); + + /** + * Updates this distributed mesh by splitting one of its part. + * This splitting method leans on medsplitter, by V. Bergeaud (CEA). + * \param pPartName name of the part to be splitted. + * \param pNbParts number of sub-parts. + * \param pPartitionner MULTIPR_METIS or MULTIPR_SCOTCH. + * \throw RuntimeException if any error occurs. + */ + void splitPart(const char* pPartName, int pNbParts, int pPartitionner); + + /** + * Creates 3 resolution (CURRENT = FULL, MEDIUM and LOW) of a part of this distributed mesh. + * Names of new meshes are <original_name>_MED and <original_name>_LOW. + * \param pPartName + * \param pFielName + * \param pFieldIt + * \param pFilterName + * \param pTMed threshold used to generate MEDIUM resolution. + * \param pTLow threshold used to generate LOW resolution (must be >= pTMed). + * \param pRadius + * \param pBoxing number of cells along each axis; e.g. if 100 then grid will have 100*100*100 = 10**6 cells; 100 by default. + * \return a list of strings, containing names of empty resulting parts, empty list if all resolutions are non-empty. + * \throw RuntimeException if any error occurs. + */ + std::list<std::string> decimatePart( + const char* pPartName, + const char* pFieldName, + med_int pFieldIt, + const char* pFilterName, + const char* pFilterParams); + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + * \return + */ + std::string evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams); + + /** + * Get the statistics of the last decimation. + * The format is : "lowres-compression-rate medres-compression-rate". + */ + std::string& getDecimationStatistics() { return mStats; } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads the master file of a distributed MED file. + * \param pMEDfilename + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any i/o error occurs. + */ + void readDistributedMED(const char* pMEDfilename); + + /** + * Works like \a readDistributedMED(), but assumes that the distributed MED file was + * moved from the original location and its ASCII master file needs to be updated. + * + * \note This method is mentioned to be used only in persistence. + */ + void readPersistentDistributedMED(const char* pMEDfilename); + + /** + * Writes this distributed MED file (including master file and sub MED files if necessary). + * \param pMEDfilenamePrefix + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any i/o error occurs. + */ + void writeDistributedMED (const char* pMEDfilenamePrefix, + bool pIsPersistence = false); + + /** + * Update save progress. + * \param pPercents current save progress in percents. + */ + void setProgress (int pPercents); + + /** + * Obtain save progress. + * \return current save progress in percents. + */ + int getProgress(); + + /** + * Read and write the fields for optimized domain split. + * \param pMeshName The name of the current mesh. + * \param pGroups The groups. + * \param pGaussList The list of gauss index. + * \param pProfils The profiles of the mesh. + */ + void readAndWriteFields (const char* pMeshName, std::vector<Group*>* pGroups, + GaussIndexList* pGaussList, std::vector<Profil*>& pProfils); + + /** + * Dumps any MeshDis to the given output stream. + * \param pOs any output stream. + * \param pM any MeshDis. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, MeshDis& pM); + +private: + + /** + * Recomputes the number of parts in this distributed mesh. + * This method is used by writeDistributedMED(). + * \return the number of parts in this distributed mesh. + */ + int computeNumParts(); + +private: + + char mSequentialMEDFilename[256]; /**< Name of the original MED file used to build distribyuted MED. */ + char mDistributedMEDFilename[256]; /**< Name of this distributed MED file (= name of the master file). */ + std::vector<MeshDisPart*> mParts; /**< Table of sub-parts; a distributed mesh is composed of N sub-part, where N = mParts.size(). */ + std::string mStats; /**< Statistics of the last decimation */ + + int mWriteProgress; /**< Mesh saving progress in percents */ + boost::recursive_mutex mWriteMutex; /**< For thread-safe access to mWriteProgress */ + +private: + + // do not allow copy constructor + MeshDis(const MeshDis&); + + // do not allow copy + MeshDis& operator=(const MeshDis&); + + // do not allow operator == + bool operator==(const MeshDis&); + +}; // class MeshDis + +/* +//---------------------------------------------------------------------------- +//! This class provide thread-safety for MEDWrapper interaction +class TLockProxy +{ + TLockProxy& operator=(const TLockProxy& ); + MeshDis* myMeshDis; + boost::shared_ptr<boost::mutex> myMutex; + +public: + TLockProxy(MeshDis* theMeshDis, boost::shared_ptr<boost::mutex> theMutex); + + ~TLockProxy(); + + MeshDis * operator-> () const; +}; + +//---------------------------------------------------------------------------- +//! To specialize the SharedPtr for MeshDis +template<class T> +class SharedPtr: public boost::shared_ptr<T> +{ +public: + SharedPtr() + : myMutex(new boost::mutex()) + {} + + template<class Y> + explicit SharedPtr(Y * p) + : boost::shared_ptr<T>(p), + myMutex(new boost::mutex()) + {} + + template<class Y> + SharedPtr(SharedPtr<Y> const & r) + : boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag()), + myMutex(r->myMutex) + {} + + template<class Y> + SharedPtr& + operator=(SharedPtr<Y> const & r) + { + boost::shared_ptr<T>(r,boost::detail::dynamic_cast_tag()).swap(*this); + myMutex = r->myMutex; + return *this; + } + + template<class Y> + SharedPtr& + operator()(Y * p) // Y must be complete + { + return operator=<Y>(SharedPtr<Y>(p)); + } + + template<class Y> + SharedPtr& + operator()(SharedPtr<Y> const & r) // Y must be complete + { + return operator=<Y>(SharedPtr<Y>(r)); + } + + TLockProxy operator-> () const // never throws + { + return TLockProxy(this->get(), myMutex); + } + + template<class Y> + void reset (Y * p) // Y must be complete + { + //boost::detail::thread::lock_ops<typename T::TMutex>::lock(p->myMutex); + boost::detail::thread::lock_ops<boost::mutex>::lock(*myMutex); + if (boost::shared_ptr<T>::get() != NULL) delete (boost::shared_ptr<T>::get()); + boost::shared_ptr<T>(p).swap(*this); + //boost::detail::thread::lock_ops<typename T::TMutex>::unlock(p->myMutex); + boost::detail::thread::lock_ops<boost::mutex>::unlock(*myMutex); + } + +protected: + operator const T& () const; + + operator T& (); + + T& operator* () const; + + T * get() const // never throws + { + return boost::shared_ptr<T>::get(); + } + +private: + boost::shared_ptr<boost::mutex> myMutex; +}; +*/ + +} // namespace MULTIPR + + +#endif // MULTIPR_MESHDIS_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Nodes.cxx b/src/MULTIPR/MULTIPR_Nodes.cxx new file mode 100755 index 000000000..e3596a491 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Nodes.cxx @@ -0,0 +1,496 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Nodes.cxx + * + * \brief see MULTIPR_Nodes.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Nodes.hxx" +#include "MULTIPR_Exceptions.hxx" + +#include <iostream> + +using namespace std; + + +namespace multipr +{ + + +//***************************************************************************** +// Class Nodes implementation +//***************************************************************************** + +Nodes::Nodes() +{ + mId = NULL; + mFamIdent = NULL; + mNames = NULL; + mCoo = NULL; + mNamesCoo = NULL; + mNamesUnitCoo = NULL; + + reset(); +} + + +Nodes::~Nodes() +{ + reset(); +} + + +void Nodes::reset() +{ + mNum = 0; + mDim = 0; + mCoordSystem = MED_CART; + + if (mId != NULL) { delete[] mId; mId = NULL; } + if (mFamIdent != NULL) { delete[] mFamIdent; mFamIdent = NULL; } + if (mNames != NULL) { delete[] mNames; mNames = NULL; } + if (mCoo != NULL) { delete[] mCoo; mCoo = NULL; } + if (mNamesCoo != NULL) { delete[] mNamesCoo; mNamesCoo = NULL; } + if (mNamesUnitCoo != NULL) { delete[] mNamesUnitCoo; mNamesUnitCoo = NULL; } + + mFlagPrintAll = false; +} + + +const med_float* Nodes::getCoordinates(med_int pIndexNode) const +{ + if ((pIndexNode < 0) || (pIndexNode >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mCoo + pIndexNode * mDim; +} + + +med_int Nodes::getFamIdent(med_int pIndexNode) const +{ + if ((pIndexNode < 0) || (pIndexNode >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mFamIdent[pIndexNode]; +} + + +void Nodes::getBBox(med_float pMin[3], med_float pMax[3]) const +{ + //--------------------------------------------------------------------- + // Special case: no nodes => bbox = [0 ; 0] x [0 ; 0] x [0 ; 0] + //--------------------------------------------------------------------- + if (mNum == 0) + { + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + pMin[itDim] = med_float(0.0); + pMax[itDim] = med_float(0.0); + } + + return; + } + + //--------------------------------------------------------------------- + // Compute axis-aligned bounding box + //--------------------------------------------------------------------- + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + pMin[itDim] = numeric_limits<med_float>::max(); + pMax[itDim] = -pMin[itDim]; + } + for (int itNode = 0 ; itNode < mNum ; itNode++) + { + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + med_float coord = mCoo[itNode * mDim + itDim]; + if (coord < pMin[itDim]) pMin[itDim] = coord; + if (coord > pMax[itDim]) pMax[itDim] = coord; + } + } +} + + +set<med_int> Nodes::getSetOfFamilies() const +{ + set<med_int> setOfFamilies; + + // for each node, ad its family to the set + for (int itNode = 0 ; itNode < mNum ; itNode++) + { + setOfFamilies.insert(mFamIdent[itNode]); + } + + return setOfFamilies; +} + + +Nodes* Nodes::extractSubSet(const set<med_int>& pSetIndices) const +{ + Nodes* subset = new Nodes(); + + subset->mNum = pSetIndices.size(); + subset->mDim = mDim; + subset->mCoordSystem = mCoordSystem; + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + subset->mFamIdent = new med_int[subset->mNum]; + subset->mCoo = new med_float[subset->mDim * subset->mNum]; + subset->mNamesCoo = new char[subset->mDim * MED_TAILLE_PNOM + 1]; + subset->mNamesUnitCoo = new char[subset->mDim * MED_TAILLE_PNOM + 1]; + + memcpy(subset->mNamesCoo, mNamesCoo, subset->mDim * MED_TAILLE_PNOM + 1); + memcpy(subset->mNamesUnitCoo, mNamesUnitCoo, subset->mDim * MED_TAILLE_PNOM + 1); + + //--------------------------------------------------------------------- + // Copy subset of familys id and coords. + //--------------------------------------------------------------------- + set<med_int>::iterator itSet = pSetIndices.begin(); + for (int i = 0 ; i < subset->mNum && itSet != pSetIndices.end(); i++) + { + + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mFamIdent[i] = mFamIdent[srcIndex]; + med_float* srcCoo = mCoo + srcIndex * mDim; + med_float* destCoo = subset->mCoo + i * subset->mDim; + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + destCoo[itDim] = srcCoo[itDim]; + } + + itSet++; + } + //--------------------------------------------------------------------- + // Copy subset of identifiers if necessary + //--------------------------------------------------------------------- + if (isIdentifiers()) + { + itSet = pSetIndices.begin(); + subset->mId = new med_int[subset->mNum]; + for (int i = 0 ; i < subset->mNum && itSet != pSetIndices.end(); i++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mId[i] = mId[srcIndex]; + + itSet++; + } + } + + //--------------------------------------------------------------------- + // Copy subset of names if necessary + //--------------------------------------------------------------------- + if (isNames()) + { + subset->mNames = new char[MED_TAILLE_PNOM * subset->mNum + 1]; + char* destPtr = subset->mNames; + itSet = pSetIndices.begin(); + for (int i = 0 ; i < subset->mNum && itSet != pSetIndices.end(); i++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + char* srcPtr = mNames + srcIndex * MED_TAILLE_PNOM; + memcpy(destPtr, srcPtr, MED_TAILLE_PNOM); + destPtr += MED_TAILLE_PNOM; + + itSet++; + } + subset->mNames[MED_TAILLE_PNOM * subset->mNum] = '\0'; + } + return subset; +} + + +Nodes* Nodes::mergePartial(Nodes* pNodes) +{ + Nodes* nodes = new Nodes(); + + nodes->mNum = mNum + pNodes->mNum; + + if (mDim != pNodes->mDim) throw IllegalStateException("dimension should be the same", __FILE__, __LINE__); + nodes->mDim = mDim; + + if (mCoordSystem != pNodes->mCoordSystem) throw IllegalStateException("coord. sytstem should be the same", __FILE__, __LINE__); + nodes->mCoordSystem = mCoordSystem; + + nodes->mId = NULL; // optional: ignored + nodes->mNames = NULL; // optional: ignored + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + nodes->mFamIdent = new med_int[nodes->mNum]; + nodes->mCoo = new med_float[nodes->mDim * nodes->mNum]; + nodes->mNamesCoo = new char[nodes->mDim * MED_TAILLE_PNOM + 1]; + nodes->mNamesUnitCoo = new char[nodes->mDim * MED_TAILLE_PNOM + 1]; + + memcpy(nodes->mNamesCoo, mNamesCoo, nodes->mDim * MED_TAILLE_PNOM + 1); + memcpy(nodes->mNamesUnitCoo, mNamesUnitCoo, nodes->mDim * MED_TAILLE_PNOM + 1); + + //--------------------------------------------------------------------- + // Copy familys id and coords. + //--------------------------------------------------------------------- + memcpy(nodes->mFamIdent, mFamIdent, mNum * sizeof(med_int)); + memcpy(nodes->mFamIdent + mNum, pNodes->mFamIdent, pNodes->mNum * sizeof(med_int)); + + memcpy(nodes->mCoo, mCoo, mNum * mDim * sizeof(med_float)); + memcpy(nodes->mCoo + (mNum * mDim), pNodes->mCoo, pNodes->mNum * pNodes->mDim * sizeof(med_float)); + + return nodes; +} + + +Nodes* Nodes::mergePartial(vector<Nodes*> pNodes) +{ + if (pNodes.size() == 0) throw IllegalArgumentException("pNodes should contain at least 1 element", __FILE__, __LINE__); + + Nodes* nodes = new Nodes(); + + // count total number of nodes and check if all set of nodes are compatible + nodes->mNum = mNum; + for (unsigned i = 0 ; i < pNodes.size() ; i++) + { + nodes->mNum += pNodes[i]->mNum; + + if (mDim != pNodes[i]->mDim) throw IllegalStateException("dimension should be the same", __FILE__, __LINE__); + if (mCoordSystem != pNodes[i]->mCoordSystem) throw IllegalStateException("coord. sytstem should be the same", __FILE__, __LINE__); + } + + nodes->mDim = mDim; + nodes->mCoordSystem = mCoordSystem; + + nodes->mId = NULL; // optional: ignored + nodes->mNames = NULL; // optional: ignored + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + nodes->mFamIdent = new med_int[nodes->mNum]; + nodes->mCoo = new med_float[nodes->mDim * nodes->mNum]; + nodes->mNamesCoo = new char[nodes->mDim * MED_TAILLE_PNOM + 1]; + nodes->mNamesUnitCoo = new char[nodes->mDim * MED_TAILLE_PNOM + 1]; + + memcpy(nodes->mNamesCoo, mNamesCoo, nodes->mDim * MED_TAILLE_PNOM + 1); + memcpy(nodes->mNamesUnitCoo, mNamesUnitCoo, nodes->mDim * MED_TAILLE_PNOM + 1); + + //--------------------------------------------------------------------- + // Copy familys id and coords. + //--------------------------------------------------------------------- + memcpy(nodes->mFamIdent, mFamIdent, mNum * sizeof(med_int)); + memcpy(nodes->mCoo, mCoo, mNum * mDim * sizeof(med_float)); + + int offsetFamIdent = mNum; + int offsetCoo = mNum; + for (unsigned i = 0 ; i < pNodes.size() ; i++) + { + memcpy(nodes->mFamIdent + offsetFamIdent, pNodes[i]->mFamIdent, pNodes[i]->mNum * sizeof(med_int)); + memcpy(nodes->mCoo + (offsetCoo * mDim), pNodes[i]->mCoo, pNodes[i]->mNum * mDim * sizeof(med_float)); + + offsetFamIdent += pNodes[i]->mNum; + offsetCoo += pNodes[i]->mNum; + } + + return nodes; +} + + +void Nodes::readMED(med_idt pMEDfile, char* pMeshName, med_int pDim) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pDim != 3) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + mDim = pDim; + mNum = MEDnEntMaa( + pMEDfile, + pMeshName, + MED_COOR, + MED_NOEUD, + med_geometrie_element(0), + med_connectivite(0)); + + if (mNum < 0) throw IOException("", __FILE__, __LINE__); + + if (mNum == 0) + { + // empty mesh + return; + } + + mId = new med_int[mNum]; + mFamIdent = new med_int[mNum]; + mNames = new char[MED_TAILLE_PNOM * mNum + 1]; + mCoo = new med_float[mDim * mNum]; + mNamesCoo = new char[mDim * MED_TAILLE_PNOM + 1]; + mNamesUnitCoo = new char[mDim * MED_TAILLE_PNOM + 1]; + + mNames[0] = '\0'; + mNamesCoo[0] = '\0'; + mNamesUnitCoo[0] = '\0'; + + med_booleen isIdentifiers; + med_booleen isNames; + + med_err ret = MEDnoeudsLire( + pMEDfile, + pMeshName, + mDim, + mCoo, + MED_FULL_INTERLACE, + &mCoordSystem, + mNamesCoo, + mNamesUnitCoo, + mNames, + &isNames, + mId, + &isIdentifiers, + mFamIdent, + mNum); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + // check if coordinates system is CARTESIAN + if (mCoordSystem != MED_CART) throw IllegalStateException("", __FILE__, __LINE__); + + if (!isNames) + { + delete[] mNames; + mNames = NULL; + } + + if (!isIdentifiers) + { + delete[] mId; + mId = NULL; + } +} + + +void Nodes::writeMED(med_idt pMEDfile, char* pMeshName) const +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((mDim < 1) || (mDim > 3)) throw IllegalStateException("", __FILE__, __LINE__); + if (mFamIdent == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mNamesCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mNamesUnitCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + + // special case: if no nodes => do nothing + if (mNum == 0) return; + + med_err ret = MEDnoeudsEcr( + pMEDfile, + pMeshName, + mDim, + mCoo, + MED_FULL_INTERLACE, + mCoordSystem, + mNamesCoo, + mNamesUnitCoo, + mNames, + isNames()?MED_VRAI:MED_FAUX, + mId, + isIdentifiers()?MED_VRAI:MED_FAUX, + mFamIdent, + mNum); + + if (ret != 0) throw IOException("i/o error while writing nodes", __FILE__, __LINE__); + +} + + +ostream& operator<<(ostream& pOs, Nodes& pN) +{ + char strCoordSystem[16]; + switch (pN.mCoordSystem) + { + case MED_CART: strcpy(strCoordSystem, "CARTESIAN"); break; + case MED_CYL: strcpy(strCoordSystem, "CYLINDRIC"); break; + case MED_SPHER: strcpy(strCoordSystem, "SPHERIC"); break; + default: strcpy(strCoordSystem, "UNKNOWN"); break; + } + + pOs << "Nodes: " << endl; + pOs << " #number =" << pN.mNum << endl; + pOs << " Dimension =" << pN.mDim << endl; + pOs << " Coord. system=" << strCoordSystem << endl; + pOs << " Has names ?" << (pN.isNames()?"yes":"no") << endl; + pOs << " Has id ?" << (pN.isIdentifiers()?"yes":"no") << endl; + if (pN.mNamesCoo != NULL) pOs << " Axis names =" << "|" << pN.mNamesCoo << "|" << endl; + if (pN.mNamesUnitCoo != NULL) pOs << " Unit axis =" << "|" << pN.mNamesUnitCoo << "|" << endl; + + { + set<med_int> setOfFam = pN.getSetOfFamilies(); + if (setOfFam.size() == 0) + { + pOs << " Families: #fam=0" << endl; + } + else + { + set<med_int>::iterator itFam = setOfFam.end(); + itFam--; + pOs << " Families: #fam=" << setOfFam.size() << " id_min=" << (*(setOfFam.begin())) << " id_max=" << (*itFam) << endl; + } + + if (pN.mFlagPrintAll) + { + for (int itNode = 0 ; itNode < pN.mNum; itNode++) + { + pOs << " Node " << (itNode+1) << ": " << pN.mFamIdent[itNode] << endl; + } + } + } + + med_float bboxMin[3], bboxMax[3]; + pN.getBBox(bboxMin, bboxMax); + pOs << " BBox: [" << bboxMin[0] << " ; " << bboxMax[0] << "] x [" << bboxMin[1] << " ; " << bboxMax[1] << "] x [" << bboxMin[2] << " ; " << bboxMax[2] << "]" << endl; + + if (pN.mFlagPrintAll) + { + pOs << " Coordinates: " << endl; + for (int itNode = 0 ; itNode < pN.mNum ; itNode++) + { + pOs << " Node " << (itNode+1) << ": "; + for (int itDim = 0 ; itDim < pN.mDim ; itDim++) + { + pOs << pN.mCoo[itNode * pN.mDim + itDim] << " "; + } + pOs << endl; + } + + if (pN.isIdentifiers()) + { + pOs << " Num: " << endl; + for (int itNode = 0 ; itNode < pN.mNum; itNode++) + { + pOs << " Node " << (itNode+1) << ": " << pN.mId[itNode] << endl; + } + } + + if (pN.isNames()) + { + pN.mNames[MED_TAILLE_PNOM * pN.mNum] = '\0'; + pOs << " Names: |" << pN.mNames << "|" << endl; + } + + } + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Nodes.hxx b/src/MULTIPR/MULTIPR_Nodes.hxx new file mode 100755 index 000000000..a33ffd43e --- /dev/null +++ b/src/MULTIPR/MULTIPR_Nodes.hxx @@ -0,0 +1,201 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Nodes.hxx + * + * \brief Class Nodes = table of nodes. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_NODES_HXX +#define MULTIPR_NODES_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <iostream> +#include <set> +#include <vector> + + +namespace multipr +{ + + +//***************************************************************************** +// Class Nodes +//***************************************************************************** + +class Nodes +{ +public: + + /** + * Builds an empty set of nodes (default constructor). + */ + Nodes(); + + /** + * Destructor. Removes everything. + */ + ~Nodes(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true if nodes have a name. + * \return true if nodes have a name. + */ + bool isNames() const { return (mNames != NULL); } + + /** + * Returns true if elements have an identifier (= a number). + * \return true if elements have an identifier (= a number). + */ + bool isIdentifiers() const { return (mId != NULL); } + + /** + * Returns the coordinates of one node according to its index. + * \param pIndexNode index of node in [0..NUMBER_OF_NODES-1]. + * \return the coordinates of one node. + * \throw IndexOutOfBoundsException if pIndexNode is invalid. + */ + const med_float* getCoordinates(med_int pIndexNode) const; + + /** + * Returns the family of one node. + * \param pIndexNode index of node in [0..NUMBER_OF_NODES-1]. + * \return the family of the given node. + * \throw IndexOutOfBoundsException if pIndexNode is invalid. + */ + med_int getFamIdent(med_int pIndexNode) const; + + /** + * Returns the number of nodes. + * \return the number of nodes. + */ + int getNumberOfNodes() const { return mNum; } + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Returns the axis-aligned bounding box (CARTESIAN coordinates system) of this set of nodes. + * \param pMin (out) coordinates of the min-corner of the bbox. + * \param pMin (out) coordinates of the max-corner of the bbox. + */ + void getBBox(med_float pMin[3], med_float pMax[3]) const; + + /** + * Returns the set of families referenced by this set of nodes. + * Each family is described by its identifier. + * \return the set of families referenced by this set of nodes. + */ + std::set<med_int> getSetOfFamilies() const; + + /** + * Constructor. Creates a subset of this set of nodes from a set of indices. + * \param pSetOfIndices set of indices; each index must be >= 1. + * \return a subset of this set of nodes from a set of indices. + */ + Nodes* extractSubSet(const std::set<med_int>& pSetIndices) const; + + /** + * Builds a new set of nodes by merging two set of nodes (this and pNodes) if possible. + * Merge is partial because Id and Names are not take into account. + * \param pNodes any set of nodes to be merged with this. + * \return a new set of nodes. + * \throw IllegalStateException if the two sets of nodes are incompatible. + */ + Nodes* mergePartial(Nodes* pNodes); + Nodes* mergePartial(std::vector<Nodes*> pNodes); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads all nodes of a mesh from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName name of the mesh to be read. + * \param pDim dimension of the mesh. + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, char* pMeshName, med_int pDim); + + /** + * Writes this set of nodes to a MED file. Nodes are associated with the given mesh. + * WARNING: mesh must have been created and added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pMeshName any mesh of the MED file. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName) const; + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Nodes to the given output stream. + * \param pOs any output stream. + * \param pN any Nodes. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Nodes& pN); + +private: + + med_int mNum; /**< Number of nodes in this set. */ + med_int mDim; /**< Dimension of nodes. */ + med_repere mCoordSystem; /**< Type of coordinates system; should be MED_CART for cartesian. */ + + med_int* mId; /**< Optional; for each node, its identifier; NULL if undefined. */ + med_int* mFamIdent; /**< For each node, its identifier of its family. */ + char* mNames; /**< Optional; for each node, its name; NULL if undefined. */ + med_float* mCoo; /**< For each node, coordinates of node; array is interlaced: x1 y1 z1 x2 y2 z2 ...*/ + char* mNamesCoo; /**< Names of axis of the coordinates system. */ + char* mNamesUnitCoo; /**< Unit of axis of the coordinates system. */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + +private: + + // do not allow copy constructor + Nodes(const Nodes&); + + // do not allow copy + Nodes& operator=(const Nodes&); + + // do not allow operator == + bool operator==(const Nodes&); + +}; // class Nodes + + +} // namespace MULTIPR + + +#endif // MULTIPR_NODES_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Obj.cxx b/src/MULTIPR/MULTIPR_Obj.cxx new file mode 100755 index 000000000..b081f81fc --- /dev/null +++ b/src/MULTIPR/MULTIPR_Obj.cxx @@ -0,0 +1,739 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Obj.cxx + * + * \brief see MULTIPR_Obj.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Obj.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_Family.hxx" +#include "MULTIPR_MeshDis.hxx" +#include "MULTIPR_Utils.hxx" +#include "MULTIPR_Profil.hxx" +#include "MED_Factory.hxx" + +#include <stdio.h> +#include <iostream> +#include <errno.h> + +extern int errno; + +using namespace std; + + +namespace multipr +{ + +//***************************************************************************** +// Class Obj implementation +//***************************************************************************** + +Obj::Obj() + : mMeshDis(NULL) +{ + reset(); +} + + +Obj::~Obj() +{ + reset(); +} + + +void Obj::reset() +{ + mPrevPath = ""; + mMEDfilename = ""; + mMeshName = ""; + mState = MULTIPR_OBJ_STATE_RESET; + mDoReadWriteFields = false; + + mGaussList.clear(); + for (std::vector<Group*>::iterator it = mGroups.begin(); it != mGroups.end(); ++it) + { + delete *it; + } + mGroups.clear(); + + if (mMeshDis != NULL) { + delete mMeshDis; + mMeshDis = NULL; + } +} + + +void Obj::create(const char* pMEDfilename) +{ + if (pMEDfilename == NULL) + throw multipr::NullArgumentException("file name must not be NULL", __FILE__, __LINE__); + + // reset everything before associating a new MED file to this object + reset(); + + mMEDfilename = pMEDfilename; + + // check if file exists + FILE* f = fopen(pMEDfilename, "rb"); + + // Big file (> 2Go) problem : since the other library may use 32bits off_t we check + // the EFBIG error. Compile with -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 + // -D_LARGEFILE64_SOURCE flags to resolve this issue. + if (f == NULL && errno == EFBIG) + { + mState = MULTIPR_OBJ_STATE_ERROR; + throw IOException("Big file error : please compile with -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE flags.", __FILE__, __LINE__); + } + if (f == NULL) + { + // file does not exist + mState = MULTIPR_OBJ_STATE_ERROR; + throw FileNotFoundException("file not found", __FILE__, __LINE__); + } + fclose(f); + + // test whether it is a sequential MED file or a distributed MED file. + MED::EVersion aVersion = MED::GetVersionId(pMEDfilename, true); + if (aVersion != MED::eVUnknown) + { + // sequential MED file has been sucessfuly openened + + // CASE 1: sequential MED file + mState = MULTIPR_OBJ_STATE_SEQ_INIT; + cout << "Sequential MED file " << pMEDfilename << " has been successfuly opened" << endl; + } + else + { + // CASE 2: distributed MED file? + try + { + mMeshDis = new multipr::MeshDis(); + mMeshDis->readDistributedMED(pMEDfilename); + + mState = MULTIPR_OBJ_STATE_DIS; + cout << "Distributed MED file " << pMEDfilename << " has been successfuly opened" << endl; + } + catch (RuntimeException& e) + { + e.dump(cout); + // neither a sequential MED file, nor a distributed MED file => error + mState = MULTIPR_OBJ_STATE_ERROR; + throw IOException("file is nor a sequential MED file, neither a distributed MED file", __FILE__, __LINE__); + } + } +} + + +std::string Obj::getSequentialMEDFilename() const +{ + // partitionneGroupe() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + return mMeshDis->getSequentialMEDFilename(); +} + + +void Obj::setMesh(const char* pMeshName) +{ + // setMesh() is only available for sequential MED file (not distributed MED file) + if ((mState != MULTIPR_OBJ_STATE_SEQ_INIT) && + (mState != MULTIPR_OBJ_STATE_SEQ)) throw IllegalStateException("expected a sequential MED file", __FILE__, __LINE__); + + mMeshName = pMeshName; + + // change state to MULTIPR_OBJ_STATE_SEQ (in case of state=MULTIPR_OBJ_STATE_SEQ_INIT) + mState = MULTIPR_OBJ_STATE_SEQ; +} + + +vector<string> Obj::getMeshes() const +{ + // test whether it is a sequential MED file or a distributed MED file + if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || + (mState == MULTIPR_OBJ_STATE_SEQ)) + { + // CASE 1: sequential MED file + return multipr::getListMeshes(mMEDfilename.c_str()); + } + else + { + // CASE 2: distributed MED file + if (mMeshDis == NULL) + { + throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + } + + return mMeshDis->getMeshes(); + } +} + + +vector<string> Obj::getFields(const char* pPartList) const +{ + vector<string> res; + // test whether it is a sequential MED file or a distributed MED file + if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || + (mState == MULTIPR_OBJ_STATE_SEQ)) + { + // CASE 1: sequential MED file + vector<pair<string, int> > tmp; + multipr::getListScalarFields(mMEDfilename.c_str(), tmp, true, mMeshName.c_str()); + + for (unsigned i = 0 ; i < tmp.size() ; i++) + { + res.push_back(tmp[i].first); + } + + return res; + } + else + { + // CASE 2: distributed MED file + if (mMeshDis == NULL) + throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + if (pPartList != NULL) + { + return mMeshDis->getFields(pPartList, true); + } + else + { + return res; + } + } + return res; +} + + +int Obj::getTimeStamps(const char* pPartList, const char* pFieldName) const +{ + // test whether it is a sequential MED file or a distributed MED file + if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || + (mState == MULTIPR_OBJ_STATE_SEQ)) + { + // CASE 1: sequential MED file + vector<pair<string, int> > tmp; + multipr::getListScalarFields(mMEDfilename.c_str(), tmp); + for (unsigned i = 0 ; i < tmp.size() ; i++) + { + if (strcmp(tmp[i].first.c_str(), pFieldName) == 0) + { + return tmp[i].second; + } + } + // pFieldName not found in the list of fields + return 0; + } + else + { + // CASE 2: distributed MED file + if (mMeshDis == NULL) + throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + if (pPartList != NULL) + { + return mMeshDis->getTimeStamps(pPartList, pFieldName); + } + else + { + return 0; + } + } + return 0; +} + +void Obj::getFieldMinMax(const char* pPartName, const char* pFieldName, float& pMin, float& pMax) +{ + // getFieldMinMax() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + pMin = 0.0f; + pMax = 0.0f; + + MeshDisPart* part = mMeshDis->findPart(pPartName); + if (part == NULL) + { + return; + } + if (part->getMesh() == NULL) + { + part->readMED(); + } + part->getMesh()->getFieldMinMax(pFieldName, pMin, pMax); +} + +vector<string> Obj::getParts() const +{ + // getParts() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) + { + throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + } + return getListParts(); +} + + +string Obj::getPartInfo(const char* pPartName) const +{ + // getParts() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + return mMeshDis->getPartInfo(pPartName); + +} + + +void Obj::removeParts(const char* pPrefixPartName) +{ + // removePart() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + mMeshDis->removeParts(pPrefixPartName); + mState = MULTIPR_OBJ_STATE_DIS_MEM; +} + + +vector<string> Obj::partitionneDomaine() +{ + if (mState == MULTIPR_OBJ_STATE_SEQ_INIT) throw IllegalStateException("use setMesh() before", __FILE__, __LINE__); + + // partitionneDomaine() is only available for sequential MED file (not distributed MED file) + if (mState != MULTIPR_OBJ_STATE_SEQ) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + //------------------------------------------------------------- + // Read the sequential mesh + //------------------------------------------------------------- + cout << "Read sequential MED file: " << mMEDfilename << ": please wait... " << endl; + + Mesh mesh; + mesh.readSequentialMED(mMEDfilename.c_str(), mMeshName.c_str(), false); + // We need to COPY the groups of the original mesh. + // We delete the mesh at the end of the domain split but we still need + // the groups for the optimized field extraction. + // This data will be used and deleted in the save method. + std::vector<Group*>* lGroups = mesh.getGroups(); + std::vector<Group*>::iterator it; + Group* curGroup; + for (it = lGroups->begin(); it != lGroups->end(); ++it) + { + curGroup = new Group(); + curGroup->setName((*it)->getName()); + for (int i = 0; i < eMaxMedMesh; ++i) + { + curGroup->setSetOfElt((eMeshType)i, (*it)->getSetOfElt((eMeshType)i)); + } + curGroup->setIsGroupOfNodes((*it)->isGroupOfNodes()); + mGroups.push_back(curGroup); + } + cout << mesh << endl; + + //------------------------------------------------------------- + // Build distributed mesh from groups + //------------------------------------------------------------- + cout << "Build distributed mesh: please wait... " << endl; + try + { + // We need to COPY the gauss information from the original mesh (look at previous comment). + mMeshDis = mesh.splitGroupsOfElements(); + mGaussList = *mesh.editGaussIndex(); + mesh.editGaussIndex()->clear(); + // We need to COPY the profiles of the original mesh (look at previous comment). + std::vector<Profil*>& lProfils = mesh.getProfils(); + for (std::vector<Profil*>::iterator it = lProfils.begin(); it != lProfils.end(); ++it) + { + mProfils.push_back(new Profil(*(*it))); + } + mDoReadWriteFields = true; + } + catch (RuntimeException& e) + { + e.dump(cout); + delete mMeshDis; + mMeshDis = NULL; + throw e; + } + + mState = MULTIPR_OBJ_STATE_DIS_MEM; + + return getListParts(); +} + + +vector<string> Obj::partitionneGroupe( + const char* pPartName, + int pNbParts, + int pPartitionner) +{ + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + if (pPartName == NULL) + throw NullArgumentException("part name is empty", __FILE__, __LINE__); + if (pNbParts < 2) + throw IllegalArgumentException("number of parts must be at least two", __FILE__, __LINE__); + if ((pPartitionner != 0) && (pPartitionner != 1)) throw IllegalArgumentException("partitionner should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__); + + // partitionneGroupe() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + // if distributed MED file is currently in memory, + // then write to disk before performing partitionneGroupe() + // (because MEDSPLIITER starts from a file) + if (mState == MULTIPR_OBJ_STATE_DIS_MEM) + { + //----------------------------------------------------- + // Write distributed mesh + //----------------------------------------------------- + cout << "Write distributed mesh: please wait... " << endl; + string strPrefix = removeExtension(mMEDfilename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str()); + + mMEDfilename = mMeshDis->getDistributedMEDFilename(); + + delete mMeshDis; + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + int ret = MEDformatConforme(mMEDfilename.c_str()); + if (ret == 0) + throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); + + mMeshDis = new MeshDis(); + mMeshDis->readDistributedMED(mMEDfilename.c_str()); + + mState = MULTIPR_OBJ_STATE_DIS; + } + + //--------------------------------------------------------------------- + // Split the given part (pGroupName) + //--------------------------------------------------------------------- + mMeshDis->splitPart(pPartName, pNbParts, pPartitionner); + cout << mMeshDis << endl; + + //--------------------------------------------------------------------- + // Write new distributed mesh + //--------------------------------------------------------------------- + string strPrefix = multipr::removeExtension(mMEDfilename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str()); + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + delete mMeshDis; + mMeshDis = new MeshDis(); + //cout << "read dis MED file: filename=" << mMEDfilename << endl; + mMeshDis->readDistributedMED(mMEDfilename.c_str()); + + return getListParts(); +} + + +vector<string> Obj::decimePartition( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + std::list<std::string> pEmptyMeshes; + return decimePartition(pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams, + pEmptyMeshes); +} + + +vector<string> Obj::decimePartition (const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams, + std::list<std::string>& pEmptyMeshes) +{ + vector<string> ret; + // decimePartition() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) + throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Decimate + //--------------------------------------------------------------------- + std::list<std::string> emptyMeshes = mMeshDis->decimatePart( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + + std::list<std::string>::iterator it = emptyMeshes.begin(), end = emptyMeshes.end(); + for (; it != end; it++) + { + pEmptyMeshes.push_back(*it); + } + + mState = MULTIPR_OBJ_STATE_DIS_MEM; + + ret = getListParts(); + ret.push_back(mMeshDis->getDecimationStatistics()); + return ret; +} + + +string Obj::evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) +{ + // decimePartition() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + string res = mMeshDis->evalDecimationParams( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + + return res; +} + +void Obj::getMEDInfo(char* pStats, char* pPartName) +{ + + med_idt lMEDfile; + med_int lRet; + + // Get the mesh path + MeshDisPart* curMeshDis = this->mMeshDis->findPart(pPartName); + if (curMeshDis == NULL) + { + throw IllegalStateException("Can't find part.", __FILE__, __LINE__); + return ; + } + const char* curMesh = curMeshDis->getMEDFileName(); + if (curMesh == NULL) + { + throw IllegalStateException("Can't find mesh.", __FILE__, __LINE__); + return ; + } + + // open MED file for reading + lMEDfile = MEDouvrir(const_cast<char*>(curMesh), MED_LECTURE); + if (lMEDfile <= 0) + { + throw IllegalStateException("Can't open file.", __FILE__, __LINE__); + return ; + } + const char* meshName = curMeshDis->getMeshName(); + if (meshName == 0) + { + throw IllegalStateException("Can't find mesh name.", __FILE__, __LINE__); + } + // Get the number of cells + for (int itCell = 0 ; itCell < MED_NBR_GEOMETRIE_MAILLE ; itCell++) + { + lRet = MEDnEntMaa(lMEDfile, const_cast<char*>(meshName), MED_CONN, MED_MAILLE, CELL_TYPES[itCell], MED_NOD); + if (lRet > 0) + { + break; + } + } + sprintf(pStats, "%d", lRet); +} + +vector<string> Obj::getListParts() const +{ + if (mMeshDis == NULL) throw IllegalStateException("not a distributed mesh", __FILE__, __LINE__); + + vector<string> names; + + int numParts = mMeshDis->getNumParts(); + for (int i = 0 ; i < numParts ; i++) + { + names.push_back( mMeshDis->getPart(i)->getPartName() ); + } + + return names; +} + + +void Obj::save(const char* pPath) +{ + // only save file if it is a distributed MED file currently in memory or path has changed + if ((mState == MULTIPR_OBJ_STATE_DIS_MEM) || (strcmp(pPath, mPrevPath.c_str()) != 0)) + { + mPrevPath = pPath; + + //------------------------------------------------------------- + // Write new distributed mesh + //------------------------------------------------------------- + string filename; + if (strlen(pPath) == 0) + { + filename = multipr::removeExtension(mMEDfilename.c_str(), ".med"); + } + else + { + filename = string(pPath) + string("/") + multipr::getFilenameWithoutPath(mMEDfilename.c_str()); + } + string strPrefix = multipr::removeExtension(filename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str()); + if (mDoReadWriteFields == true) + { + try + { + mMeshDis->readAndWriteFields(mMeshName.c_str(), &mGroups, &mGaussList, mProfils); + + } + catch (RuntimeException& e) + { + e.dump(cout); + delete mMeshDis; + mMeshDis = NULL; + throw e; + } + // need to delete some garb + mGaussList.clear(); + for (std::vector<Group*>::iterator it = mGroups.begin(); it != mGroups.end(); ++it) + { + delete *it; + } + mGroups.clear(); + mDoReadWriteFields = false; + } + mMEDfilename = mMeshDis->getDistributedMEDFilename(); + + cout << "Write MED master file: " << mMEDfilename << ": OK" << endl; + + //------------------------------------------------------------- + // Read the distributed mesh + //------------------------------------------------------------- + { + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + delete mMeshDis; + mMeshDis = new MeshDis(); + } + mMeshDis->readDistributedMED(mMEDfilename.c_str()); + + mState = MULTIPR_OBJ_STATE_DIS; + } + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + mMeshDis->setProgress(100); +} + +void Obj::resetProgress() +{ + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + mMeshDis->setProgress(0); +} + +int Obj::getProgress() +{ + boost::recursive_mutex::scoped_lock aLock (mWriteMutex); + return mMeshDis->getProgress(); +} + +void Obj::savePersistent (const char* pPath) +{ + if (pPath == NULL) + throw multipr::NullArgumentException("path must not be NULL", __FILE__, __LINE__); + + //------------------------------------------------------------- + // Write distributed mesh + //------------------------------------------------------------- + string filename = string(pPath) + string("/") + multipr::getFilenameWithoutPath(mMEDfilename.c_str()); + string strPrefix = multipr::removeExtension(filename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str(), /*pIsPersistence*/true); +} + +void Obj::restorePersistent (const char* pMEDfilename) +{ + if (pMEDfilename == NULL) + throw multipr::NullArgumentException("file name must not be NULL", __FILE__, __LINE__); + + // reset everything before associating a new MED file to this object + reset(); + + mMEDfilename = pMEDfilename; + mState = MULTIPR_OBJ_STATE_ERROR; + + // check if file exists + FILE* f = fopen(pMEDfilename, "rb"); + if (f == 0) + { + // file does not exist + mState = MULTIPR_OBJ_STATE_ERROR; + throw FileNotFoundException("file not found", __FILE__, __LINE__); + } + fclose(f); + + // test whether it is a sequential MED file or a distributed MED file + MED::EVersion aVersion = MED::GetVersionId(pMEDfilename, true); + if (aVersion != MED::eVUnknown) + { + mState = MULTIPR_OBJ_STATE_SEQ_INIT; + cout << "Sequential MED file " << pMEDfilename << " has been successfuly opened" << endl; + } + else + { + // CASE 2: distributed MED file? + try + { + mMeshDis = new multipr::MeshDis(); + //mMeshDis.reset(new MeshDis()); + mMeshDis->readPersistentDistributedMED(pMEDfilename); + + mState = MULTIPR_OBJ_STATE_DIS; + cout << "Distributed MED file " << pMEDfilename << " has been successfuly opened" << endl; + } + catch (...) + { + // neither a sequential MED file, nor a distributed MED file => error + mState = MULTIPR_OBJ_STATE_ERROR; + throw IOException("file is neither a sequential, nor a distributed MED file", __FILE__, __LINE__); + } + } +} + +ostream& operator<<(ostream& pOs, Obj& pO) +{ + pOs << "Obj:" << endl; + pOs << " Name:" << pO.mMEDfilename << endl; + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Obj.hxx b/src/MULTIPR/MULTIPR_Obj.hxx new file mode 100755 index 000000000..f6474bc62 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Obj.hxx @@ -0,0 +1,360 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_GaussLoc.hxx + * + * \brief Class MULTIPR_Obj. + * This class is used as an interface to implement MULTIPR services in the salome MODULE + * as described in the spec/design doc. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_OBJ_HXX +#define MULTIPR_OBJ_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include <iostream> +#include <string> +#include <vector> +#include <list> + +#include <boost/thread/recursive_mutex.hpp> + +#include "MULTIPR_Globals.hxx" + +namespace multipr +{ + +class MeshDis; +class Group; +class Profil; + +//***************************************************************************** +// Class Obj +//***************************************************************************** + +enum ObjState +{ + MULTIPR_OBJ_STATE_ERROR, + MULTIPR_OBJ_STATE_RESET, + MULTIPR_OBJ_STATE_SEQ_INIT, + MULTIPR_OBJ_STATE_SEQ, + MULTIPR_OBJ_STATE_DIS, + MULTIPR_OBJ_STATE_DIS_MEM +}; // enum ObjState + + +class Obj +{ +public: + + /** + * Builds an empty Gauss reference (default constructor). + */ + Obj(); + + /** + * Destructor. Removes everything. + */ + ~Obj(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + /** + * Associate a MED file (sequential or distributed) with this object. + * This method also: + * - reset everything before starting + * - determine if the given file is a sequential (SEQ) or a distributed (DIS) MED file + * - read the ASCII master file if it is a distributed MED file + * - set state + */ + void create(const char* pMEDfilename); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //-------------------------------------------------------------------- + + /** + * Returns true iff this obj represents a valid sequential MED file. + * \return true iff this obj represents a valid sequential MED file. + */ + bool isValidSequentialMEDFile() const { return (mState == MULTIPR_OBJ_STATE_SEQ) || (mState == MULTIPR_OBJ_STATE_SEQ_INIT); } + + /** + * Returns true iff this obj represents a valid distributed MED file. + * \return true iff this obj represents a valid distributed MED file. + */ + bool isValidDistributedMEDFile() const { return (mState == MULTIPR_OBJ_STATE_DIS) || (mState == MULTIPR_OBJ_STATE_DIS_MEM); } + + /** + * Returns the name of the associated MED file. + * \return the name of the associated MED file. + */ + std::string getMEDFilename() const { return mMEDfilename; } + + /** + * Returns the name of the associated sequential MED file. + * \return the name of the associated sequential MED file. + */ + std::string getSequentialMEDFilename() const; + + /** + * Defines the mesh to be processed. + * \param pMeshName name of the mesh to be partitionned. + */ + void setMesh(const char* pMeshName); + + /** + * Returns the name of mesh, defined via setMesh(). + * \return the name of mesh, defined via setMesh(). + */ + std::string getMeshName() const { return mMeshName; } + + /** + * Returns the list of meshes contained in the sequential MED file. + * Assumes this object encapsulates a sequential MED file. + * \return the list of meshes contained in the sequential MED file. + */ + std::vector<std::string> getMeshes() const; + + /** + * Returns the list of fields contained in the sequential MED file. + * Assumes this object encapsulates a sequential MED file. + * \param pPartList The list of parts to get the fields from (separator is '|'). + * \return the list of fields contained in the sequential MED file. + */ + std::vector<std::string> getFields(const char* pPartList) const; + + /** + * Returns the number of timestamps for a given field. + * Assumes this object encapsulates a sequential MED file. + * \param pFieldName name of any field. + * \param pPartList The list of parts to get the time stamps from (separator is '|'). + * \return the number of timestamps for a given field; 0 if field not found. + */ + int getTimeStamps(const char* pPartList, const char* pFieldName) const; + + /** + * Get the minimum and maximum value of a part's field. + * \param pPartName The name of the part. + * \param pFieldName The name of the field. + * \param pMin The mininum value to fill. + * \param pMax The maxinum value to fill. + */ + void getFieldMinMax(const char* pPartName, const char* pFieldName, float& pMin, float& pMax); + + /** + * Returns the name of all partitions. + * Assumes this object encapsulates a distributed MED file. + * \return the name of all partitions. + */ + std::vector<std::string> getParts() const; + + /** + * Returns all information about a part. + * \param pPartName name of the part. + * \return all information about a part. + */ + std::string getPartInfo(const char* pPartName) const; + + /** + * Removes all the part beginning by pPrefixPartName from the distributed MED file. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". + * Assume this object encapsulates a distributed MED file. + * \param pPrefixPartName name of the part. + */ + void removeParts(const char* pPrefixPartName); + + + //--------------------------------------------------------------------- + // Algorithms + //-------------------------------------------------------------------- + + /** + * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file. + * Assumes: + * - the file is in MED format and can be read using MED file v2.3. + * - the file is sequential (not a distributed MED). + * - the file only contains TETRA10 elements (dimension of space and mesh is 3). + * - the file have no profil. + * \return the name of each part. + * \throw RuntimeException if any error occurs. + */ + std::vector<std::string> partitionneDomaine(); + + /** + * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * - nbPart > 1 + * \param pPartName name of the part to be splitted. + * \param pNbParts number of parts; must be > 1. + * \param pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch. + * \return the name of each part. + * \throw RuntimeException if any error occurs. + */ + std::vector<std::string> partitionneGroupe( + const char* pPartName, + int pNbParts, + int pPartitionner=0); + + /** + * Creates 3 resolutions of the given part of a distributed MED file (V2.3). + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGroupe() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * \param pPartName name of the part to be decimated. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + * \return the name of each part. + * \throw RuntimeException if any error occurs. + */ + std::vector<std::string> decimePartition( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParam); + + /** + * Works exactly like the above method and has the same parameters + * and returning value meaning, except the last additional parameter. + * \param pEmptyMeshes list of names of empty meshes, corresponding to medium and/or lower resolution. + */ + std::vector<std::string> decimePartition( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParam, + std::list<std::string>& pEmptyMeshes); + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + */ + std::string evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams); + + /** + * Get mesh statistics. + * \param pStats [the number of mesh] space [number of gauss points] + * \param pPartName The path to the part. + */ + void getMEDInfo(char* pStats, char* pPartName); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Saves the associated MED file if necessary. + * \param pPath path where to save the file. + * \throw IOException if any i/o error occurs. + */ + void save(const char* pPath); + + /** + * Reset save progress to zero. + * \param pPercents current save progress in percents. + */ + void resetProgress(); + + /** + * Obtain save progress. + * \return current save progress in percents. + */ + int getProgress(); + + /** + * Saves the associated MED file to the given location. + * Calling this method does not influence the object state. + * + * \note This method is mentioned to be used only in persistence. + * + * \param pPath path where to save the file. + * \throw IOException if any i/o error occurs. + */ + void savePersistent(const char* pPath); + + /** + * Works like \a create(), but assumes that the distributed MED file was moved + * from the original location and its ASCII master file needs to be updated. + * + * \note This method is mentioned to be used only in persistence. + */ + void restorePersistent(const char* pMEDfilename); + + /** + * Dumps any Obj to the given output stream. + * \param pOs any output stream. + * \param pO any Obj. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Obj& pO); + +private: + + /** + * Returns the list of parts contained in the current distributed mesh. + * \return the list of parts contained in the current distributed mesh. + * \throw IllegalStateException if the distributed mesh does not still exist. + */ + std::vector<std::string> getListParts() const; + +private: + + std::string mMEDfilename; /**< Name of the MED file: sequential or distributed. */ + std::string mMeshName; /**< Mesh to be partitionned. */ + ObjState mState; /**< State of this object. */ + MeshDis* mMeshDis; /**< Distributed mesh. */ + bool mDoReadWriteFields;/**< Flag for optimized domain split. */ + std::vector<Group*> mGroups; /**< We need to keep the groups for optimized domain split. */ + GaussIndexList mGaussList; /**< We need to keep gauss information for optimized domain split. */ + std::vector<Profil*> mProfils; /**< We need to keep the profiles for optimized domain split. */ + boost::recursive_mutex mWriteMutex; /**< Write progress thread safe access. */ + + std::string mPrevPath; + +private: + + // do not allow copy constructor + Obj(const Obj&); + + // do not allow copy + Obj& operator=(const Obj&); + + // do not allow operator == + bool operator==(const Obj&); + +}; // class Obj + + +} // namespace MULTIPR + + +#endif // MULTIPR_OBJ_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_PointOfField.hxx b/src/MULTIPR/MULTIPR_PointOfField.hxx new file mode 100755 index 000000000..bcf340654 --- /dev/null +++ b/src/MULTIPR/MULTIPR_PointOfField.hxx @@ -0,0 +1,100 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_PointOfField.hxx + * + * \brief Class PointOfField used for decimation. PointOfField = a point in a field = coordinates + value. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_POINTOFFIELD_HXX +#define MULTIPR_POINTOFFIELD_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + + +namespace multipr +{ + + +//***************************************************************************** +// Class PointOfField +//***************************************************************************** + +class PointOfField +{ +public: + + /** + * Builds an empty set of elements (default constructor). + */ + PointOfField() { reset(); } + + /** + * Constructor. + * \param pX x-coordinate of the point. + * \param pY y-coordinate of the point. + * \param pZ z-coordinate of the point. + * \param pVal value of the field at the given point. + */ + PointOfField(med_float pX, med_float pY, med_float pZ, med_float pVal) + { + mXYZ[0] = pX; + mXYZ[1] = pY; + mXYZ[2] = pZ; + mVal = pVal; + } + + /** + * Destructor. Removes everything. + */ + ~PointOfField() { reset(); } + + /** + * Resets this object in its state by default (empty). + */ + void reset() + { + mXYZ[0] = std::numeric_limits<med_float>::quiet_NaN(); + mXYZ[1] = std::numeric_limits<med_float>::quiet_NaN(); + mXYZ[2] = std::numeric_limits<med_float>::quiet_NaN(); + mVal = std::numeric_limits<med_float>::quiet_NaN(); + } + + /** + * Dumps any PointOfField to the given output stream. + * \param pOs any output stream. + * \param pP any PointOfField. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, PointOfField& pP) + { + pOs << "[ " << pP.mXYZ[0] << " ; " << pP.mXYZ[1] << " ; " << pP.mXYZ[2] << "]: " << pP.mVal; + return pOs; + } + +public: + + med_float mXYZ[3]; /**< 3D-position. */ + med_float mVal; /**< Value of the field at this point. */ + +}; // class PointOfField + + +} // namespace multipr + + +#endif // MULTIPR_FIELDPOINT_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Profil.cxx b/src/MULTIPR/MULTIPR_Profil.cxx new file mode 100755 index 000000000..11649e374 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Profil.cxx @@ -0,0 +1,350 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Profil.cxx + * + * \brief see MULTIPR_Profil.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Profil.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Mesh.hxx" + +#include <iostream> + +using namespace std; + + +namespace multipr +{ + + +//***************************************************************************** +// Class Profil implementation +//***************************************************************************** + +Profil::Profil() +{ + reset(); +} + +Profil::Profil(const Profil& pProfil) +{ + strcpy(mName, pProfil.mName); + mTable = pProfil.mTable; + mBinding = pProfil.mBinding; + mGeomIdx = pProfil.mGeomIdx; +} + +Profil::~Profil() +{ + reset(); +} + + +void Profil::reset() +{ + mName[0] = '\0'; + mTable.clear(); + mBinding = Undef; + mGeomIdx = 0; +} + + +void Profil::create(const char* pName) +{ + if (pName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + reset(); + strcpy(mName, pName); +} + + + +const char* Profil::getName() const +{ + return mName; +} + +void Profil::add(med_int pElt) +{ + mTable.insert(pElt); +} + +bool Profil::find(med_int pElt) +{ + if (mTable.find(pElt) != mTable.end()) + { + return true; + } + else + { + return false; + } +} + +void Profil::filterSetOfElement(std::set<med_int>& pIn, std::set<med_int>& pOut) +{ + if (&pOut == &pIn) throw IllegalStateException("pIn and pOut must be different !", __FILE__, __LINE__); + int count = 1; + + for (std::set< med_int>::iterator it = mTable.begin(); it != mTable.end(); ++it) + { + if (pIn.find(*it) != pIn.end()) + { + pOut.insert(count); + } + ++count; + } +} + +void Profil::extractSetOfElement(const std::set<med_int>& pIn, std::set<med_int>& pOut) +{ + if (&pOut == &pIn) throw IllegalStateException("pIn and pOut must be different !", __FILE__, __LINE__); + int count = 1; + + for (std::set< med_int>::iterator it = pIn.begin(); it != pIn.end(); ++it) + { + if (mTable.find(*it) != mTable.end()) + { + pOut.insert(count); + } + ++count; + } +} + +void Profil::readMED(med_idt pMEDfile, med_int pIndexProfil) +{ + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pIndexProfil < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + // Get the profil info. + med_int numData; + med_err ret = MEDprofilInfo( + pMEDfile, + pIndexProfil, + mName, + &numData); + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + // Read the data of the profil. + med_int* dataTmp = new med_int[numData]; + ret = MEDprofilLire( + pMEDfile, + dataTmp, + mName); + if (ret != 0) throw IOException("", __FILE__, __LINE__); + for (int itData = 0 ; itData < numData ; itData++) + { + mTable.insert(dataTmp[itData]); + } + + delete[] dataTmp; +} + +void Profil::readProfilBinding(med_idt pMEDfile, char* pMeshName) +{ + if (strlen(mName) == 0) throw IllegalStateException("The name of the Profil is empty", __FILE__, __LINE__); + + int nbField; + med_err ret; + char cha[MED_TAILLE_NOM + 1]; + med_type_champ type; + char* comp; + char* unit; + med_int numComponents; + char gaussLocName[MED_TAILLE_NOM + 1]; + char profilName[MED_TAILLE_NOM + 1]; + int sizeOfData; + int sizeOfType; + unsigned char* fieldData; + bool fieldOnNodes = false; + med_entite_maillage entity; + med_geometrie_element geom; + med_int ngauss; + med_int numdt; + med_int numo; + char dtunit[MED_TAILLE_PNOM + 1]; + med_float dt; + char maa[MED_TAILLE_NOM + 1]; + med_booleen local; + med_int nmaa; + int geomIdx = 0; + + // Get the number of field in this file. + nbField = MEDnChamp(pMEDfile, 0); + if (nbField < 0) throw IOException("Can't read number of fields.", __FILE__, __LINE__); + // For each field. + for (int i = 1; i <= nbField; ++i) + { + // Get the number of component. + numComponents = MEDnChamp(pMEDfile, i); + comp = new char[numComponents * MED_TAILLE_PNOM + 1]; + unit = new char[numComponents * MED_TAILLE_PNOM + 1]; + // Get some information about the field. + ret = MEDchampInfo(pMEDfile, i, cha, &type, comp, unit, numComponents); + if (nbField < 0) throw IOException("Can't read fields info.", __FILE__, __LINE__); + // Get the size of one component. + switch (type) + { + case MED_FLOAT64: sizeOfType = 8; break; + case MED_INT64: sizeOfType = 8; break; + case MED_INT32: sizeOfType = 4; break; + case MED_INT: sizeOfType = 4; break; + default: throw IllegalStateException("Unknown field data type", __FILE__, __LINE__); + } + + // Try to figure out if the field is on nodes or on elements. + med_int numTimeStepNodes = MEDnPasdetemps( + pMEDfile, + cha, + MED_NOEUD, + (med_geometrie_element) 0); + + if (numTimeStepNodes < 0) throw IOException("Can't read fields number of time steps.", __FILE__, __LINE__); + if (numTimeStepNodes > 0) + { + // Its on nodes. + fieldOnNodes = true; + entity = MED_NOEUD; + geom = (med_geometrie_element) 0; + } + else + { + // Its on elements. + fieldOnNodes = false; + entity = MED_MAILLE; + // Get the geometry. + for (int i = 0; i < eMaxMedMesh; ++i) + { + if (MEDnPasdetemps(pMEDfile, cha, entity, CELL_TYPES[i]) > 0) + { + geom = CELL_TYPES[i]; + geomIdx = i; + break; + } + } + } + + // Get some information about the first time step. + ret = MEDpasdetempsInfo( + pMEDfile, + cha, + entity, + geom, + 1, + &ngauss, + &numdt, + &numo, + dtunit, + &dt, + maa, + &local, + &nmaa); + if (ret < 0) throw IOException("Can't read fields time steps info.", __FILE__, __LINE__); + // Get the number of values for the first time step. + med_int nval = MEDnVal( + pMEDfile, + cha, + entity, + geom, + numdt, + numo, + pMeshName, + MED_GLOBAL); + if (nval < 0) throw IOException("Can't read fields number values.", __FILE__, __LINE__); + // Read the one time step of the field. + sizeOfData = sizeOfType * numComponents * nval * 10; + unsigned char* fieldData = new unsigned char[sizeOfData]; + gaussLocName[0] = '\0'; + ret = MEDchampLire( + pMEDfile, + pMeshName, + cha, + fieldData, + MED_FULL_INTERLACE, + MED_ALL, + gaussLocName, + profilName, + MED_GLOBAL, + entity, + geom, + numdt, + numo); + delete[] fieldData; + if (ret < 0) throw IOException("Can't read field.", __FILE__, __LINE__); + // Does this field use our profile ? + if (strncmp(profilName, mName, MED_TAILLE_NOM) == 0) + { + // It does ! + if (fieldOnNodes) + { + mBinding = OnNodes; + mGeomIdx = geomIdx; + } + else + { + mBinding = OnElements; + mGeomIdx = geomIdx; + } + break; + } + } +} + +void Profil::writeMED(med_idt pMEDfile) +{ + if (pMEDfile == 0) throw IOException("pMEDfile is 0", __FILE__, __LINE__); + if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("Empty name", __FILE__, __LINE__); + if (mTable.size() == 0) throw IllegalStateException("Empty table", __FILE__, __LINE__); + int itData; + std::set<med_int>::iterator it; + med_int* dataTmp = new med_int[mTable.size()]; + for (it = mTable.begin(), itData = 0; it != mTable.end(); ++it, ++itData) + { + dataTmp[itData] = *it; + } + med_err ret = MEDprofilEcr( + pMEDfile, + dataTmp, + mTable.size(), + mName); + + if (ret != 0) throw IOException("Can't write profil", __FILE__, __LINE__); + + delete[] dataTmp; +} + + +ostream& operator<<(ostream& pOs, Profil& pP) +{ + pOs << "Profil:" << endl; + pOs << " Name=|" << pP.mName << "|" << endl; + pOs << " Size=" << pP.mTable.size() << endl; + + pOs << " Entities=["; + for (std::set<med_int>::iterator it = pP.mTable.begin(); + it != pP.mTable.end(); ++it) + { + pOs << *it << " "; + } + pOs << "]"; + + return pOs; +} + + +} // namespace multipr + +// EOF diff --git a/src/MULTIPR/MULTIPR_Profil.hxx b/src/MULTIPR/MULTIPR_Profil.hxx new file mode 100755 index 000000000..fba60ff0b --- /dev/null +++ b/src/MULTIPR/MULTIPR_Profil.hxx @@ -0,0 +1,204 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Profil.hxx + * + * \brief Class Profil used to managed MED profil. + * Profil is just a list of indices related to elements (NODES, CELLS). + * !!! currently not used !!! + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_PROFIL_HXX +#define MULTIPR_PROFIL_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + +extern "C" +{ + #include "med.h" +} + +#include <vector> +#include <set> + +namespace multipr +{ + +enum eProfilBinding +{ + Undef, + OnNodes, + OnElements +}; + +//***************************************************************************** +// Class Profil +//***************************************************************************** + +class Profil +{ +public: + + /** + * Builds an empty profil (default constructor). + */ + Profil(); + + /** + * Copy constructor. + * \param pProfil The profil to copy. + */ + Profil(const Profil& pProfil); + + /** + * Destructor. Removes everything. + */ + ~Profil(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + /** + * Creates a profil from its name (reset before). + * \param pName name of the profil to be created. + * \throw NullArgumentException if pName is NULL. + */ + void create(const char* pName); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the name of this profil. + * \return the name of this profil. + */ + const char* getName() const; + + /** + * Get the complete set of elements of this profile. + * \return The set of elements. + */ + std::set< med_int>& getSet() { return mTable; } + + /** + * Adds a new element to this profil. + * \param pElt element to be added; must be >= 1. + */ + void add(med_int pElt); + + /** + * Find the given element in the profile. + * \param pElt The index of the element. + * \return true if the element was found. + */ + bool find(med_int pElt); + + /** + * Assign a set of element to this profile. + * \param pElt The set of element to assign. + */ + void set(std::set< med_int>& pElt) { this->mTable = pElt; } + + /** + * Select the elements of pIn contained in this profile. The two parameters pIn + * and pOut MUST be different. + * \param pIn Set of elements to filter. + * \param pOut The result. + * \throw IllegalStateException if pIn and pOut are not different. + */ + void filterSetOfElement(std::set<med_int>& pIn, std::set<med_int>& pOut); + + /** + * Extract a profil. The two parameters pIn + * and pOut MUST be different. + * \param pIn Set of elements to extract. + * \param pOut The result. + * \throw IllegalStateException if pIn and pOut are not different. + */ + void extractSetOfElement(const std::set<med_int>& pIn, std::set<med_int>& pOut); + + /** + * Returns the association of the profile. + * \return OnNodes or OnElements or Undef. + */ + eProfilBinding getBinding() { return mBinding; } + + /** + * Return the index of the geometry (if any) associated with this profile. + * If this profile is on nodes it will return 0. Since the geometry index starts at + * 0 use getBinding to know if its on elements. + * \return the index of the geometry. + */ + unsigned getGeomIdx() { return mGeomIdx; } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a Profil from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pIndexProfil index of the profil to be read; must be >= 1. + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, med_int pIndexProfil); + + /** + * Try to find in the MED file if this profile is associated to the nodes + * or the elements. If the profile is associated with elements it will get the + * index of the geometry. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName The name of the mesh. + * \throw IllegalStateException if the profile is empty. + */ + void readProfilBinding(med_idt pMEDfile, char* pMeshName); + + /** + * Writes this profil to a MED file. + * \param pMEDfile any valid MED file opened for writing. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile); + + /** + * Dumps any Profil to the given output stream. + * \param pOs any output stream. + * \param pP any Profil. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Profil& pP); + +private: + + char mName[MED_TAILLE_NOM + 1]; /**< Name of the profil. */ + std::set<med_int> mTable; /**< Table of elements. */ + eProfilBinding mBinding; /**< Profil of nodes or elements. */ + unsigned mGeomIdx; /**< If this profile is on elements, the index of the geometry. */ + +private: + + // do not allow copy + Profil& operator=(const Profil&); + + // do not allow operator == + bool operator==(const Profil&); + +}; // class Profil + + +} // namespace MULTIPR + + +#endif // MULTIPR_PROFIL_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_ProgressCallback.hxx b/src/MULTIPR/MULTIPR_ProgressCallback.hxx new file mode 100755 index 000000000..22f6938d4 --- /dev/null +++ b/src/MULTIPR/MULTIPR_ProgressCallback.hxx @@ -0,0 +1,110 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_ProgressCallback.hxx + * + * \brief Class MULTIPR_ProgressCallback + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_PROGRESS_CALLBACK_HXX +#define MULTIPR_PROGRESS_CALLBACK_HXX + +//***************************************************************************** +// Includes section +//***************************************************************************** + + +//***************************************************************************** +// Class MULTIPR_ProgressCallback +// Used to provide feedback on the progress of a slow operation. +//***************************************************************************** + +class MULTIPR_ProgressCallback +{ +public: + + /** + * Builds a new MULTIPR_ProgressCallback (default constructor). + */ + MULTIPR_ProgressCallback() { init(100); } + + /** + * Destructor. Removes everything. + */ + virtual ~MULTIPR_ProgressCallback() { /* do nothing */ } + + /** + * Starts to provide feedback on the progress of a slow operation. + * \param pTaskTitle name of the task to be monitored. + * \param pNumSteps number of steps in the task. + */ + virtual void start(const char* pTaskTitle, int pNumSteps) = 0; + + /** + * Moves on the current amount of progress made. + */ + void moveOn() { mCurrentStep++; float percent = float(mCurrentStep)/float(mTotalSteps)*100.0f; progress(percent); } + + /** + * Termines to provide feedback. + */ + virtual void done() = 0; + +protected: + + /** + * Resets this progress callback. + * \param pNumSteps number of steps in the task to be monitored. + */ + void init(int pNumSteps) { mCurrentStep = 0; mTotalSteps = pNumSteps; } + + /** + * Callback. Called on each progress. + * \param pPercent percent accomplished. + */ + virtual void progress(float pPercent) = 0; + +private: + + int mCurrentStep; + int mTotalSteps; + +}; // class MULTIPR_ProgressCallback + + +//***************************************************************************** +// Class MULTIPR_EmptyMeshCallback +// Used to provide feedback when an empty mesh is produced. +//***************************************************************************** + +class MULTIPR_EmptyMeshCallback +{ +public: + + /** + * Builds a new MULTIPR_EmptyMeshCallback (default constructor). + */ + MULTIPR_EmptyMeshCallback() { /* do nothing */ } + + /** + * Destructor. Removes everything. + */ + virtual ~MULTIPR_EmptyMeshCallback() { /* do nothing */ } + + /** + * Callback. Called each time an empty mesh is produced. + * \param pInfo information related to the empty mesh. + */ + virtual void reportEmptyMesh(std::string pInfo) = 0; + +}; // class MULTIPR_EmptyMeshCallback + + +#endif // MULTIPR_PROGRESS_CALLBACK_HXX + +// EOF diff --git a/src/MULTIPR/MULTIPR_Utils.cxx b/src/MULTIPR/MULTIPR_Utils.cxx new file mode 100755 index 000000000..ed0a3e95f --- /dev/null +++ b/src/MULTIPR/MULTIPR_Utils.cxx @@ -0,0 +1,366 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Utils.cxx + * + * \brief see MULTIPR_Utils.hxx + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +//***************************************************************************** +// Includes section +//***************************************************************************** + +#include "MULTIPR_Utils.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Mesh.hxx" + +#include <iostream> + +using namespace std; + +//***************************************************************************** +// Implementation +//***************************************************************************** + +void multipr::trim(char* pStr, char pChar) +{ + int len = strlen(pStr) - 1; + int p = len; + while (pStr[p] == pChar) + { + p--; + } + if (p != len) + { + pStr[p + 1] = '\0'; + } +} + + +bool multipr::startsWith(const char* pStr, const char* pStrPrefix) +{ + int i = 0; + while ((pStr[i] != '\0') && (pStrPrefix[i] != '\0') && (pStr[i] == pStrPrefix[i])) + { + i++; + } + return (pStrPrefix[i] == '\0'); +} + + +string multipr::removeExtension(const char* pFilename, const char* pExtension) +{ + string strPrefix(pFilename); + strPrefix.erase(strPrefix.rfind(pExtension), strlen(pExtension)); + + return strPrefix; +} + + +string multipr::getFilenameWithoutPath(const char* pFilename) +{ + char* res = strrchr(pFilename, '/'); + if (res == NULL) + { + return pFilename; + } + else + { + char* name = res + 1; + return name; + } +} + + +string multipr::getPath(const char* pFilename) +{ + // find (reverse) the first occurrence of '/' in the given string + std::string aFilename(pFilename); + std::string::size_type aPos = aFilename.rfind('/'); + + if ( aPos == std::string::npos ) + return ""; + + aFilename = aFilename.substr( 0, aPos + 1 ); + while ( true ) { + aPos = aFilename.find( "//" ); + + if ( aPos == std::string::npos ) + break; + + aFilename.replace( aPos, 2, "/" ); + } + + return aFilename; +} + + +void multipr::copyFile(const char* pFilename, const char* pDestDir) +{ + std::string srcDir = multipr::getPath(pFilename); + if (strcmp(srcDir.c_str(), pDestDir) == 0) return; + + std::string filenameWithoutPath = multipr::getFilenameWithoutPath(pFilename); + std::string pDstFilename (pDestDir); + pDstFilename += filenameWithoutPath; + + // open binary source file + FILE* src = fopen(pFilename, "rb"); + if (src == NULL) return; + + // open (create) binary destination file + FILE* dst = fopen(pDstFilename.c_str(), "wb"); + if (dst == NULL) return; + + const int size = 65536; // size of buffer is 64Kb + char* buf = new char[size]; + int ret; + ret = fread(buf, 1, size, src); + while (ret != 0) + { + fwrite(buf, 1, ret, dst); // write to destination + ret = fread(buf, 1, size, src); // read from source + } + + delete[] buf; + fclose(src); + fclose(dst); +} + + +void multipr::printArray2D( + const med_float* pData, + const int pNumElt, + const int pDimElt, + const char* pPrefix) +{ + for (int itElt = 0 ; itElt < pNumElt ; itElt++) + { + cout << pPrefix << " " << (itElt + 1) << ": "; + for (int itDim = 0 ; itDim < pDimElt ; itDim++) + { + cout << pData[itElt * pDimElt + itDim] << " "; + } + cout << endl; + } +} + + +string multipr::realToString(med_float mV) +{ + char str[32]; + sprintf(str, "%lf", mV); + trim(str, '0'); + int len = strlen(str); + if (str[len - 1] == '.') + { + str[len] = '0'; + str[len + 1] = '\0'; + } + return string(str); +} + + +vector<string> multipr::getListMeshes(const char* pMEDfilename) +{ + if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); + + vector<string> res; + med_err ret; + + //--------------------------------------------------------------------- + // Open MED file (READ_ONLY) + //--------------------------------------------------------------------- + med_idt file = MEDouvrir(const_cast<char*>(pMEDfilename), MED_LECTURE); // open MED file for reading + if (file <= 0) throw multipr::IOException("MED file not found or not a sequential MED file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read name of meshes + //--------------------------------------------------------------------- + med_int nbMeshes = MEDnMaa(file); + if (nbMeshes <= 0) throw multipr::IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); + + // for each mesh in the file (warning: first mesh is number 1) + for (int itMesh = 1 ; itMesh <= nbMeshes ; itMesh++) + { + char meshName[MED_TAILLE_NOM + 1]; + + med_int meshDim; + med_maillage meshType; + char meshDesc[MED_TAILLE_DESC + 1]; + + ret = MEDmaaInfo( + file, + itMesh, + meshName, + &meshDim, + &meshType, + meshDesc); + + if (ret != 0) throw multipr::IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); + + res.push_back(meshName); + } + + //--------------------------------------------------------------------- + // Close the MED file + //--------------------------------------------------------------------- + ret = MEDfermer(file); + if (ret != 0) throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); + + return res; +} + + +void multipr::getListScalarFields(const char* pMEDfilename, vector<pair<string, int> >& pFields, bool pAddNbGaussPoint, const char *pMeshName) +{ + if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); + med_err ret; + med_int ngauss = 0; + bool isOnNodes = true; + //--------------------------------------------------------------------- + // Open MED file (READ_ONLY) + //--------------------------------------------------------------------- + med_idt file = MEDouvrir(const_cast<char*>(pMEDfilename), MED_LECTURE); // open MED file for reading + if (file <= 0) throw multipr::IOException("MED file not found or not a sequential MED file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read number of fields + //--------------------------------------------------------------------- + med_int numFields = MEDnChamp(file, 0); + if (numFields < 0) throw IOException("Can't read number of fields.", __FILE__, __LINE__); + if (numFields == 0) + { + return ; + } + + //--------------------------------------------------------------------- + // For each field, read its name + //--------------------------------------------------------------------- + for (int itField = 1 ; itField <= numFields ; itField++) + { + char* name = new char[MED_TAILLE_NOM + 1024]; + med_type_champ type; + med_int numComponents = MEDnChamp(file, itField); + + if (numComponents < 0) throw IOException("Number of component less than zero.", __FILE__, __LINE__); + + // collect scalar field only (not vectorial fields) + if (numComponents != 1) + { + continue; + } + // temporary buffers + char* strComponent = new char[numComponents * MED_TAILLE_PNOM + 1]; + char* strUnit = new char[numComponents * MED_TAILLE_PNOM + 1]; + strComponent[0] = '\0'; + strUnit[0] = '\0'; + + // Get field info. + med_err ret = MEDchampInfo( + file, + itField, + name, + &(type), + strComponent, + strUnit, + numComponents); + delete[] strUnit; + delete[] strComponent; + if (ret != 0) throw IOException("Can't get information on a field.", __FILE__, __LINE__); + + // Get number of time step on nodes. + med_int numTimeStamps = MEDnPasdetemps( + file, + name, + MED_NOEUD, + (med_geometrie_element) 0); + if (numTimeStamps < 0) throw IOException("Can't get number of time steps on nodes", __FILE__, __LINE__); + + // Get the number of time step on elements. + if (numTimeStamps == 0) + { + for (int i = 0; i < eMaxMedMesh; ++i) + { + numTimeStamps = MEDnPasdetemps( + file, + name, + MED_MAILLE, + CELL_TYPES[i]); + if (numTimeStamps > 0) + { + isOnNodes = false; + break; + } + } + } + + if (numTimeStamps < 0) throw IOException("Can't get number of time steps on elements", __FILE__, __LINE__); + // For GUI only : add the nomber of gauss points to the string. + if (pAddNbGaussPoint == true && pMeshName != NULL) + { + char* tmp = new char[1024]; + char* tmp2 = new char[1024]; + med_booleen local; + med_int numdt, numo, nmaa; + med_float dt; + med_int nb_values = -1; + + if (isOnNodes) + { + // Get number of gauss points on nodes. + ret = MEDpasdetempsInfo(file, name, MED_NOEUD, (med_geometrie_element) 0, 1, &ngauss, &numdt, &numo, tmp2, &dt, tmp, &local, &nmaa); + nb_values = MEDnVal(file, name, MED_NOEUD,(med_geometrie_element) 0, numdt, numo, const_cast<char*>(pMeshName), MED_COMPACT); + } + else + { + // Get number of gauss points on elements. + // For each geometry type. + for (int itCell = 0 ; itCell < eMaxMedMesh ; ++itCell) + { + tmp[0] = '\0'; + // For each time step. + for (int j = 1; j <= numTimeStamps; ++j) + { + ret = MEDpasdetempsInfo(file, name, MED_MAILLE, const_cast<med_geometrie_element*>(CELL_TYPES)[itCell], j, &ngauss, &numdt, &numo, tmp2, &dt, tmp, &local, &nmaa); + // If we can get info on this field, it must exist. + if (ret == 0) + { + nb_values = MEDnVal(file, name, MED_MAILLE,const_cast<med_geometrie_element*>(CELL_TYPES)[itCell], numdt, numo, const_cast<char*>(pMeshName), MED_COMPACT); + if (nb_values > 0) + { + break; + } + } + } + // We got what we need : don't need to go further. + if (ret == 0) + { + break; + } + + } + } + tmp[0] = '\0'; + sprintf(tmp, "%s : %d gauss points", name, nb_values); + sprintf(name, "%s", tmp); + } + + // add the pair(name, #time stamps) to the result + pFields.push_back(make_pair(name, numTimeStamps)); + } + + //--------------------------------------------------------------------- + // Close the MED file + //--------------------------------------------------------------------- + ret = MEDfermer(file); + if (ret != 0) throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); +} + + +// EOF diff --git a/src/MULTIPR/MULTIPR_Utils.hxx b/src/MULTIPR/MULTIPR_Utils.hxx new file mode 100755 index 000000000..e77bec718 --- /dev/null +++ b/src/MULTIPR/MULTIPR_Utils.hxx @@ -0,0 +1,132 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file MULTIPR_Utils.hxx + * + * \brief Some useful miscellaneous tools. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#ifndef MULTIPR_UTILS_HXX +#define MULTIPR_UTILS_HXX + +extern "C" +{ + #include "med.h" +} + +#include <string> +#include <vector> + + +namespace multipr +{ + + +/** + * Removes all the pChar at the end of the string. + * \param pStr any valid C string ending with the char '\0'. + * \param pChar any char; SPACE by default. + * \return the same string where the ending spaces have been removed. + */ +void trim(char* pStr, char pChar=' '); + + +/** + * Returns true iff the given string starts by prefix. + * \param pStr any valid C string ending with the char '\0'. + * \param pStrPrefix any valid C string ending with the char '\0'. + * \return true iff the given string starts by prefix. + */ +bool startsWith(const char* pStr, const char* pStrPrefix); + + +/** + * Removes the extension (suffix) of a filename. + * Example: removeExtension("agregat100grains_12pas.med", ".med") -> "agregat100grains_12pas" + * \param pPilename any valid C string ending with the char '\0'. + * \param pExtension any valid C string ending with the char '\0'. + * \return the filename without extension. + */ +std::string removeExtension(const char* pFilename, const char* pExtension); + + +/** + * Returns the name of the file, excluding the path. + * Example: getFilenameWithoutPath("/home/data/agregat100grains_12pas.med") -> "agregat100grains_12pas.med" + * \param pPilename any valid C string ending with the char '\0'. + * \return the name of the file, excluding the path. + */ +std::string getFilenameWithoutPath(const char* pFilename); + + +/** + * Returns the path of the filename (which may be relative or absolute). + * Example: getPath("/home/data/agregat100grains_12pas.med") -> "/home/data/" + * \param pPilename any valid C string ending with the char '\0'. + * \return the path of the filename (which may be relative or absolute). + */ +std::string getPath(const char* pFilename); + + +/** + * Copies the given file into a directory. + * \param pFilename name of any file to be copied. + * \param pDestDir destination directory. + */ +void copyFile(const char* pFilename, const char* pDestDir); + + +/** + * Prints all the elements of a 2D array. + * \param pData all the data (should contain pNumberOfElements * pDimOfElements values) + * \param pNumElt number of elements to display. + * \param pDimElt Dimension of elements. + * \param pPrefix string to display before each element. + */ +void printArray2D( + const med_float* pData, + const int pNumElt, + const int pDimElt, + const char* pPrefix); + + +/** + * Converts any float value to a string (remove unecessary 0). + * \param mV any float value. + */ +std::string realToString(med_float mV); + + +/** + * Returns the name of all meshes contained in a sequential MED file. + * \param pMEDfilename name of any valid sequential MED file; must not be NULL. + * \return a list of mesh names. + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any other error occurs while reading MED file. + */ + std::vector<std::string> getListMeshes(const char* pMEDfilename); + + + /** + * For each scalar field in a sequential MED file, returns its name and the related number of time stamps. + * Do not returns info about vectorial fields (because, currently, decimation can only be performed on scalar fields). + * \param pMEDfilename name of any valid sequential MED file; must not be NULL. + * \param pFields The information on the fields. + * \param pAddNbGaussPoint If set to true, the number of gauss point of each field is added. + * \param pMeshName Mesh name used if pAddNbGaussPoint is true. + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any other error occurs while reading MED file. + */ + void getListScalarFields(const char* pMEDfilename, std::vector<std::pair<std::string, int> >& pFields, bool pAddNbGaussPoint = false, const char *pMeshName = NULL); + +} // namespace MULTIPR + + +#endif // MULTIPR_UTILS_HXX + +// EOF diff --git a/src/MULTIPR/Makefile.am b/src/MULTIPR/Makefile.am new file mode 100644 index 000000000..0aafc5b70 --- /dev/null +++ b/src/MULTIPR/Makefile.am @@ -0,0 +1,89 @@ +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMULTIPR_API.la + +salomeinclude_HEADERS= \ +MULTIPR_API.hxx \ +MULTIPR_DecimationAccel.hxx \ +MULTIPR_DecimationFilter.hxx \ +MULTIPR_Elements.hxx \ +MULTIPR_Exceptions.hxx \ +MULTIPR_Family.hxx \ +MULTIPR_Field.hxx \ +MULTIPR_GaussLoc.hxx \ +MULTIPR_Globals.hxx \ +MULTIPR_MeshDis.hxx \ +MULTIPR_Mesh.hxx \ +MULTIPR_Nodes.hxx \ +MULTIPR_PointOfField.hxx \ +MULTIPR_Profil.hxx \ +MULTIPR_Utils.hxx \ +MULTIPR_Obj.hxx \ +MULTIPR_ProgressCallback.hxx + +dist_libMULTIPR_API_la_SOURCES= \ +MULTIPR_API.cxx \ +MULTIPR_Mesh.cxx \ +MULTIPR_Profil.cxx \ +MULTIPR_GaussLoc.cxx \ +MULTIPR_Field.cxx \ +MULTIPR_Nodes.cxx \ +MULTIPR_Elements.cxx \ +MULTIPR_Family.cxx \ +MULTIPR_MeshDis.cxx \ +MULTIPR_DecimationFilter.cxx \ +MULTIPR_DecimationAccel.cxx \ +MULTIPR_Utils.cxx \ +MULTIPR_Obj.cxx + +libMULTIPR_API_la_CPPFLAGS= $(MED2_INCLUDES) @CXXTMPDPTHFLAGS@ -Wall -pthread $(BOOST_CPPFLAGS) \ + -I$(srcdir)/../MEDWrapper/Factory \ + -I$(srcdir)/../MEDWrapper/Base \ + -I$(srcdir)/../MEDMEM \ + -I$(srcdir)/../MEDSPLITTER \ + -I$(top_builddir)/salome_adm/unix +libMULTIPR_API_la_LDFLAGS= $(MED2_LIBS) -lm -lmed \ + ../MEDWrapper/Factory/libMEDWrapper.la \ + ../MEDWrapper/Base/libMEDWrapperBase.la \ + ../MEDMEM/libmedmem.la \ + ../MEDSPLITTER/libmedsplitter.la + +if MED_ENABLE_KERNEL + libMULTIPR_API_la_CPPFLAGS+= ${KERNEL_CXXFLAGS} + libMULTIPR_API_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace +#libMULTIPR_API_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSalomeContainer -lOpUtil -lSALOMELocalTrace +endif + +# Executables targets +bin_PROGRAMS= multipr + +dist_multipr_SOURCES= multipr.cxx + +multipr_CPPFLAGS= $(libMULTIPR_API_la_CPPFLAGS) +multipr_LDADD= $(libMULTIPR_API_la_LDFLAGS) \ + ../MEDWrapper/V2_1/Core/libmed_V2_1.la \ + $(BOOST_LIBS) -lboost_thread${BOOST_LIBSUFFIX} \ + ../MEDWrapper/V2_1/Wrapper/libMEDWrapper_V2_1.la \ + ../MEDWrapper/V2_2/libMEDWrapper_V2_2.la \ + ../MEDWrapper/Base/libMEDWrapperBase.la \ + libMULTIPR_API.la diff --git a/src/MULTIPR/multipr.cxx b/src/MULTIPR/multipr.cxx new file mode 100755 index 000000000..b06f612d6 --- /dev/null +++ b/src/MULTIPR/multipr.cxx @@ -0,0 +1,793 @@ +// Project MULTIPR, IOLS WP1.2.1 - EDF/CS +// Partitioning/decimation module for the SALOME v3.2 platform + +/** + * \file multipr.cxx + * + * \brief Standalone command line application of the MULTIPR component. + * The application aims to reduce large data set to allow interactive visualization. + * Its two main function are the following: + * 1. Splits any TETRA10 mesh contained in a MED file. + * a. Builds a distributed MED file by extracting all the groups from a sequential MED file. + * b. Splits a part of distributed MED file. + * 2. Decimates fields to produce multi-resolution data set. + * + * Return 0 if application succeed, 1 otherwise (failure). + * + * See http://www.salome-platform.org to learn more about Salome or MED. + * + * \author Olivier LE ROUX - CS, Virtual Reality Dpt + * + * \date 01/2007 + */ + +#include "MULTIPR_API.hxx" +#include "MULTIPR_Obj.hxx" +#include "MULTIPR_Mesh.hxx" +#include "MULTIPR_MeshDis.hxx" +#include "MULTIPR_Exceptions.hxx" +#include "MULTIPR_Utils.hxx" + +#include <iostream> +#include <vector> +#include <string> + +using namespace std; + + +// This command line application can use 2 differents API to do the same work. +// If MULTIPR_USE_OBJ_API is defined then this command line application used the MULTIPR_Obj API; +// otherwise, it uses the MULTIPR_API +//#define MULTIPR_USE_OBJ_API + + +const int MULTIPR_APP_OK = 0; +const int MULTIPR_APP_FAILED = 1; + + +/** + * Enumerates all the usages of this application. + */ +enum Usage +{ + MULTIPR_USAGE_UNKNOWN, + MULTIPR_USAGE_DISPLAY_HELP, + MULTIPR_USAGE_AUTOTEST, + MULTIPR_USAGE_PARTITION1, + MULTIPR_USAGE_PARTITION2, + MULTIPR_USAGE_DECIMATION, + MULTIPR_USAGE_MERGE, + MULTIPR_USAGE_INFO +}; + + +/** + * Enumerates all the possible errors. + */ +enum Error +{ + MULTIPR_APP_NO_ERROR, + MULTIPR_APP_UNKNOWN_USAGE, + MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS, + MULTIPR_APP_ILLEGAL_ARGUMENT, + MULTIPR_APP_FILE_NOT_FOUND, + MULTIPR_APP_IO_ERROR, + MULTIPR_APP_UNDEFINED_ERROR +}; + + +// global variables used to configure the application +int g_usage = 0; +int g_errorCode = MULTIPR_APP_NO_ERROR; +char* g_medFilename = NULL; +char* g_meshName = NULL; +char* g_partName = NULL; +int g_nbParts = 0; +int g_splitter = multipr::MULTIPR_METIS; +char* g_filterName = NULL; +char* g_fieldName = NULL; +int g_fieldTimeStepIt = 0; +float g_decimThresholdMed = 0.0f; +float g_decimThresholdLow = 0.0f; +float g_decimRadius = 0.0f; +int g_boxing = 100; +char g_params[1024] = ""; + +// merge +std::vector<std::string> g_medFilenameSrc; +char* g_medFilenameDst = NULL; + + +/** + * \fn const char* getUsage(int usage) + * \brief returns a string describing the usage of this application. + */ +const char* getUsage(int usage) +{ + switch(usage) + { + case MULTIPR_USAGE_DISPLAY_HELP: + return "--help: display help"; + + case MULTIPR_USAGE_AUTOTEST: + return "--auto: perform all unit tests"; + + case MULTIPR_USAGE_PARTITION1: + return "--part1: extract all groups from a sequential MED file"; + + case MULTIPR_USAGE_PARTITION2: + return "--part2: split a part of a distributed MED file"; + + case MULTIPR_USAGE_DECIMATION: + return "--decim: generated level of details from a part of a distributed MED file"; + + case MULTIPR_USAGE_MERGE: + return "--merge: merge two sequential MED file if possible"; + + case MULTIPR_USAGE_INFO: + return "--info: prints all infos about a mesh in a sequential MED file"; + + default: + return "unknown"; + } +} + + +/** + * \fn void printDescription() + * \brief prints a short description of this application. + */ +void printDescription() +{ + cout << "Keywords:" << endl; + cout << " Post-processing numerical simulation, Salome platform, " << endl; + cout << " Large data set visualization, 3D meshes and fields" << endl; + cout << "Description:" << endl; + cout << " multipr is a partitionning/decimation tool of MED files." << endl; + cout << " See http://www.salome-platform.org for information about MED or Salome." << endl; + cout << " Note: current version only accept TETRA10 meshes." << endl; +} + + +/** + * \fn void printUsage() + * \brief prints "how to use" manual of this tools.2NbPart + */ +void printUsage() +{ + cout << "Usages:" << endl; + cout << " --auto Autotest: performs some unit tests on the MULTIPR API" << endl; + cout << " * Usage: --auto path (path where to find test file \"agregat100grains_12pas.med\")" << endl; + cout << " --part1 Extracts all groups from a sequential MED file (V2.2 or higher)" << endl; + cout << " * Usage: --part1 file.med meshName" << endl; + cout << " --part2 Split a group of a distributed MED file (V2.3) produced with --part1" << endl; + cout << " * Usage: --part2 file.med partName nbParts [splitter (0=METIS 1=SCOTCH)]" << endl; + cout << " --decim Generates 3 level of details (full, medium and low) from a part" << endl; + cout << " of a distributed MED file (V2.3)" << endl; + cout << " * Usage: --decim file.med partName fieldName fieldIt filterName [...]" << endl; + cout << " * Only one filter is currently available: Filtre_GradientMoyen" << endl; + cout << " * Usage: --decim file.med partName fieldName fieldIt Filtre_GradientMoyen m l radius" << endl; + cout << " where m=threshold for medium res. and l=threshold for low res.; assume m < l" << endl; + cout << " --info Dumps all infos related to a mesh in a sequential MED file" << endl; + cout << " * Usage: --info file.med [meshName]" << endl; + cout << " --help Displays this help page" << endl; + cout << endl; +} + + +/** + * \fn void printGlobals() + * \brief print current state of all global variables. + */ +void printGlobals() +{ + cout << endl; + cout << "********************************************************************************" << endl; + cout << "CONFIGURATION" << endl; + cout << "--------------------------------------------------------------------------------" << endl; + cout << "Mode : " << getUsage(g_usage) << endl; + cout << "Med filename : " << ((g_medFilename != NULL) ? g_medFilename : "UNDEFINED") << endl; + cout << "Mesh name : " << ((g_meshName != NULL) ? g_meshName : "UNDEFINED") << endl; + cout << "Part name : " << ((g_partName != NULL) ? g_partName : "UNDEFINED") << endl; + cout << "Nb parts : " << g_nbParts << endl; + cout << "Decimation:" << endl; + cout << " Field name : " << ((g_fieldName != NULL) ? g_fieldName : "UNDEFINED") << endl; + cout << " Time step iteration : " << g_fieldTimeStepIt << endl; + cout << " Filter name : " << ((g_filterName != NULL) ? g_filterName : "UNDEFINED") << endl; + cout << " Threshold for med. res. : " << g_decimThresholdMed << endl; + cout << " Threshold for low res. : " << g_decimThresholdLow << endl; + cout << " Radius : " << g_decimRadius << endl; + cout << " Boxing : " << g_boxing << endl; + cout << "********************************************************************************" << endl; + cout << endl; +} + + +/** + * \fn const char* getErrorMsg() + * \brief returns the error message corresponding to current error code. + * \return the current error message. + */ +const char* getErrorMsg() +{ + switch (g_errorCode) + { + case MULTIPR_APP_NO_ERROR: + return "no error"; + + case MULTIPR_APP_UNKNOWN_USAGE: + return "unknown usage"; + + case MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS: + return "wrong number of arguments"; + + case MULTIPR_APP_ILLEGAL_ARGUMENT: + return "illegal argument"; + + case MULTIPR_APP_FILE_NOT_FOUND: + return "file not found"; + + case MULTIPR_APP_IO_ERROR: + return "i/o error"; + + default: + return "error (undefined)"; + } +} + + +/** + * \fn void parseCommandLine(int argc, char** argv) + * \brief parses the command line and configure this application. + * \param argc number of arguments. + * \param argv array of arguments. + */ +void parseCommandLine(int argc, char** argv) +{ + if (argc == 1) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + return; + } + + if (strcmp(argv[1],"--help") == 0) + { + g_usage = MULTIPR_USAGE_DISPLAY_HELP; + } + else if (strcmp(argv[1],"--auto") == 0) + { + if (argc != 3) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_AUTOTEST; + g_medFilename = argv[2]; + } + } + else if (strcmp(argv[1],"--part1") == 0) + { + if (argc != 4) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_PARTITION1; + g_medFilename = argv[2]; + g_meshName = argv[3]; + } + } + else if (strcmp(argv[1],"--part2") == 0) + { + if ((argc != 5) && (argc != 6)) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_PARTITION2; + g_medFilename = argv[2]; + g_partName = argv[3]; + g_nbParts = atoi(argv[4]); + + if (argc == 6) + { + g_splitter = atoi(argv[5]); + } + } + } + else if (strcmp(argv[1],"--decim") == 0) + { + if (argc < 9) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + return ; + } + else + { + g_usage = MULTIPR_USAGE_DECIMATION; + g_medFilename = argv[2]; + g_partName = argv[3]; + g_fieldName = argv[4]; + g_fieldTimeStepIt = atoi(argv[5]); + g_filterName = argv[6]; + g_decimThresholdMed = atof(argv[7]); + g_decimThresholdLow = atof(argv[8]); + } + if (strcmp(g_filterName, "Filtre_GradientMoyen") == 0 && argc == 11) + { + g_decimRadius = atof(argv[9]); + g_boxing = atoi(argv[10]); + sprintf(g_params, "%lf %lf %lf %d", g_decimThresholdMed, g_decimThresholdLow, g_decimRadius, g_boxing); + } + else if (strcmp(g_filterName, "Filtre_Direct") == 0) + { + sprintf(g_params, "%lf %lf", g_decimThresholdMed, g_decimThresholdLow); + } + else + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_ILLEGAL_ARGUMENT; + } + + } + else if (strcmp(argv[1],"--merge") == 0) + { + if (argc < 7) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_MERGE; + for (int i = 2 ; i < argc-3 ; i++) + { + g_medFilenameSrc.push_back(argv[i]); + } + g_meshName = argv[argc-3]; + g_fieldName = argv[argc-2]; + if (strcmp(g_fieldName, "NULL") == 0) g_fieldName = NULL; + g_medFilenameDst = argv[argc-1]; + } + } + else if (strcmp(argv[1],"--info") == 0) + { + if ((argc != 3) && (argc != 4)) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_INFO; + g_medFilename = argv[2]; + + if (argc == 4) + { + g_meshName = argv[3]; + } + } + } + else + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_UNKNOWN_USAGE; + } +} + + +/** + * \fn int runAutotest() + * \brief performs some unit tests on the MULTIPR API. + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int runAutotest() +{ + cout << "Start autotest..." << endl; + + int ret = MULTIPR_APP_OK; + int nbPartsSupp = 100; + try + { + string strMEDfilename = g_medFilename; + strMEDfilename += "/agregat100grains_12pas.med"; + + cout << "Test file: " << strMEDfilename << endl << endl; + + //--------------------------------------------------------------------- + // Test partionneDomaine() = extract groups from a sequential MED file + //--------------------------------------------------------------------- + multipr::partitionneDomaine(strMEDfilename.c_str(), "MAIL"); + + //--------------------------------------------------------------------- + // Test partitionneGroupe() = split a group from a distributed MED file + // using MEDSPLITTER (METIS) + //--------------------------------------------------------------------- + string strDistributedMEDfilename = g_medFilename; + strDistributedMEDfilename += "/agregat100grains_12pas_groupes_maitre.med"; + + multipr::partitionneGroupe( + strDistributedMEDfilename.c_str(), + "MAIL_1", + 4, + multipr::MULTIPR_SCOTCH); + nbPartsSupp += 4; + + multipr::partitionneGroupe( + strDistributedMEDfilename.c_str(), + "MAIL_97", + 3, + multipr::MULTIPR_METIS); + nbPartsSupp += 3; + + //--------------------------------------------------------------------- + // Test decimePartition() = generate 2 lower resolution of a mesh + // using decimation based on gradient + //--------------------------------------------------------------------- + multipr::decimePartition( + strDistributedMEDfilename.c_str(), + "MAIL_98", + "SIG_____SIEF_ELGA_______________", + 12, + "Filtre_GradientMoyen", + "10.0 25.0 0.3 100"); + nbPartsSupp += 2; + + multipr::decimePartition( + strDistributedMEDfilename.c_str(), + "MAIL_92", + "SIG_____SIEF_ELGA_______________", + 11, + "Filtre_GradientMoyen", + "10.0 25.0 0.5 10"); + nbPartsSupp += 2; + + multipr::decimePartition( + strDistributedMEDfilename.c_str(), + "MAIL_97_2", + "SIG_____SIEF_ELGA_______________", + 10, + "Filtre_GradientMoyen", + "10.0 25.0 0.4 20"); + nbPartsSupp += 2; + + //--------------------------------------------------------------------- + // Test passed: OK! + //--------------------------------------------------------------------- + cout << endl; + + // Check quantity of parts at the end + multipr::MeshDis meshDis; + meshDis.readDistributedMED(strDistributedMEDfilename.c_str()); + int nbParts = meshDis.getNumParts(); + cout << "Auto Test: final quantity of parts is " << nbParts + << " (must be " << nbPartsSupp << ")" << endl; + if (nbParts != nbPartsSupp) + { + cout << "Test failed: wrong quantity of parts obtained!" << endl; + cout << "Failure" << endl << endl; + ret = MULTIPR_APP_FAILED; + } + else + { + cout << "Test passed: everything seems to be OK" << endl; + cout << "OK" << endl << endl; + } + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + cout << endl; + cout << "Test failed" << endl; + cout << "Failure" << endl << endl; + ret = MULTIPR_APP_FAILED; + } + + return ret; +} + + +/** + * \fn void runPartition1() + * \brief builds a distributed MED file (v2.3) by extracting groups from a sequential MED file. + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int runPartition1() +{ + int ret = MULTIPR_APP_OK; + try + { + multipr::partitionneDomaine(g_medFilename, g_meshName); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; +} + + +/** + * \fn void runPartition2() + * \brief builds a distributed MED file (v2.3) by splitting a part of a distributed MED file generated by runPartition1(). + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int runPartition2() +{ + int ret = MULTIPR_APP_OK; + try + { + multipr::partitionneGroupe( + g_medFilename, + g_partName, + g_nbParts, + g_splitter); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; +} + + +/** + * \fn int runDecimation() + * \brief creates 3 resolutions of a part of a distributed MED file. + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int runDecimation() +{ + int ret = MULTIPR_APP_OK; + try + { + multipr::decimePartition( + g_medFilename, + g_partName, + g_fieldName, + g_fieldTimeStepIt, + g_filterName, + g_params); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; +} + + +/** + * \fn int runMerge() + * \brief merges two sequential MED file if possible. + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int runMerge() +{ + int ret = MULTIPR_APP_OK; + try + { + + multipr::merge( + g_medFilenameSrc, + g_meshName, + g_fieldName, + g_medFilenameDst); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; +} + + +/** + * \fn int runDumpMED() + * \brief dumps info about a sequential MED file. + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int runDumpMED() +{ +#ifdef MULTIPR_USE_OBJ_API + int ret = MULTIPR_APP_OK; + try + { + // if mesh is unknown, then list all the meshes in the given MED file + if (g_meshName == NULL) + { + multipr::Obj obj; + obj.create(g_medFilename); + + { + // display list of meshes contained in the MED file + vector<string> res = obj.getMeshes(); + cout << "List of meshes in this MED file:" << endl; + for (unsigned i = 0 ; i < res.size() ; i++) + { + cout << "Mesh " << (i + 1) << ": \"" << res[i] << "\"" << endl; + } + } + + cout << endl; + + { + // display list of fields contained in the MED file + vector<string> names = obj.getFields(); + cout << "List of scalar fields in this MED file:" << endl; + for (unsigned i = 0 ; i < names.size() ; i++) + { + cout << "Field " << (i + 1) << ": \"" << names[i] << "\" #Time stamps=" << obj.getTimeStamps(names[i].c_str()) << endl; + } + } + } + else + { + // display all infos about one mesh in a MED file + multipr::Mesh mesh; + mesh.readSequentialMED(g_medFilename, g_meshName); + mesh.setPrintAll(true); + cout << mesh << endl; + } + cout << "OK" << endl; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; +#else + int ret = MULTIPR_APP_OK; + try + { + // if mesh is unknown, then list all the meshes in the given MED file + if (g_meshName == NULL) + { + { + // display list of meshes contained in the MED file + vector<string> res = multipr::getListMeshes(g_medFilename); + cout << "List of meshes in this MED file:" << endl; + for (unsigned i = 0 ; i < res.size() ; i++) + { + cout << "Mesh " << (i + 1) << ": \"" << res[i] << "\"" << endl; + } + } + + cout << endl; + + { + // display list of fields contained in the MED file + vector<pair<string,int> > res; + multipr::getListScalarFields(g_medFilename, res); + cout << "List of scalar fields in this MED file:" << endl; + for (unsigned i = 0 ; i < res.size() ; i++) + { + cout << "Field " << (i + 1) << ": \"" << res[i].first << "\" #Time stamps=" << res[i].second << endl; + } + } + } + else + { + // display all infos about one mesh in a MED file + multipr::Mesh mesh; + mesh.readSequentialMED(g_medFilename, g_meshName); + mesh.setPrintAll(true); + cout << mesh << endl; + } + cout << "OK" << endl; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; +#endif +} + + +/** + * \fn int run() + * \brief applies partitioning/decimation according to global parameters. + * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. + */ +int run() +{ + printGlobals(); + + int ret = MULTIPR_APP_OK; + switch (g_usage) + { + case MULTIPR_USAGE_AUTOTEST: ret = runAutotest(); break; + case MULTIPR_USAGE_PARTITION1: ret = runPartition1(); break; + case MULTIPR_USAGE_PARTITION2: ret = runPartition2(); break; + case MULTIPR_USAGE_DECIMATION: ret = runDecimation(); break; + case MULTIPR_USAGE_MERGE: ret = runMerge(); break; + case MULTIPR_USAGE_INFO: ret = runDumpMED(); break; + default: + cout << "ERROR: unknown usage" << endl; + ret = MULTIPR_APP_FAILED; + break; + } + + return ret; +} + + +/** + * \fn int main(int argc, char** argv) + * \brief entry point of the application. + * \param argc number of arguments. + * \param argv list of arguments. + * \return 0 if OK, 1 if failed. + */ +int main(int argc, char** argv) +{ + string strTitle = string("multipr v") + string(multipr::getVersion()) + string(" - by EDF/CS - 04/2007"); + string strUnderline = ""; + + for (int i = 0, len = strTitle.length() ; i < len ; i++) strUnderline += '='; + + cout << strTitle << endl; + cout << strUnderline << endl; + + #ifdef MULTIPR_USE_OBJ_API + cout << "Version MULTIPR_Obj" << endl; + #else + cout << "Version MULTIPR_API" << endl; + #endif + + parseCommandLine(argc, argv); + + int ret = MULTIPR_APP_OK; // assume no error at the beginning + + if (g_usage == MULTIPR_USAGE_UNKNOWN) + { + if (argc != 1) + { + // if usage is unknown and there are some arguments, print an error message + cout << "ERROR: " << getErrorMsg() << endl; + cout << endl; + ret = MULTIPR_APP_FAILED; + } + else + { + // if no argument, print a description of this application + printDescription(); + } + + printUsage(); + } + else if (g_usage == MULTIPR_USAGE_DISPLAY_HELP) + { + printDescription(); + printUsage(); + } + else + { + // the application seems to be configured properly: it can be executed + ret = run(); + } + + return ret; +} + +// EOF diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 000000000..6e901cee2 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,45 @@ +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS = MEDWrapper MEDMEM INTERPOLATION MEDMEM_SWIG + +if MED_ENABLE_SPLITTER + SUBDIRS+= MEDSPLITTER + +# MULTIPR +if MED_ENABLE_METIS + MULTIPR_DIR = MULTIPR +endif +if MED_ENABLE_SCOTCH + MULTIPR_DIR = MULTIPR +endif + +endif + +if MED_ENABLE_KERNEL + SUBDIRS+= $(MULTIPR_DIR) MEDMEM_I MED MedCorba_Swig MED_SWIG MedClient +endif + +if MED_ENABLE_GUI + SUBDIRS+= MEDGUI +endif + +DIST_SUBDIRS= MEDWrapper INTERPOLATION MEDMEM MEDMEM_SWIG MEDSPLITTER MULTIPR MEDMEM_I MED MedCorba_Swig MED_SWIG MedClient MEDGUI diff --git a/src/Makefile.in b/src/Makefile.in deleted file mode 100644 index 1f0273d84..000000000 --- a/src/Makefile.in +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Paul RASCLE, EDF -# Module : MED -# $Header$ - -top_srcdir=@top_srcdir@ -top_builddir=.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ - -@COMMENCE@ - -#SUBDIRS = MEDWrapper INTERPOLATION MEDMEM MEDMEM_SWIG MEDMEM_I MED MEDGUI MedCorba_Swig MED_SWIG MedClient - -SUBDIRS = MEDWrapper INTERPOLATION MEDMEM MEDMEM_SWIG - -ifeq ($(MED_WITH_KERNEL),yes) - SUBDIRS+= MEDMEM_I MED MedCorba_Swig MED_SWIG MedClient -endif - -ifeq (@WITHIHM@,yes) - SUBDIRS+= MEDGUI -endif - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -@MODULE@ diff --git a/src/MedClient/Makefile.am b/src/MedClient/Makefile.am new file mode 100644 index 000000000..4cda3c5b9 --- /dev/null +++ b/src/MedClient/Makefile.am @@ -0,0 +1,24 @@ +# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +SUBDIRS = src test diff --git a/src/MedClient/Makefile.in b/src/MedClient/Makefile.in deleted file mode 100644 index 11ed60338..000000000 --- a/src/MedClient/Makefile.in +++ /dev/null @@ -1,40 +0,0 @@ -# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED -# source path - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@srcdir@/idl - -@COMMENCE@ - -SUBDIRS = src test - -MODULE = MEDClient - -@MODULE@ diff --git a/src/MedClient/src/CONNECTIVITYClient.cxx b/src/MedClient/src/CONNECTIVITYClient.cxx index 831ef3709..07fe4a369 100644 --- a/src/MedClient/src/CONNECTIVITYClient.cxx +++ b/src/MedClient/src/CONNECTIVITYClient.cxx @@ -96,6 +96,8 @@ void CONNECTIVITYClient::blankCopy() setGeometricTypes(Types, Entity); _totalNumberOfElements_client = 0L; + if (_numberOfElements_client) + delete [] _numberOfElements_client; _numberOfElements_client = new long[nTwithPoly]; for (iT=0; iT<nT; iT++) { @@ -115,11 +117,20 @@ void CONNECTIVITYClient::blankCopy() _polyType_client = MED_EN::MED_NONE; } + if(Types) + delete [] Types; + // create a constituent (PAL10556) - if ( Entity == MED_CELL ) { - Entity = ( IOR_Mesh->getMeshDimension() == 3 ? MED_FACE : MED_EDGE ); - _constituent = new CONNECTIVITYClient( IOR_Mesh, Entity ); - } +// The consequence is that, if the remote server +// has not calculated nodal connectivity of dimension d-1, heavy method +// (CPU and memory) calculateDecsendingConnectivity is called on this +// server for a potentially useless information for client side . (by Anthony GEAY) + if ( Entity == MED_CELL ) { + Entity = ( IOR_Mesh->getMeshDimension() == 3 ? MED_FACE : MED_EDGE ); + if(_constituent) + delete _constituent; + _constituent = new CONNECTIVITYClient( IOR_Mesh, Entity ); + } _complete = false; @@ -220,7 +231,8 @@ void CONNECTIVITYClient::fillCopy() } delete[] Count; - + if (_constituent) + ((CONNECTIVITYClient *)_constituent)->fillCopy(); _complete = true; } diff --git a/src/MedClient/src/COORDINATEClient.cxx b/src/MedClient/src/COORDINATEClient.cxx index c72f12003..dca0978a6 100644 --- a/src/MedClient/src/COORDINATEClient.cxx +++ b/src/MedClient/src/COORDINATEClient.cxx @@ -80,7 +80,7 @@ void COORDINATEClient::blankCopy() delete [] tA; - setCoordinatesSystem( CORBA::string_dup(all->coordSystem)); + setCoordinatesSystem( all->coordSystem.in()); _complete = false; diff --git a/src/MedClient/src/FAMILYClient.cxx b/src/MedClient/src/FAMILYClient.cxx index 32790fb2d..84a2d0476 100644 --- a/src/MedClient/src/FAMILYClient.cxx +++ b/src/MedClient/src/FAMILYClient.cxx @@ -62,24 +62,34 @@ void FAMILYClient::blankCopy(bool blankSupport) nAttr = IOR_Family->getNumberOfAttributes(); setNumberOfAttributes(nAttr); - convertCorbaArray(i, n, IOR_Family->getAttributesIdentifiers()); + SALOME_MED::long_array* attrId= IOR_Family->getAttributesIdentifiers(); + convertCorbaArray(i, n, attrId); + delete attrId; ASSERT(n == nAttr); setAttributesIdentifiers(i); - convertCorbaArray(i, n, IOR_Family->getAttributesValues()); + attrId=IOR_Family->getAttributesValues(); + i=0; + convertCorbaArray(i, n, attrId); + delete attrId; ASSERT(n == _numberOfAttribute); setAttributesValues(i); - convertCorbaArray(s, n, IOR_Family->getAttributesDescriptions()); + SALOME_MED::string_array * attrDesc=IOR_Family->getAttributesDescriptions(); + convertCorbaArray(s, n, attrDesc); + delete attrDesc; ASSERT(n == _numberOfAttribute); setAttributesDescriptions(s); nGr = IOR_Family->getNumberOfGroups(); setNumberOfGroups(nGr); - convertCorbaArray(s, n, IOR_Family->getGroupsNames()); + attrDesc=IOR_Family->getGroupsNames(); + s=0; + convertCorbaArray(s, n, attrDesc); + delete attrDesc; ASSERT(n == _numberOfGroup); - setGroupsNames(s); + setGroupsNames(s,true); _complete = false; diff --git a/src/MedClient/src/FIELDClient.cxx b/src/MedClient/src/FIELDClient.cxx index d40a5d859..a852945eb 100644 --- a/src/MedClient/src/FIELDClient.cxx +++ b/src/MedClient/src/FIELDClient.cxx @@ -84,7 +84,9 @@ FIELDClient<T,INTERLACING_TAG>::~FIELDClient() { _fieldPtr->Destroy(); CORBA::release(_fieldPtr); + /* CCAR : better put in FIELD_ destructor if support is a SUPPORTClient if(FIELD<T,INTERLACING_TAG>::_support) FIELD<T,INTERLACING_TAG>::_support->removeReference(); + */ } diff --git a/src/MedClient/src/MESHClient.cxx b/src/MedClient/src/MESHClient.cxx index 3556ef900..f774c4f48 100644 --- a/src/MedClient/src/MESHClient.cxx +++ b/src/MedClient/src/MESHClient.cxx @@ -275,3 +275,28 @@ void MESHClient::removeReference() const delete this; } } + +//============================================================================= +/*! + * Write all the content of the MESH using driver referenced by the integer handler index + */ +//============================================================================= + +void MESHClient::write(int index/*=0*/, const string & driverName/* = ""*/) +{ + this->fillCopy(); + MESH::write(index,driverName); +} + +//================================================================================ +/*! + * \brief fillCopy() and then print myself to a stream + */ +//================================================================================ + +void MESHClient::printMySelf(ostream &os) const +{ + MESHClient* that = (MESHClient*)this; + that->fillCopy(); + MESH::printMySelf( os ); +} diff --git a/src/MedClient/src/MESHClient.hxx b/src/MedClient/src/MESHClient.hxx index ec809c8fb..ed64220e7 100644 --- a/src/MedClient/src/MESHClient.hxx +++ b/src/MedClient/src/MESHClient.hxx @@ -45,6 +45,8 @@ public : void fillCopy(); virtual void addReference() const; virtual void removeReference() const; + virtual void write(int index=0, const string & driverName = ""); + virtual void printMySelf(ostream &os) const; private: virtual ~MESHClient(); diff --git a/src/MedClient/src/Makefile.am b/src/MedClient/src/Makefile.am new file mode 100644 index 000000000..d4b21cb18 --- /dev/null +++ b/src/MedClient/src/Makefile.am @@ -0,0 +1,85 @@ +# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +salomeinclude_HEADERS= \ + COORDINATEClient.hxx \ + CONNECTIVITYClient.hxx \ + MESHClient.hxx \ + SUPPORTClient.hxx \ + FAMILYClient.hxx \ + GROUPClient.hxx \ + FIELDClient.hxx \ + FIELDClient.cxx \ + libMEDClient.i + +if MED_SWIG_1_3_21 +SWIG_DEF = libMEDClient.i dummy.i + +dummy_wrap.cxx: libMEDClient_wrap.cxx + sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libMEDClient_wrap.cxx > toto + mv toto libMEDClient_wrap.cxx + sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libMEDClient_wrap.cxx > toto + mv toto libMEDClient_wrap.cxx + touch dummy_wrap.cxx +else !MED_SWIG_1_3_21 +SWIG_DEF = libMEDClient.i +endif + +dist_salomescript_DATA= \ + medClient_test.py \ + testMeshAlliances.py +nodist_salomescript_DATA= libMEDClient.py + +lib_LTLIBRARIES= libMEDClientcmodule.la + +dist_libMEDClientcmodule_la_SOURCES= \ + COORDINATEClient.cxx \ + CONNECTIVITYClient.cxx \ + MESHClient.cxx \ + SUPPORTClient.cxx \ + FAMILYClient.cxx \ + GROUPClient.cxx + +libMEDClientcmodule_la_CPPFLAGS= $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) \ + $(MED2_INCLUDES) $(HDF5_INCLUDES) $(PYTHON_INCLUDES) ${KERNEL_CXXFLAGS} \ + -I$(srcdir)/../../MEDMEM_I -I$(srcdir)/../../MEDMEM -I$(top_builddir)/salome_adm/unix -I$(top_builddir)/idl \ + -I$(srcdir)/../../MEDWrapper/V2_1/Core -I$(srcdir)/../../MEDMEM_SWIG -I$(srcdir)/../../MED +libMEDClientcmodule_la_LDFLAGS=${KERNEL_LDFLAGS} -lOpUtil -lSalomeCommunication ../../MedCorba_Swig/libMedCorba_Swigcmodule.la ../../MEDMEM/libmedmem.la + +SWIG_FLAGS= @SWIG_FLAGS@ -I$(srcdir) -I$(srcdir)/../../MedCorba_Swig -I$(srcdir)/../../MEDMEM_SWIG +SWIG_DEP=$(srcdir)/../../MedCorba_Swig/libMedCorba_Swig.i $(srcdir)/../../MEDMEM_SWIG/libMEDMEM_Swig.i +nodist_libMEDClientcmodule_la_SOURCES= libMEDClient_wrap.cxx + +libMEDClient.py: libMEDClient_wrap.cxx + +libMEDClient_wrap.cxx: $(SWIG_DEF) $(SWIG_DEP) + $(SWIG) $(SWIG_FLAGS) -o $@ $(SWIG_DEF) + +CLEANFILES= libMEDClient.py libMEDClient_wrap.cxx + +install-exec-hook: $(libdir)/_libMEDClient.so + +$(libdir)/_libMEDClient.so: + ( cd $(libdir); ln -sf libMEDClientcmodule.so _libMEDClient.so; ) diff --git a/src/MedClient/src/Makefile.in b/src/MedClient/src/Makefile.in deleted file mode 100644 index 06ad12039..000000000 --- a/src/MedClient/src/Makefile.in +++ /dev/null @@ -1,106 +0,0 @@ -# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED -# source path -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir):$(top_srcdir)/idl:$(top_builddir)/idl - -MACHINE=PCLINUX - -@COMMENCE@ - - -EXPORT_HEADERS = \ - COORDINATEClient.hxx \ - CONNECTIVITYClient.hxx \ - MESHClient.hxx \ - SUPPORTClient.hxx \ - FAMILYClient.hxx \ - GROUPClient.hxx \ - FIELDClient.hxx \ - FIELDClient.cxx \ - libMEDClient.i - -ifeq (@SWIG_VERSION@, 1.3.21) -SWIG_DEF = libMEDClient.i dummy.i - -dummy_wrap.cxx: libMEDClient_wrap.cxx - sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libMEDClient_wrap.cxx > toto - mv toto libMEDClient_wrap.cxx - sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libMEDClient_wrap.cxx > toto - mv toto libMEDClient_wrap.cxx - touch dummy_wrap.cxx -else -SWIG_DEF = libMEDClient.i -endif - -# libMEDClient.i depends on libMEDMEM_Swig.i and libMedCorba_Swig.i: -# %include "libMedCorba_Swig.i" -# %include "libMEDMEM_Swig.i" -SWIG_DEP = libMEDMEM_Swig.i libMedCorba_Swig.i - -EXPORT_PYSCRIPTS = libMEDClient.py \ - medClient_test.py \ - testMeshAlliances.py - -# Libraries targets - -LIB=libMEDClientcmodule.la -LIB_SRC = \ - COORDINATEClient.cxx \ - CONNECTIVITYClient.cxx \ - MESHClient.cxx \ - SUPPORTClient.cxx \ - FAMILYClient.cxx \ - GROUPClient.cxx - -LIB_CLIENT_IDL= \ - SALOME_Component.idl \ - SALOMEDS.idl \ - SALOMEDS_Attributes.idl \ - SALOME_Exception.idl \ - SALOME_Comm.idl \ - MED.idl \ - SALOME_GenericObj.idl - -# Executables targets -BIN_SRC = -BIN_SERVER_IDL = -BIN_CLIENT_IDL = - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS+= $(MED2_INCLUDES) $(HDF5_INCLUDES) $(PYTHON_INCLUDES) ${KERNEL_CXXFLAGS} -I$(srcdir)/../../MEDMEM_I -CXXFLAGS+=${KERNEL_CXXFLAGS} -LDFLAGS+=${KERNEL_LDFLAGS} -lOpUtil -lMedCorba_Swigcmodule -lmedmem - -MED.hh MEDSK.cc: MED.idl - omniidl -bcxx -Wbtp -I$(top_builddir)/idl -I${KERNEL_ROOT_DIR}/idl/salome $^ - -@CONCLUDE@ diff --git a/src/MedClient/src/MakefileForTest b/src/MedClient/src/MakefileForTest index 079683ab3..a03720d47 100644 --- a/src/MedClient/src/MakefileForTest +++ b/src/MedClient/src/MakefileForTest @@ -30,7 +30,7 @@ pyTESTMEDCLIENT : TESTMEDCLIENT_Gen.idl TESTMEDCLIENTCatalog.xml : TESTMEDCLIENT_Gen.idl omniidl -bIDLparser $(INCIDL) -Wbcatalog=$@,name='TESTMEDCLIENT',username='TESTMEDCLIENT' $^ sed -e 's/TESTMEDCLIENT_Gen/TESTMEDCLIENT/g' $@ > toto - mv toto ./share/salome/resources/$@ + mv toto ./share/salome/resources/med/$@ rm *.xml TESTMEDCLIENT_GenSK.o : $(INC_IDL) TESTMEDCLIENT_GenSK.cc diff --git a/src/MedClient/src/MemorySpy.cxx b/src/MedClient/src/MemorySpy.cxx index 08828e395..1c6eb38b9 100644 --- a/src/MedClient/src/MemorySpy.cxx +++ b/src/MedClient/src/MemorySpy.cxx @@ -19,7 +19,7 @@ // #include "MemorySpy.hxx" -#ifdef PCLINUX +#if defined(PCLINUX) || defined(PCLINUX64) || defined(PCLINUX64_32) #include <unistd.h> #include <string.h> diff --git a/src/MedClient/src/MemorySpy.hxx b/src/MedClient/src/MemorySpy.hxx index 0c71a62ff..0e74148df 100644 --- a/src/MedClient/src/MemorySpy.hxx +++ b/src/MedClient/src/MemorySpy.hxx @@ -29,7 +29,7 @@ public: MemorySpy(); ~MemorySpy(); long getCurrentMemoryUsage(); -#ifdef PCLINUX +#if defined(PCLINUX) || defined(PCLINUX64) || defined(PCLINUX64_32) //SOLARIS private: long parseString(char* line); diff --git a/src/MedClient/src/SUPPORTClient.cxx b/src/MedClient/src/SUPPORTClient.cxx index d2f3cb68c..faea8438d 100644 --- a/src/MedClient/src/SUPPORTClient.cxx +++ b/src/MedClient/src/SUPPORTClient.cxx @@ -45,7 +45,8 @@ SUPPORTClient::SUPPORTClient(const SALOME_MED::SUPPORT_ptr S, _mesh=M; else { - _mesh=new MESHClient(IOR_Support->getMesh()); + SALOME_MED::MESH_var ior_mesh=IOR_Support->getMesh(); + _mesh=new MESHClient(ior_mesh); } blankCopy(); diff --git a/src/MedClient/src/libMEDClient.i b/src/MedClient/src/libMEDClient.i index 875af24b8..1307d4ea4 100644 --- a/src/MedClient/src/libMEDClient.i +++ b/src/MedClient/src/libMEDClient.i @@ -29,6 +29,17 @@ using namespace MED_EN; %} +%typemap(in) MESH* { + if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 0)) == -1) { + MESHClient *client; + if ((SWIG_ConvertPtr($input, (void **) &client, $descriptor(MESHClient *), 0)) == -1) { + SWIG_Python_TypeError("MESH* or MESHClient*", $input); + return NULL; + } + $1 = (MESH *) client; + } +} + %include "libMedCorba_Swig.i" %include "libMEDMEM_Swig.i" @@ -37,6 +48,23 @@ $1 = ($input != 0); } +/* + managing C++ exception in the Python API +*/ +/*%exception +{ + class PyAllowThreadsGuard { + public: + PyAllowThreadsGuard() { _save = PyEval_SaveThread(); } + ~PyAllowThreadsGuard() { PyEval_RestoreThread(_save); } + private: + PyThreadState *_save; + }; + + PyAllowThreadsGuard guard; + + $action +}*/ class MESHClient : public MESH { @@ -87,39 +115,55 @@ public: ~FIELDClient(); }; -%template (FIELDDOUBLEClient) FIELDClient<double, FullInterlace>; -%template (FIELDDOUBLENOINTERLACEClient) FIELDClient<double, NoInterlace>; -%template (FIELDINTClient) FIELDClient<int, FullInterlace>; -%template (FIELDINTNOINTERLACEClient) FIELDClient<int, NoInterlace>; +%template (FIELDDOUBLEClient) FIELDClient<double, FullInterlace>; +%template (FIELDDOUBLENOINTERLACEClient) FIELDClient<double, NoInterlace>; +%template (FIELDDOUBLENOINTERLACEBYTYPEClient) FIELDClient<double, NoInterlaceByType>; +%template (FIELDINTClient) FIELDClient<int, FullInterlace>; +%template (FIELDINTNOINTERLACEClient) FIELDClient<int, NoInterlace>; +%template (FIELDINTNOINTERLACEBYTYPEClient) FIELDClient<int, NoInterlaceByType>; %extend FIELDClient<double, FullInterlace> { - %template(FIELDDOUBLEClients) FIELDClient<SALOME_MED::FIELDDOUBLE_ptr>; + %template(FIELDDOUBLEClient) FIELDClient<SALOME_MED::FIELDDOUBLE_ptr>; }; %extend FIELDClient<double, NoInterlace> { - %template(FIELDDOUBLENOINTERLACEClients) FIELDClient<SALOME_MED::FIELDDOUBLE_ptr>; + %template(FIELDDOUBLENOINTERLACEClient) FIELDClient<SALOME_MED::FIELDDOUBLE_ptr>; +}; + +%extend FIELDClient<double, NoInterlaceByType> +{ + %template(FIELDDOUBLENOINTERLACEBYTYPEClient) FIELDClient<SALOME_MED::FIELDDOUBLE_ptr>; }; %extend FIELDClient<int, FullInterlace> { - %template(FIELDINTClients) FIELDClient<SALOME_MED::FIELDINT_ptr>; + %template(FIELDINTClient) FIELDClient<SALOME_MED::FIELDINT_ptr>; }; %extend FIELDClient<int, NoInterlace> { - %template(FIELDINTNOINTERLACEClients) FIELDClient<SALOME_MED::FIELDINT_ptr>; + %template(FIELDINTNOINTERLACEClient) FIELDClient<SALOME_MED::FIELDINT_ptr>; +}; + +%extend FIELDClient<int, NoInterlaceByType> +{ + %template(FIELDINTNOINTERLACEBYTYPEClient) FIELDClient<SALOME_MED::FIELDINT_ptr>; }; FIELD<double> * getDoublePointer(FIELDClient<double,FullInterlace> * input); FIELD<double,NoInterlace> *getDoubleNoInterlacePointer(FIELDClient<double,NoInterlace> * input); +FIELD<double,NoInterlaceByType> *getDoubleNoInterlaceByTypePointer(FIELDClient<double,NoInterlaceByType> * input); + FIELD<int> * getIntPointer(FIELDClient<int,FullInterlace> * input); FIELD<int,NoInterlace> * getIntNoInterlacePointer(FIELDClient<int,NoInterlace> * input); +FIELD<int,NoInterlaceByType> * getIntNoInterlaceByTypePointer(FIELDClient<int,NoInterlaceByType> * input); + %{ FIELD<double> * getDoublePointer(FIELDClient<double,FullInterlace> * input) { @@ -131,6 +175,11 @@ FIELD<int,NoInterlace> * getIntNoInterlacePointer(FIELDClient<int,NoInterlace> * return (FIELD<double,NoInterlace> *) input; } + FIELD<double,NoInterlaceByType> *getDoubleNoInterlaceByTypePointer(FIELDClient<double,NoInterlaceByType> * input) + { + return (FIELD<double,NoInterlaceByType> *) input; + } + FIELD<int> * getIntPointer(FIELDClient<int,FullInterlace> * input) { return (FIELD<int> *) input; @@ -140,4 +189,9 @@ FIELD<int,NoInterlace> * getIntNoInterlacePointer(FIELDClient<int,NoInterlace> * { return (FIELD<int,NoInterlace> *) input; } + + FIELD<int,NoInterlaceByType> * getIntNoInterlaceByTypePointer(FIELDClient<int,NoInterlaceByType> * input) + { + return (FIELD<int,NoInterlaceByType> *) input; + } %} diff --git a/src/MedClient/src/medClient_test.py b/src/MedClient/src/medClient_test.py index 68c53c956..7380b952a 100644 --- a/src/MedClient/src/medClient_test.py +++ b/src/MedClient/src/medClient_test.py @@ -137,7 +137,7 @@ medComp=salome.lcc.FindOrLoadComponent("FactoryServer", "MED") import os filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" filePathName = filePath + fileName @@ -204,6 +204,10 @@ for i in range(nbOfMeshes): + meshLocalCopy0 = MESHClient(meshObj) + print "\n=============== Test printing of MESHClient (bug NPAL14100) =======================" + print meshLocalCopy0 + print "============= End Test printing of MESHClient (bug NPAL14100) =======================\n\n" meshLocalCopy = MESHClient(meshObj) diff --git a/src/MedClient/src/testMeshAlliances.py b/src/MedClient/src/testMeshAlliances.py index 12a4a6189..d2f3a4650 100755 --- a/src/MedClient/src/testMeshAlliances.py +++ b/src/MedClient/src/testMeshAlliances.py @@ -5,17 +5,19 @@ import os from libMEDClient import * filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" +filePath=filePath+"/share/salome/resources/med/" medFiles = [] medFiles.append("extendedtransport53_triangles.med") medFiles.append("maillage_5_5_5.med") medFiles.append("maillage_chemvalIV_cas1_40elts.med") +medFiles.append("Old_maillage_chemvalIV_cas1_40elts.med") meshNames = [] meshNames.append("TestA3_2094_0.1_rsurf_tri") meshNames.append("maillage_5_5_5") meshNames.append("maillage_chemvalIV_cas1_40elts") +meshNames.append("maillage_chemvalIV_cas1_40elts") nbOfFiles = len(medFiles) diff --git a/src/MedClient/test/Makefile.am b/src/MedClient/test/Makefile.am new file mode 100644 index 000000000..e61d4eac6 --- /dev/null +++ b/src/MedClient/test/Makefile.am @@ -0,0 +1,32 @@ +# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +dist_salomeres_DATA= \ + resources/pointe.med \ + resources/carre_en_quad4_seg2.med \ + resources/maill.0.med \ + resources/test_hydro_darcy1a_out.med + +SUBDIRS = environ test1 test2 diff --git a/src/MedClient/test/Makefile.in b/src/MedClient/test/Makefile.in deleted file mode 100644 index d6163a8ff..000000000 --- a/src/MedClient/test/Makefile.in +++ /dev/null @@ -1,39 +0,0 @@ -# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED -# source path -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@srcdir@/resources - -@COMMENCE@ - -RESOURCES_FILES = pointe.med carre_en_quad4_seg2.med maill.0.med test_hydro_darcy1a_out.med - -SUBDIRS = environ test1 test2 - -@MODULE@ diff --git a/src/MedClient/test/environ/Makefile.am b/src/MedClient/test/environ/Makefile.am new file mode 100644 index 000000000..c18362ec7 --- /dev/null +++ b/src/MedClient/test/environ/Makefile.am @@ -0,0 +1,35 @@ +# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +SUBDIRS= csh + +nodist_purebin_SCRIPTS= runTestMedCorba + +nodist_testsenviron_SCRIPTS= runEnvironTests + +EXTRA_DIST+= \ + runContainer.in \ + runEnvironTests.in \ + runTestMedCorba.in \ + stopContainer.in diff --git a/src/MedClient/test/environ/Makefile.in b/src/MedClient/test/environ/Makefile.in deleted file mode 100644 index 2411b3a10..000000000 --- a/src/MedClient/test/environ/Makefile.in +++ /dev/null @@ -1,73 +0,0 @@ -# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED -# source path -top_srcdir=@top_srcdir@ -top_builddir=../../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ - -BIN= runEnvironTests - -all: - $(MAKE) inc - $(MAKE) depend_idl - $(MAKE) depend - $(MAKE) lib - $(MAKE) bin - $(MAKE) resources - -depend depend_idl clean_dep lib idl resources: - -inc: ${BIN} Makefile - - -bin: - chmod u+x ${BIN} - cp -f runTestMedCorba ${top_builddir}/bin - chmod +x ${top_builddir}/bin/runTestMedCorba - chmod +x runContainer stopContainer runEnvironTests - chmod +x csh/* - -install: - mkdir -p @prefix@/Tests/environ - cp -rf ${BIN} csh @prefix@/Tests/environ - cd @prefix@/Tests/environ ; chmod u+x ${BIN} - cp -f ${top_builddir}/bin/runTestMedCorba @prefix@/bin - chmod +x @prefix@/bin/runTestMedCorba - -./%: @srcdir@/%.in - cd $(top_builddir) ; \ - ./config.status - -$(top_builddir)/config.status: $(top_srcdir)/configure - cd $(top_builddir) ; ./config.status --recheck - -clean: - \rm -f dummy *~ */*~ - -cleandep: - diff --git a/src/MedClient/test/environ/csh/Makefile.am b/src/MedClient/test/environ/csh/Makefile.am new file mode 100644 index 000000000..8ee983a9a --- /dev/null +++ b/src/MedClient/test/environ/csh/Makefile.am @@ -0,0 +1,36 @@ +# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG +# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +nodist_testsenvironcsh_SCRIPTS= \ + init1 \ + init2 \ + init3 \ + runContainer \ + runEnvironTests \ + stopContainer + +EXTRA_DIST+= \ + init1.in \ + init2.in \ + init3.in \ + runContainer.in \ + runEnvironTests.in \ + stopContainer.in diff --git a/src/MedClient/test/environ/csh/Makefile.in b/src/MedClient/test/environ/csh/Makefile.in deleted file mode 100644 index 6f53ea9e4..000000000 --- a/src/MedClient/test/environ/csh/Makefile.in +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG -# PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -top_srcdir=@top_srcdir@ -top_builddir=../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@ - -BIN= init1 init2 init3 init4 init5 runContainer stopContainer - -TYPESHELL=csh -INSTALLDIR=@prefix@/Tests/environ/${TYPESHELL} - -all: - $(MAKE) inc - $(MAKE) depend_idl - $(MAKE) depend - $(MAKE) lib - $(MAKE) bin - $(MAKE) resources - chmod u+x ${BIN} - -depend depend_idl clean_dep lib idl resources: - -inc: ${BIN} Makefile - -bin: - chmod u+x ${BIN} - -install: - mkdir -p ${INSTALLDIR} - cp -rf ${BIN} ${INSTALLDIR} - cd ${INSTALLDIR} ; chmod u+x ${BIN} - -%: @srcdir@/%.in - @echo $^ "->" $@ - cd $(top_builddir) ; \ - ./config.status ${patsubst @top_srcdir@/%, ./%, @srcdir@/$@} - -%: @srcdir@/% - @echo $^ "->" $@ - cp -f $^ $@ - -$(top_builddir)/config.status: $(top_srcdir)/configure - cd $(top_builddir) ; ./config.status --recheck diff --git a/src/MedClient/test/environ/runTestMedCorba.in b/src/MedClient/test/environ/runTestMedCorba.in index c83158c0f..736d46251 100644 --- a/src/MedClient/test/environ/runTestMedCorba.in +++ b/src/MedClient/test/environ/runTestMedCorba.in @@ -6,7 +6,7 @@ if test -n $MED_ROOT_DIR then export PATH=$MED_ROOT_DIR/bin/salome:${PATH} export LD_LIBRARY_PATH=$MED_ROOT_DIR/lib@LIB_LOCATION_SUFFIX@/salome:${LD_LIBRARY_PATH} - export PYTHONPATH=${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/salome:${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/$PYTHON_VERSION/site-packages/salome:${MED_ROOT_DIR}/share/salome/resources:${PYTHONPATH} + export PYTHONPATH=${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/salome:${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/$PYTHON_VERSION/site-packages/salome:${MED_ROOT_DIR}/share/salome/resources/med:${PYTHONPATH} # add bin, because some script are in (SALOME_SWIG) !!!! export PYTHONPATH=${MED_ROOT_DIR}/bin/salome:${PYTHONPATH} fi @@ -14,7 +14,7 @@ if test -n $MED_ROOT_DIR then export PATH=$MED_ROOT_DIR/bin/salome:${PATH} export LD_LIBRARY_PATH=$MED_ROOT_DIR/lib@LIB_LOCATION_SUFFIX@/salome:${LD_LIBRARY_PATH} - export PYTHONPATH=${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/salome:${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/$PYTHON_VERSION/site-packages/salome:${MED_ROOT_DIR}/share/salome/resources:${PYTHONPATH} + export PYTHONPATH=${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/salome:${MED_ROOT_DIR}/lib@LIB_LOCATION_SUFFIX@/$PYTHON_VERSION/site-packages/salome:${MED_ROOT_DIR}/share/salome/resources/med:${PYTHONPATH} fi mkdir -p resultats diff --git a/src/MedClient/test/resources/carre_en_quad4_seg2.med b/src/MedClient/test/resources/carre_en_quad4_seg2.med index 7d7c75370..a0ca945a5 100644 Binary files a/src/MedClient/test/resources/carre_en_quad4_seg2.med and b/src/MedClient/test/resources/carre_en_quad4_seg2.med differ diff --git a/src/MedClient/test/resources/maill.0.med b/src/MedClient/test/resources/maill.0.med index e5a7b130d..4994e63a1 100644 Binary files a/src/MedClient/test/resources/maill.0.med and b/src/MedClient/test/resources/maill.0.med differ diff --git a/src/MedClient/test/resources/pointe.med b/src/MedClient/test/resources/pointe.med index 430a74bd6..0dbc1e8fb 100644 Binary files a/src/MedClient/test/resources/pointe.med and b/src/MedClient/test/resources/pointe.med differ diff --git a/src/MedClient/test/resources/test_hydro_darcy1a_out.med b/src/MedClient/test/resources/test_hydro_darcy1a_out.med index df24a1ea6..cca7b963f 100644 Binary files a/src/MedClient/test/resources/test_hydro_darcy1a_out.med and b/src/MedClient/test/resources/test_hydro_darcy1a_out.med differ diff --git a/src/MedClient/test/test1/Makefile.am b/src/MedClient/test/test1/Makefile.am new file mode 100644 index 000000000..7d8988887 --- /dev/null +++ b/src/MedClient/test/test1/Makefile.am @@ -0,0 +1,37 @@ +# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +EXTRA_DIST+= \ + resources/CatalogModuleTest.xml \ + resources/Compo1PyCatalog.xml + +dist_salomescript_DATA= \ + Compo1.py \ + Compo1Py.py \ + TestMedCorba1.py \ + TestMedCorba2.py \ + TestMedCorba3.py \ + TestMedCorba4.py \ + TestMedCorba5.py diff --git a/src/MedClient/test/test1/Makefile.in b/src/MedClient/test/test1/Makefile.in deleted file mode 100644 index 9d905bfd2..000000000 --- a/src/MedClient/test/test1/Makefile.in +++ /dev/null @@ -1,72 +0,0 @@ -# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED -# source path -top_srcdir=@top_srcdir@ -top_builddir=../../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/bin:@top_srcdir@/resources:@srcdir@/resources:@top_srcdir@/idl - -@COMMENCE@ - -RESOURCES_FILES = \ - Compo1PyCatalog.xml - -EXPORT_PYSCRIPTS = Compo1.py Compo1Py.py \ - ${patsubst ${srcdir}/%, %, ${wildcard ${srcdir}/TestMedCorba*.py} } - - -# Libraries targets - -LIB = -LIB_SRC = -LIB_CLIENT_IDL = - -# Executables targets -BIN = -BIN_SRC = - -LDFLAGS+= - -# copy python scripts in $(top_builddir)/bin/salome -# -DEST_PYSCRIPTS = $(EXPORT_PYSCRIPTS:%=$(top_builddir)/bin/salome/%) -pyscripts: $(DEST_PYSCRIPTS) -$(DEST_PYSCRIPTS): $(top_builddir)/bin/salome/%: % - cp -f $< $@ - -# Install python script in $(bindir) -install-python: $(bindir) $(EXPORT_PYSCRIPTS:%=install-%) - -$(EXPORT_PYSCRIPTS:%=install-%): install-%: % - $(INSTALL_PROGRAM) $< $(bindir)/. - -# _CS_gbo_240504 Il s'agit d'un répertoire feuille -@CONCLUDE@ - -bin: pyscripts - -install: install-python diff --git a/src/MedClient/test/test1/TestMedCorba1.py b/src/MedClient/test/test1/TestMedCorba1.py index d20ebb619..6f71d3c18 100644 --- a/src/MedClient/test/test1/TestMedCorba1.py +++ b/src/MedClient/test/test1/TestMedCorba1.py @@ -17,7 +17,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # import os -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'carre_en_quad4_seg2.med' diff --git a/src/MedClient/test/test1/TestMedCorba2.py b/src/MedClient/test/test1/TestMedCorba2.py index 6601591a8..7cc6fd720 100644 --- a/src/MedClient/test/test1/TestMedCorba2.py +++ b/src/MedClient/test/test1/TestMedCorba2.py @@ -17,7 +17,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # import os -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'carre_en_quad4_seg2.med' diff --git a/src/MedClient/test/test1/TestMedCorba3.py b/src/MedClient/test/test1/TestMedCorba3.py index 9f1ad707e..c637bdd56 100644 --- a/src/MedClient/test/test1/TestMedCorba3.py +++ b/src/MedClient/test/test1/TestMedCorba3.py @@ -17,7 +17,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # import os -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'carre_en_quad4_seg2.med' diff --git a/src/MedClient/test/test1/TestMedCorba4.py b/src/MedClient/test/test1/TestMedCorba4.py index 2839fd780..f29dd14f9 100644 --- a/src/MedClient/test/test1/TestMedCorba4.py +++ b/src/MedClient/test/test1/TestMedCorba4.py @@ -17,7 +17,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # import os -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'carre_en_quad4_seg2.med' diff --git a/src/MedClient/test/test1/TestMedCorba5.py b/src/MedClient/test/test1/TestMedCorba5.py index 1afd43d12..2b57c5002 100644 --- a/src/MedClient/test/test1/TestMedCorba5.py +++ b/src/MedClient/test/test1/TestMedCorba5.py @@ -17,7 +17,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # import os -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'carre_en_quad4_seg2.med' diff --git a/src/MedClient/test/test2/Makefile.am b/src/MedClient/test/test2/Makefile.am new file mode 100644 index 000000000..b6d9a4168 --- /dev/null +++ b/src/MedClient/test/test2/Makefile.am @@ -0,0 +1,74 @@ +# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +dist_salomescript_DATA= \ + TestMedCorba6.py \ + TestMedCorba7.py \ + TestMedCorba8.py +nodist_salomescript_DATA= \ + libCompo2.py + +# Libraries targets +lib_LTLIBRARIES= libCompo2cmodule.la +dist_libCompo2cmodule_la_SOURCES= Compo2.cxx +nodist_libCompo2cmodule_la_SOURCES= libCompo2_wrap.cxx + +EXTRA_DIST+= Compo2.hxx + +libCompo2cmodule_la_CPPFLAGS= $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) \ + ${MED2_INCLUDES} ${HDF5_INCLUDES} ${PYTHON_INCLUDES} ${KERNEL_CXXFLAGS} \ + -I$(srcdir)/../../../MEDMEM_I -I$(srcdir)/../../../MEDMEM -I$(top_builddir)/salome_adm/unix -I$(top_builddir)/idl \ + -I$(srcdir)/../../../MEDWrapper/V2_1/Core -I$(srcdir)/../../../MEDMEM_SWIG -I$(srcdir)/../../../MED -I$(srcdir)/../../src +libCompo2cmodule_la_LDFLAGS= ${KERNEL_LDFLAGS} ${MED2_LIBS} ${HDF5_LIBS} \ + ../../src/libMEDClientcmodule.la ../../../MEDMEM_SWIG/libMEDMEM_Swigcmodule.la \ + ../../../MEDMEM/libmedmem.la ../../../MEDMEM_I/libMEDMEMImpl.la + +if MED_SWIG_1_3_21 +SWIG_DEF = libCompo2.i dummy.i + +dummy_wrap.cxx: libCompo2_wrap.cxx + sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libCompo2_wrap.cxx > toto + mv toto libCompo2_wrap.cxx + sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libCompo2_wrap.cxx > toto + mv toto libCompo2_wrap.cxx + touch dummy_wrap.cxx +else !MED_SWIG_1_3_21 +SWIG_DEF = libCompo2.i +endif + +SWIG_FLAGS= @SWIG_FLAGS@ -I$(srcdir) -I$(srcdir)/../../src -I$(srcdir)/../../../MEDMEM_SWIG -I$(srcdir)/../../../MedCorba_Swig +SWIG_DEP=../../src/libMEDClient.i ../../../MEDMEM_SWIG/libMEDMEM_Swig.i ../../../MedCorba_Swig/libMedCorba_Swig.i + +libCompo2.py: libCompo2_wrap.cxx + +libCompo2_wrap.cxx: $(SWIG_DEF) + $(SWIG) $(SWIG_FLAGS) -o $@ $< + +CLEANFILES= libCompo2_wrap.cxx libCompo2.py + +install-exec-hook: $(libdir)/_libCompo2.so + +$(libdir)/_libCompo2.so: + ( cd $(libdir); ln -sf libCompo2cmodule.so _libCompo2.so; ) diff --git a/src/MedClient/test/test2/Makefile.in b/src/MedClient/test/test2/Makefile.in deleted file mode 100644 index 13d35f416..000000000 --- a/src/MedClient/test/test2/Makefile.in +++ /dev/null @@ -1,75 +0,0 @@ -# MED MedClient : tool to transfer MED CORBA from server producer of MED object to a client using those MED object -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED -# source path -top_srcdir=@top_srcdir@ -top_builddir=../../../.. -srcdir=@srcdir@ -VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_builddir)/idl - -@COMMENCE@ - -EXPORT_PYSCRIPTS = \ - ${patsubst ${srcdir}/%, %, ${wildcard ${srcdir}/TestMedCorba*.py} } \ - libCompo2.py - -# Libraries targets - -LIB = libCompo2cmodule.la -LIB_SRC = Compo2.cxx -LIB_CLIENT_IDL= SALOME_Component.idl SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Exception.idl SALOME_Comm.idl MED.idl SALOME_GenericObj.idl - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS += ${MED2_INCLUDES} ${HDF5_INCLUDES} ${PYTHON_INCLUDES} ${KERNEL_CXXFLAGS} -LIBS = ${KERNEL_LDFLAGS} -lMEDClientcmodule -lMEDMEM_Swigcmodule -lmedmem -lMEDMEMImpl ${MED2_LIBS} ${HDF5_LIBS} - -# Executables targets - -ifeq (@SWIG_VERSION@, 1.3.21) -SWIG_DEF = libCompo2.i dummy.i - -dummy_wrap.cxx: libCompo2_wrap.cxx - sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libCompo2_wrap.cxx > toto - mv toto libCompo2_wrap.cxx - sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libCompo2_wrap.cxx > toto - mv toto libCompo2_wrap.cxx - touch dummy_wrap.cxx -else -SWIG_DEF = libCompo2.i -endif - -# libCompo2.i depends on libMEDClient.i: -# %include "libMEDClient.i" -# which in its turn depends on libMEDMEM_Swig.i and libMedCorba_Swig.i -SWIG_DEP = libMEDClient.i libMEDMEM_Swig.i libMedCorba_Swig.i - -MED.hh MEDSK.cc: MED.idl - omniidl -bcxx -Wbtp -I$(top_builddir)/idl -I${KERNEL_ROOT_DIR}/idl/salome $^ - -@CONCLUDE@ - diff --git a/src/MedClient/test/test2/TestMedCorba6.py b/src/MedClient/test/test2/TestMedCorba6.py index ddae12722..c7dc24a0e 100644 --- a/src/MedClient/test/test2/TestMedCorba6.py +++ b/src/MedClient/test/test2/TestMedCorba6.py @@ -21,7 +21,7 @@ import os ## ne fonctionne pas ? ## import salome -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'carre_en_quad4_seg2.med' diff --git a/src/MedClient/test/test2/TestMedCorba7.py b/src/MedClient/test/test2/TestMedCorba7.py index df81dd557..70283f35f 100644 --- a/src/MedClient/test/test2/TestMedCorba7.py +++ b/src/MedClient/test/test2/TestMedCorba7.py @@ -18,7 +18,7 @@ # import os -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'test_hydro_darcy1a_out.med' diff --git a/src/MedClient/test/test2/TestMedCorba8.py b/src/MedClient/test/test2/TestMedCorba8.py index 21d51de92..e73ef6e89 100644 --- a/src/MedClient/test/test2/TestMedCorba8.py +++ b/src/MedClient/test/test2/TestMedCorba8.py @@ -20,7 +20,7 @@ import os # import salome -BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/' +BASE = os.environ["MED_ROOT_DIR"] + '/share/salome/resources/med/' fileName = BASE + 'pointe.med' fileName = BASE + 'test_hydro_darcy1a_out.med' diff --git a/src/MedCorba_Swig/Makefile.am b/src/MedCorba_Swig/Makefile.am new file mode 100644 index 000000000..812f4635e --- /dev/null +++ b/src/MedCorba_Swig/Makefile.am @@ -0,0 +1,68 @@ +# MED MedCorba_Swig : binding of MED CORBA objects woth Python +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +lib_LTLIBRARIES= libMedCorba_Swigcmodule.la + +if MED_SWIG_1_3_21 +SWIG_DEF = libMedCorba_Swig.i dummy.i + +dummy_wrap.cxx: libMedCorba_Swig_wrap.cxx + sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libMedCorba_Swig_wrap.cxx > toto + mv toto libMedCorba_Swig_wrap.cxx + sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libMedCorba_Swig_wrap.cxx > toto + mv toto libMedCorba_Swig_wrap.cxx + touch dummy_wrap.cxx +else !MED_SWIG_1_3_21 +SWIG_DEF = libMedCorba_Swig.i +endif + +SWIG_FLAGS= @SWIG_FLAGS@ -I$(srcdir) -I$(srcdir)/../MEDMEM_SWIG +SWIG_DEP= ../MEDMEM_SWIG/libMEDMEM_Swig.i + +nodist_libMedCorba_Swigcmodule_la_SOURCES= libMedCorba_Swig_wrap.cxx +salomeinclude_HEADERS= libMedCorba_Swig.i + +libMedCorba_Swig.py: libMedCorba_Swig_wrap.cxx + +libMedCorba_Swig_wrap.cxx: $(SWIG_DEF) $(SWIG_DEP) + $(SWIG) $(SWIG_FLAGS) -o $@ $(SWIG_DEF) + +############################################################################# + +libMedCorba_Swigcmodule_la_CPPFLAGS= $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) \ + $(PYTHON_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} -ftemplate-depth-42 \ + -I$(srcdir)/../MEDMEM_I -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDMEM_SWIG -I$(srcdir)/../MED -I$(srcdir)/../MEDWrapper/V2_1/Core \ + -I$(top_builddir)/salome_adm/unix -I$(top_builddir)/idl +libMedCorba_Swigcmodule_la_LDFLAGS=$(PYTHON_LIBS) $(MED2_LIBS) $(HDF5_LIBS) ${KERNEL_LDFLAGS} -lSALOMELocalTrace \ + ../MEDMEM_I/libMEDMEMImpl.la ../MEDMEM/libmedmem.la ../MEDMEM_SWIG/libMEDMEM_Swigcmodule.la ../MED/libMEDEngine.la + +dist_salomescript_DATA = medcorba_test.py batchmode_medcorba_test.py batchmode_medcorba_test1.py +nodist_salomescript_DATA = libMedCorba_Swig.py + +CLEANFILES= libMedCorba_Swig.py libMedCorba_Swig_wrap.cxx + +install-exec-hook: $(libdir)/_libMedCorba_Swig.so + +$(libdir)/_libMedCorba_Swig.so: + ( cd $(libdir); ln -sf libMedCorba_Swigcmodule.so _libMedCorba_Swig.so; ) diff --git a/src/MedCorba_Swig/Makefile.in b/src/MedCorba_Swig/Makefile.in deleted file mode 100644 index db6cf0b59..000000000 --- a/src/MedCorba_Swig/Makefile.in +++ /dev/null @@ -1,83 +0,0 @@ -# MED MedCorba_Swig : binding of MED CORBA objects woth Python -# -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# -# -# -# File : Makefile.in -# Author : Nadir BOUHAMOU (CEA/DEN/DM2S/SFME/LGLS) -# Module : MED - -top_srcdir=@top_srcdir@ -top_builddir=../.. -srcdir=@srcdir@ -VPATH=.:$(srcdir):$(top_srcdir)/idl:$(top_builddir)/idl - -@COMMENCE@ - -# Libraries targets - -LIB = libMedCorba_Swigcmodule.la - -LIB_SRC = - -ifeq (@SWIG_VERSION@, 1.3.21) -SWIG_DEF = libMedCorba_Swig.i dummy.i - -dummy_wrap.cxx: libMedCorba_Swig_wrap.cxx - sed -e 's/SwigValueWrapper< vector<FAMILY \* > >/vector<FAMILY \* >/g' libMedCorba_Swig_wrap.cxx > toto - mv toto libMedCorba_Swig_wrap.cxx - sed -e 's/SwigValueWrapper< vector<SUPPORT \* > const >/vector<SUPPORT \* >/g' libMedCorba_Swig_wrap.cxx > toto - mv toto libMedCorba_Swig_wrap.cxx - touch dummy_wrap.cxx -else -SWIG_DEF = libMedCorba_Swig.i -endif - -# libMedCorba_Swig.i depends on libMEDMEM_Swig.i: -# %include "libMEDMEM_Swig.i" -SWIG_DEP = libMEDMEM_Swig.i - -LIB_SERVER_IDL = MED.idl - -LIB_CLIENT_IDL= SALOME_Component.idl SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Exception.idl SALOME_Comm.idl SALOME_GenericObj.idl - -EXPORT_PYSCRIPTS = libMedCorba_Swig.py medcorba_test.py batchmode_medcorba_test.py batchmode_medcorba_test1.py - -EXPORT_HEADERS = libMedCorba_Swig.i - -############################################################################# - -LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome - -CPPFLAGS+= $(PYTHON_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} -CXXFLAGS+=-ftemplate-depth-42 ${KERNEL_CXXFLAGS} -LIBS= $(PYTHON_LIBS) -#LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lMEDMEMImpl -lmedmem -lMEDMEM_Swigcmodule ${KERNEL_LDFLAGS} -lSalomeLoggerServer ${KERNEL_LDFLAGS} -# change motivated by the bug KERNEL4778. -LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lMEDMEMImpl -lmedmem -lMEDMEM_Swigcmodule ${KERNEL_LDFLAGS} -lSALOMELocalTrace - -############################################################################# - -MED.hh MEDSK.cc: MED.idl - omniidl -bcxx -Wbtp -I$(top_builddir)/idl -I${KERNEL_ROOT_DIR}/idl/salome $^ - -@CONCLUDE@ diff --git a/src/MedCorba_Swig/libMedCorba_Swig.i b/src/MedCorba_Swig/libMedCorba_Swig.i index b63881bdd..e4ae4ec9f 100644 --- a/src/MedCorba_Swig/libMedCorba_Swig.i +++ b/src/MedCorba_Swig/libMedCorba_Swig.i @@ -30,13 +30,14 @@ #include "MEDMEM_Med_i.hxx" #include "MEDMEM_Mesh_i.hxx" #include "MEDMEM_Support_i.hxx" +#include "Med_Gen_i.hxx" using namespace MEDMEM; using namespace MED_EN; %} /* - typemap in and out for Corba Objects (MESH, FIELDDOUBLE, FIELDINT and + typemap in, out and typecheck for Corba Objects (MESH, FIELDDOUBLE, FIELDINT and Support) between C++ and Python WARNING (NB) to the user of those typmaps (SWIG wrapping for C++ routines @@ -46,6 +47,9 @@ using, because CORBA pointeur _ptr or _var could be wrapped by SWIG using their reference rather than the pointeur itself (differences detected using SWIG 1.1.x, SWIG 1.3.13 and SWIG 1.3.17) + + typecheck always says OK, as currently all overloaded methods HERE differ + only in nb of parameters (there are default ones) */ %typemap(python,out) SALOME_MED::MESH_ptr, SALOME_MED::FIELDDOUBLE_ptr, @@ -79,7 +83,25 @@ SCRUTE(s); PyObject * tmp = PyString_FromString(s.c_str()); SCRUTE(tmp); - $result = PyObject_CallMethod(orb, "string_to_object", "O", tmp); + PyObject * corbaObj = PyObject_CallMethod(orb, "string_to_object", "O", tmp); + $result = corbaObj; + + // cast CORBA object, if necessary + + // make target class name +// string className = "$1_type"; +// className.replace( className.find(':'), 2, "."); +// className.erase( className.find("_ptr")); + +// // get target class object +// string getClassCmd = ( "cls = " + className ); +// PyRun_String("import SALOME_MED", Py_single_input, pdict, pdict); +// PyRun_String(getClassCmd.c_str(), Py_single_input, pdict, pdict); +// PyObject* cls = PyDict_GetItemString(pdict, "cls"); + +// // cast +// $result = PyObject_CallMethod(corbaObj, "_narrow", "O", cls); + SCRUTE($result); } @@ -116,6 +138,18 @@ SCRUTE($result); } +%typemap(typecheck) SALOME_MED::MESH_ptr, SALOME_MED::FIELDDOUBLE_ptr, + SALOME_MED::FIELDINT_ptr, SALOME_MED::SUPPORT_ptr, + const SALOME_MED::MESH_ptr, const SALOME_MED::FIELDDOUBLE_ptr, + const SALOME_MED::FIELDINT_ptr, const SALOME_MED::SUPPORT_ptr, + SALOME_MED::MESH_var, SALOME_MED::FIELDDOUBLE_var, + SALOME_MED::FIELDINT_var, SALOME_MED::SUPPORT_var, + const SALOME_MED::MESH_var, const SALOME_MED::FIELDDOUBLE_var, + const SALOME_MED::FIELDINT_var, const SALOME_MED::SUPPORT_var +{ + $1 = 1; +} + %typemap(python,in) const SALOME_MED::MESH_ptr &, SALOME_MED::MESH_ptr & { @@ -500,6 +534,25 @@ SCRUTE($1); } + +/* + managing C++ exception in the Python API +*/ +/*%exception +{ + class PyAllowThreadsGuard { + public: + PyAllowThreadsGuard() { _save = PyEval_SaveThread(); } + ~PyAllowThreadsGuard() { PyEval_RestoreThread(_save); } + private: + PyThreadState *_save; + }; + + PyAllowThreadsGuard guard; + + $action +}*/ + SALOME_MED::FIELDDOUBLE_ptr createCorbaFieldDouble(SALOME_MED::SUPPORT_ptr, FIELDDOUBLE *, bool ownCppPtr=false); @@ -546,7 +599,20 @@ SALOME_MED::MESH_ptr createCorbaMesh(MESH * mesh); delete [] name; - return fieldcorba2; + // try to set support to field + ::MEDMEM::SUPPORT * sup = 0; + if ( SUPPORT_i * sup_i = Med_Gen_i::DownCast< SUPPORT_i * >( mySupportIOR )) + { + std::map < int,::MEDMEM::SUPPORT *>::iterator index_supp = + SUPPORT_i::supportMap.find( sup_i->getCorbaIndex() ); + if ( index_supp != SUPPORT_i::supportMap.end() ) + sup = index_supp->second; + } + SCRUTE( sup ); + if ( sup ) + field->setSupport( sup ); + + return fieldcorba2; } SALOME_MED::FIELDINT_ptr createCorbaFieldInt(SALOME_MED::SUPPORT_ptr mySupportIOR,FIELDINT * field, bool ownCppPtr=false) @@ -577,6 +643,19 @@ SALOME_MED::MESH_ptr createCorbaMesh(MESH * mesh); delete [] name; + // try to set support to field + ::MEDMEM::SUPPORT * sup = 0; + if ( SUPPORT_i * sup_i = Med_Gen_i::DownCast< SUPPORT_i * >( mySupportIOR )) + { + std::map < int,::MEDMEM::SUPPORT *>::iterator index_supp = + SUPPORT_i::supportMap.find( sup_i->getCorbaIndex() ); + if ( index_supp != SUPPORT_i::supportMap.end() ) + sup = index_supp->second; + } + SCRUTE( sup ); + if ( sup ) + field->setSupport( sup ); + return fieldcorba2; } diff --git a/src/MedCorba_Swig/medcorba_test.py b/src/MedCorba_Swig/medcorba_test.py index 56f2fcb08..9c568cfdb 100644 --- a/src/MedCorba_Swig/medcorba_test.py +++ b/src/MedCorba_Swig/medcorba_test.py @@ -37,9 +37,10 @@ from random import * import os -filePath=os.environ["MED_ROOT_DIR"] -filePath=filePath+"/share/salome/resources/" - +# filePath=os.environ["MED_ROOT_DIR"] +# filePath=filePath+"/share/salome/resources/med/" +filePath = os.environ["DATA_DIR"] +filePath = os.path.join( filePath, "MedFiles" ) #============================================================================== def AnalyzeField(field): @@ -130,14 +131,27 @@ print "" fileName = "cube_hexa8_quad4.med" #medFile = "carre_en_quad4_seg2.med" -medFile = filePath + fileName +medFile = os.path.join( filePath, fileName ) print "Loading of the Med Component" print "" med_comp = salome.lcc.FindOrLoadComponent("FactoryServer", "MED") -med_comp.readStructFile(medFile,studyCurrent) +print "Read file", medFile +print "" + +import SALOME +try: + med_comp.readStructFileWithFieldType(medFile,studyCurrent) +except SALOME.SALOME_Exception, inst: + msg = "SALOME.SALOME_Exception caght, see details:" + msg+="\n******* text:\t" + inst.details.text + msg+="\n******* type:\t" + str(inst.details.type) + msg+="\n******* where:\t" + inst.details.sourceFile + ":" + \ + str(inst.details.lineNumber) + raise RuntimeError, msg + sg.updateObjBrowser(1) med_obj = getMedObjectFromStudy(fileName) @@ -209,56 +223,53 @@ for entity in [SALOME_MED.MED_NODE,SALOME_MED.MED_CELL,SALOME_MED.MED_FACE,SALOM print "" lengthValue = familycorba.getNumberOfElements(SALOME_MED.MED_ALL_ELEMENTS) nbOfComp = 1 - print "Generate a Local scalar double field" + + print "\nGenerate a Local scalar double field" fieldScalDblLoc = createLocalFieldDouble(nbOfComp,lengthValue) - for k in range(lengthValue): - valueI = [] - for kcomp in range(nbOfComp): - valueI.append(random()) - fieldScalDblLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI) - valueIverif = fieldScalDblLoc.getValueI(MED_FULL_INTERLACE,k+1) - print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp] - print "Generate a Corba scalar double field" + value = [ random() for k in range(lengthValue*nbOfComp) ] + fieldScalDblLoc.setValue( value ) ## the only way as field support not defined + valueIverif = fieldScalDblLoc.getValue() + print " Set ",value + print " Get ",valueIverif + + print "\nGenerate a Corba scalar double field" fieldScalDblCorba = createCorbaFieldDouble(familycorba,fieldScalDblLoc) AnalyzeField(fieldScalDblCorba) - print "" + print "Generate a Local scalar integer field" fieldScalIntLoc = createLocalFieldInt(nbOfComp,lengthValue) - for k in range(lengthValue): - valueI = [] - for kcomp in range(nbOfComp): - valueI.append(randint(0,100)) - fieldScalIntLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI) - valueIverif = fieldScalIntLoc.getValueI(MED_FULL_INTERLACE,k+1) - print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp] - print "Generate a Corba scalar integer field" + value = [ randint(0,100) for k in range(lengthValue*nbOfComp) ] + fieldScalIntLoc.setValue( value ) ## the only way as field support not defined + valueIverif = fieldScalIntLoc.getValue() + print " Set ",value + print " Get ",valueIverif + + print "\nGenerate a Corba scalar integer field" fieldScalIntCorba = createCorbaFieldInt(familycorba,fieldScalIntLoc) AnalyzeField(fieldScalIntCorba) - print "" + nbOfComp = spaceDim - print "Generate a Local vector double field" + print "\nGenerate a Local vector double field" fieldVectDblLoc = createLocalFieldDouble(nbOfComp,lengthValue) - for k in range(lengthValue): - valueI = [] - for kcomp in range(nbOfComp): - valueI.append(random()) - fieldVectDblLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI) - valueIverif = fieldVectDblLoc.getValueI(MED_FULL_INTERLACE,k+1) - print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp] - print "Generate a Corba vector double field" + value = [ random() for k in range(lengthValue*nbOfComp) ] + fieldVectDblLoc.setValue(value) + valueIverif = fieldVectDblLoc.getValue() + print " Set ",value + print " Get ",valueIverif + + print "\nGenerate a Corba vector double field" fieldVectDblCorba = createCorbaFieldDouble(familycorba,fieldVectDblLoc) AnalyzeField(fieldVectDblCorba) - print "" - print "Generate a Local vector integer field" + + print "\nGenerate a Local vector integer field" fieldVectIntLoc = createLocalFieldInt(nbOfComp,lengthValue) - for k in range(lengthValue): - valueI = [] - for kcomp in range(nbOfComp): - valueI.append(randint(0,100)) - fieldVectIntLoc.setValueI(MED_FULL_INTERLACE,k+1,valueI) - valueIverif = fieldVectIntLoc.getValueI(MED_FULL_INTERLACE,k+1) - print " Set/Get Entry *",(k+1)," ",valueI[:nbOfComp]," / ",valueIverif[:nbOfComp] - print "Generate a Corba vector integer field" + value = [ randint(0,100) for k in range(lengthValue*nbOfComp) ] + fieldVectIntLoc.setValue(value) + valueIverif = fieldVectIntLoc.getValue() + print " Set ",value + print " Get ",valueIverif + + print "\nGenerate a Corba vector integer field" fieldVectIntCorba = createCorbaFieldInt(familycorba,fieldVectIntLoc) AnalyzeField(fieldVectIntCorba) print ""